12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399 |
- import AttributeCompression from "../Core/AttributeCompression.js";
- import BoundingSphere from "../Core/BoundingSphere.js";
- import Cartesian2 from "../Core/Cartesian2.js";
- import Cartesian3 from "../Core/Cartesian3.js";
- import Color from "../Core/Color.js";
- import ComponentDatatype from "../Core/ComponentDatatype.js";
- import defaultValue from "../Core/defaultValue.js";
- import defined from "../Core/defined.js";
- import destroyObject from "../Core/destroyObject.js";
- import DeveloperError from "../Core/DeveloperError.js";
- import EncodedCartesian3 from "../Core/EncodedCartesian3.js";
- import IndexDatatype from "../Core/IndexDatatype.js";
- import CesiumMath from "../Core/Math.js";
- import Matrix4 from "../Core/Matrix4.js";
- import WebGLConstants from "../Core/WebGLConstants.js";
- import Buffer from "../Renderer/Buffer.js";
- import BufferUsage from "../Renderer/BufferUsage.js";
- import ContextLimits from "../Renderer/ContextLimits.js";
- import DrawCommand from "../Renderer/DrawCommand.js";
- import Pass from "../Renderer/Pass.js";
- import RenderState from "../Renderer/RenderState.js";
- import ShaderProgram from "../Renderer/ShaderProgram.js";
- import ShaderSource from "../Renderer/ShaderSource.js";
- import VertexArrayFacade from "../Renderer/VertexArrayFacade.js";
- import BillboardCollectionFS from "../Shaders/BillboardCollectionFS.js";
- import BillboardCollectionVS from "../Shaders/BillboardCollectionVS.js";
- import Billboard from "./Billboard.js";
- import BlendingState from "./BlendingState.js";
- import BlendOption from "./BlendOption.js";
- import HeightReference from "./HeightReference.js";
- import HorizontalOrigin from "./HorizontalOrigin.js";
- import SceneMode from "./SceneMode.js";
- import SDFSettings from "./SDFSettings.js";
- import TextureAtlas from "./TextureAtlas.js";
- import VerticalOrigin from "./VerticalOrigin.js";
- var SHOW_INDEX = Billboard.SHOW_INDEX;
- var POSITION_INDEX = Billboard.POSITION_INDEX;
- var PIXEL_OFFSET_INDEX = Billboard.PIXEL_OFFSET_INDEX;
- var EYE_OFFSET_INDEX = Billboard.EYE_OFFSET_INDEX;
- var HORIZONTAL_ORIGIN_INDEX = Billboard.HORIZONTAL_ORIGIN_INDEX;
- var VERTICAL_ORIGIN_INDEX = Billboard.VERTICAL_ORIGIN_INDEX;
- var SCALE_INDEX = Billboard.SCALE_INDEX;
- var IMAGE_INDEX_INDEX = Billboard.IMAGE_INDEX_INDEX;
- var COLOR_INDEX = Billboard.COLOR_INDEX;
- var ROTATION_INDEX = Billboard.ROTATION_INDEX;
- var ALIGNED_AXIS_INDEX = Billboard.ALIGNED_AXIS_INDEX;
- var SCALE_BY_DISTANCE_INDEX = Billboard.SCALE_BY_DISTANCE_INDEX;
- var TRANSLUCENCY_BY_DISTANCE_INDEX = Billboard.TRANSLUCENCY_BY_DISTANCE_INDEX;
- var PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX =
- Billboard.PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX;
- var DISTANCE_DISPLAY_CONDITION_INDEX = Billboard.DISTANCE_DISPLAY_CONDITION;
- var DISABLE_DEPTH_DISTANCE = Billboard.DISABLE_DEPTH_DISTANCE;
- var TEXTURE_COORDINATE_BOUNDS = Billboard.TEXTURE_COORDINATE_BOUNDS;
- var SDF_INDEX = Billboard.SDF_INDEX;
- var NUMBER_OF_PROPERTIES = Billboard.NUMBER_OF_PROPERTIES;
- var attributeLocations;
- var attributeLocationsBatched = {
- positionHighAndScale: 0,
- positionLowAndRotation: 1,
- compressedAttribute0: 2,
- compressedAttribute1: 3,
- compressedAttribute2: 4,
- eyeOffset: 5,
- scaleByDistance: 6,
- pixelOffsetScaleByDistance: 7,
- compressedAttribute3: 8,
- textureCoordinateBoundsOrLabelTranslate: 9,
- a_batchId: 10,
- sdf: 11,
- };
- var attributeLocationsInstanced = {
- direction: 0,
- positionHighAndScale: 1,
- positionLowAndRotation: 2,
- compressedAttribute0: 3,
- compressedAttribute1: 4,
- compressedAttribute2: 5,
- eyeOffset: 6,
- scaleByDistance: 7,
- pixelOffsetScaleByDistance: 8,
- compressedAttribute3: 9,
- textureCoordinateBoundsOrLabelTranslate: 10,
- a_batchId: 11,
- sdf: 12,
- };
- function BillboardCollection(options) {
- options = defaultValue(options, defaultValue.EMPTY_OBJECT);
- this._scene = options.scene;
- this._batchTable = options.batchTable;
- this._textureAtlas = undefined;
- this._textureAtlasGUID = undefined;
- this._destroyTextureAtlas = true;
- this._sp = undefined;
- this._spTranslucent = undefined;
- this._rsOpaque = undefined;
- this._rsTranslucent = undefined;
- this._vaf = undefined;
- this._billboards = [];
- this._billboardsToUpdate = [];
- this._billboardsToUpdateIndex = 0;
- this._billboardsRemoved = false;
- this._createVertexArray = false;
- this._shaderRotation = false;
- this._compiledShaderRotation = false;
- this._shaderAlignedAxis = false;
- this._compiledShaderAlignedAxis = false;
- this._shaderScaleByDistance = false;
- this._compiledShaderScaleByDistance = false;
- this._shaderTranslucencyByDistance = false;
- this._compiledShaderTranslucencyByDistance = false;
- this._shaderPixelOffsetScaleByDistance = false;
- this._compiledShaderPixelOffsetScaleByDistance = false;
- this._shaderDistanceDisplayCondition = false;
- this._compiledShaderDistanceDisplayCondition = false;
- this._shaderDisableDepthDistance = false;
- this._compiledShaderDisableDepthDistance = false;
- this._shaderClampToGround = false;
- this._compiledShaderClampToGround = false;
- this._propertiesChanged = new Uint32Array(NUMBER_OF_PROPERTIES);
- this._maxSize = 0.0;
- this._maxEyeOffset = 0.0;
- this._maxScale = 1.0;
- this._maxPixelOffset = 0.0;
- this._allHorizontalCenter = true;
- this._allVerticalCenter = true;
- this._allSizedInMeters = true;
- this._baseVolume = new BoundingSphere();
- this._baseVolumeWC = new BoundingSphere();
- this._baseVolume2D = new BoundingSphere();
- this._boundingVolume = new BoundingSphere();
- this._boundingVolumeDirty = false;
- this._colorCommands = [];
-
- this.modelMatrix = Matrix4.clone(
- defaultValue(options.modelMatrix, Matrix4.IDENTITY)
- );
- this._modelMatrix = Matrix4.clone(Matrix4.IDENTITY);
-
- this.debugShowBoundingVolume = defaultValue(
- options.debugShowBoundingVolume,
- false
- );
-
- this.debugShowTextureAtlas = defaultValue(
- options.debugShowTextureAtlas,
- false
- );
-
- this.blendOption = defaultValue(
- options.blendOption,
- BlendOption.OPAQUE_AND_TRANSLUCENT
- );
- this._blendOption = undefined;
- this._mode = SceneMode.SCENE3D;
-
- this._buffersUsage = [
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- BufferUsage.STATIC_DRAW,
- ];
- this._highlightColor = Color.clone(Color.WHITE);
- var that = this;
- this._uniforms = {
- u_atlas: function () {
- return that._textureAtlas.texture;
- },
- u_highlightColor: function () {
- return that._highlightColor;
- },
- };
- var scene = this._scene;
- if (defined(scene) && defined(scene.terrainProviderChanged)) {
- this._removeCallbackFunc = scene.terrainProviderChanged.addEventListener(
- function () {
- var billboards = this._billboards;
- var length = billboards.length;
- for (var i = 0; i < length; ++i) {
- if (defined(billboards[i])) {
- billboards[i]._updateClamping();
- }
- }
- },
- this
- );
- }
- }
- Object.defineProperties(BillboardCollection.prototype, {
-
- length: {
- get: function () {
- removeBillboards(this);
- return this._billboards.length;
- },
- },
-
- textureAtlas: {
- get: function () {
- return this._textureAtlas;
- },
- set: function (value) {
- if (this._textureAtlas !== value) {
- this._textureAtlas =
- this._destroyTextureAtlas &&
- this._textureAtlas &&
- this._textureAtlas.destroy();
- this._textureAtlas = value;
- this._createVertexArray = true;
- }
- },
- },
-
- destroyTextureAtlas: {
- get: function () {
- return this._destroyTextureAtlas;
- },
- set: function (value) {
- this._destroyTextureAtlas = value;
- },
- },
- });
- function destroyBillboards(billboards) {
- var length = billboards.length;
- for (var i = 0; i < length; ++i) {
- if (billboards[i]) {
- billboards[i]._destroy();
- }
- }
- }
- BillboardCollection.prototype.add = function (options) {
- var b = new Billboard(options, this);
- b._index = this._billboards.length;
- this._billboards.push(b);
- this._createVertexArray = true;
- return b;
- };
- BillboardCollection.prototype.remove = function (billboard) {
- if (this.contains(billboard)) {
- this._billboards[billboard._index] = null;
- this._billboardsRemoved = true;
- this._createVertexArray = true;
- billboard._destroy();
- return true;
- }
- return false;
- };
- BillboardCollection.prototype.removeAll = function () {
- destroyBillboards(this._billboards);
- this._billboards = [];
- this._billboardsToUpdate = [];
- this._billboardsToUpdateIndex = 0;
- this._billboardsRemoved = false;
- this._createVertexArray = true;
- };
- function removeBillboards(billboardCollection) {
- if (billboardCollection._billboardsRemoved) {
- billboardCollection._billboardsRemoved = false;
- var newBillboards = [];
- var billboards = billboardCollection._billboards;
- var length = billboards.length;
- for (var i = 0, j = 0; i < length; ++i) {
- var billboard = billboards[i];
- if (billboard) {
- billboard._index = j++;
- newBillboards.push(billboard);
- }
- }
- billboardCollection._billboards = newBillboards;
- }
- }
- BillboardCollection.prototype._updateBillboard = function (
- billboard,
- propertyChanged
- ) {
- if (!billboard._dirty) {
- this._billboardsToUpdate[this._billboardsToUpdateIndex++] = billboard;
- }
- ++this._propertiesChanged[propertyChanged];
- };
- BillboardCollection.prototype.contains = function (billboard) {
- return defined(billboard) && billboard._billboardCollection === this;
- };
- BillboardCollection.prototype.get = function (index) {
-
- if (!defined(index)) {
- throw new DeveloperError("index is required.");
- }
-
- removeBillboards(this);
- return this._billboards[index];
- };
- var getIndexBuffer;
- function getIndexBufferBatched(context) {
- var sixteenK = 16 * 1024;
- var indexBuffer = context.cache.billboardCollection_indexBufferBatched;
- if (defined(indexBuffer)) {
- return indexBuffer;
- }
-
-
- var length = sixteenK * 6 - 6;
- var indices = new Uint16Array(length);
- for (var i = 0, j = 0; i < length; i += 6, j += 4) {
- indices[i] = j;
- indices[i + 1] = j + 1;
- indices[i + 2] = j + 2;
- indices[i + 3] = j + 0;
- indices[i + 4] = j + 2;
- indices[i + 5] = j + 3;
- }
-
-
- indexBuffer = Buffer.createIndexBuffer({
- context: context,
- typedArray: indices,
- usage: BufferUsage.STATIC_DRAW,
- indexDatatype: IndexDatatype.UNSIGNED_SHORT,
- });
- indexBuffer.vertexArrayDestroyable = false;
- context.cache.billboardCollection_indexBufferBatched = indexBuffer;
- return indexBuffer;
- }
- function getIndexBufferInstanced(context) {
- var indexBuffer = context.cache.billboardCollection_indexBufferInstanced;
- if (defined(indexBuffer)) {
- return indexBuffer;
- }
- indexBuffer = Buffer.createIndexBuffer({
- context: context,
- typedArray: new Uint16Array([0, 1, 2, 0, 2, 3]),
- usage: BufferUsage.STATIC_DRAW,
- indexDatatype: IndexDatatype.UNSIGNED_SHORT,
- });
- indexBuffer.vertexArrayDestroyable = false;
- context.cache.billboardCollection_indexBufferInstanced = indexBuffer;
- return indexBuffer;
- }
- function getVertexBufferInstanced(context) {
- var vertexBuffer = context.cache.billboardCollection_vertexBufferInstanced;
- if (defined(vertexBuffer)) {
- return vertexBuffer;
- }
- vertexBuffer = Buffer.createVertexBuffer({
- context: context,
- typedArray: new Float32Array([0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0]),
- usage: BufferUsage.STATIC_DRAW,
- });
- vertexBuffer.vertexArrayDestroyable = false;
- context.cache.billboardCollection_vertexBufferInstanced = vertexBuffer;
- return vertexBuffer;
- }
- BillboardCollection.prototype.computeNewBuffersUsage = function () {
- var buffersUsage = this._buffersUsage;
- var usageChanged = false;
- var properties = this._propertiesChanged;
- for (var k = 0; k < NUMBER_OF_PROPERTIES; ++k) {
- var newUsage =
- properties[k] === 0 ? BufferUsage.STATIC_DRAW : BufferUsage.STREAM_DRAW;
- usageChanged = usageChanged || buffersUsage[k] !== newUsage;
- buffersUsage[k] = newUsage;
- }
- return usageChanged;
- };
- function createVAF(
- context,
- numberOfBillboards,
- buffersUsage,
- instanced,
- batchTable,
- sdf
- ) {
- var attributes = [
- {
- index: attributeLocations.positionHighAndScale,
- componentsPerAttribute: 4,
- componentDatatype: ComponentDatatype.FLOAT,
- usage: buffersUsage[POSITION_INDEX],
- },
- {
- index: attributeLocations.positionLowAndRotation,
- componentsPerAttribute: 4,
- componentDatatype: ComponentDatatype.FLOAT,
- usage: buffersUsage[POSITION_INDEX],
- },
- {
- index: attributeLocations.compressedAttribute0,
- componentsPerAttribute: 4,
- componentDatatype: ComponentDatatype.FLOAT,
- usage: buffersUsage[PIXEL_OFFSET_INDEX],
- },
- {
- index: attributeLocations.compressedAttribute1,
- componentsPerAttribute: 4,
- componentDatatype: ComponentDatatype.FLOAT,
- usage: buffersUsage[TRANSLUCENCY_BY_DISTANCE_INDEX],
- },
- {
- index: attributeLocations.compressedAttribute2,
- componentsPerAttribute: 4,
- componentDatatype: ComponentDatatype.FLOAT,
- usage: buffersUsage[COLOR_INDEX],
- },
- {
- index: attributeLocations.eyeOffset,
- componentsPerAttribute: 4,
- componentDatatype: ComponentDatatype.FLOAT,
- usage: buffersUsage[EYE_OFFSET_INDEX],
- },
- {
- index: attributeLocations.scaleByDistance,
- componentsPerAttribute: 4,
- componentDatatype: ComponentDatatype.FLOAT,
- usage: buffersUsage[SCALE_BY_DISTANCE_INDEX],
- },
- {
- index: attributeLocations.pixelOffsetScaleByDistance,
- componentsPerAttribute: 4,
- componentDatatype: ComponentDatatype.FLOAT,
- usage: buffersUsage[PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX],
- },
- {
- index: attributeLocations.compressedAttribute3,
- componentsPerAttribute: 4,
- componentDatatype: ComponentDatatype.FLOAT,
- usage: buffersUsage[DISTANCE_DISPLAY_CONDITION_INDEX],
- },
- {
- index: attributeLocations.textureCoordinateBoundsOrLabelTranslate,
- componentsPerAttribute: 4,
- componentDatatype: ComponentDatatype.FLOAT,
- usage: buffersUsage[TEXTURE_COORDINATE_BOUNDS],
- },
- ];
-
- if (instanced) {
- attributes.push({
- index: attributeLocations.direction,
- componentsPerAttribute: 2,
- componentDatatype: ComponentDatatype.FLOAT,
- vertexBuffer: getVertexBufferInstanced(context),
- });
- }
- if (defined(batchTable)) {
- attributes.push({
- index: attributeLocations.a_batchId,
- componentsPerAttribute: 1,
- componentDatatype: ComponentDatatype.FLOAT,
- bufferUsage: BufferUsage.STATIC_DRAW,
- });
- }
- if (sdf) {
- attributes.push({
- index: attributeLocations.sdf,
- componentsPerAttribute: 2,
- componentDatatype: ComponentDatatype.FLOAT,
- usage: buffersUsage[SDF_INDEX],
- });
- }
-
- var sizeInVertices = instanced ? numberOfBillboards : 4 * numberOfBillboards;
- return new VertexArrayFacade(context, attributes, sizeInVertices, instanced);
- }
- var writePositionScratch = new EncodedCartesian3();
- function writePositionScaleAndRotation(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- ) {
- var i;
- var positionHighWriter = vafWriters[attributeLocations.positionHighAndScale];
- var positionLowWriter = vafWriters[attributeLocations.positionLowAndRotation];
- var position = billboard._getActualPosition();
- if (billboardCollection._mode === SceneMode.SCENE3D) {
- BoundingSphere.expand(
- billboardCollection._baseVolume,
- position,
- billboardCollection._baseVolume
- );
- billboardCollection._boundingVolumeDirty = true;
- }
- EncodedCartesian3.fromCartesian(position, writePositionScratch);
- var scale = billboard.scale;
- var rotation = billboard.rotation;
- if (rotation !== 0.0) {
- billboardCollection._shaderRotation = true;
- }
- billboardCollection._maxScale = Math.max(
- billboardCollection._maxScale,
- scale
- );
- var high = writePositionScratch.high;
- var low = writePositionScratch.low;
- if (billboardCollection._instanced) {
- i = billboard._index;
- positionHighWriter(i, high.x, high.y, high.z, scale);
- positionLowWriter(i, low.x, low.y, low.z, rotation);
- } else {
- i = billboard._index * 4;
- positionHighWriter(i + 0, high.x, high.y, high.z, scale);
- positionHighWriter(i + 1, high.x, high.y, high.z, scale);
- positionHighWriter(i + 2, high.x, high.y, high.z, scale);
- positionHighWriter(i + 3, high.x, high.y, high.z, scale);
- positionLowWriter(i + 0, low.x, low.y, low.z, rotation);
- positionLowWriter(i + 1, low.x, low.y, low.z, rotation);
- positionLowWriter(i + 2, low.x, low.y, low.z, rotation);
- positionLowWriter(i + 3, low.x, low.y, low.z, rotation);
- }
- }
- var scratchCartesian2 = new Cartesian2();
- var UPPER_BOUND = 32768.0;
- var LEFT_SHIFT16 = 65536.0;
- var LEFT_SHIFT12 = 4096.0;
- var LEFT_SHIFT8 = 256.0;
- var LEFT_SHIFT7 = 128.0;
- var LEFT_SHIFT5 = 32.0;
- var LEFT_SHIFT3 = 8.0;
- var LEFT_SHIFT2 = 4.0;
- var RIGHT_SHIFT8 = 1.0 / 256.0;
- var LOWER_LEFT = 0.0;
- var LOWER_RIGHT = 2.0;
- var UPPER_RIGHT = 3.0;
- var UPPER_LEFT = 1.0;
- function writeCompressedAttrib0(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- ) {
- var i;
- var writer = vafWriters[attributeLocations.compressedAttribute0];
- var pixelOffset = billboard.pixelOffset;
- var pixelOffsetX = pixelOffset.x;
- var pixelOffsetY = pixelOffset.y;
- var translate = billboard._translate;
- var translateX = translate.x;
- var translateY = translate.y;
- billboardCollection._maxPixelOffset = Math.max(
- billboardCollection._maxPixelOffset,
- Math.abs(pixelOffsetX + translateX),
- Math.abs(-pixelOffsetY + translateY)
- );
- var horizontalOrigin = billboard.horizontalOrigin;
- var verticalOrigin = billboard._verticalOrigin;
- var show = billboard.show && billboard.clusterShow;
-
-
- if (billboard.color.alpha === 0.0) {
- show = false;
- }
-
- if (verticalOrigin === VerticalOrigin.BASELINE) {
- verticalOrigin = VerticalOrigin.BOTTOM;
- }
- billboardCollection._allHorizontalCenter =
- billboardCollection._allHorizontalCenter &&
- horizontalOrigin === HorizontalOrigin.CENTER;
- billboardCollection._allVerticalCenter =
- billboardCollection._allVerticalCenter &&
- verticalOrigin === VerticalOrigin.CENTER;
- var bottomLeftX = 0;
- var bottomLeftY = 0;
- var width = 0;
- var height = 0;
- var index = billboard._imageIndex;
- if (index !== -1) {
- var imageRectangle = textureAtlasCoordinates[index];
-
- if (!defined(imageRectangle)) {
- throw new DeveloperError("Invalid billboard image index: " + index);
- }
-
- bottomLeftX = imageRectangle.x;
- bottomLeftY = imageRectangle.y;
- width = imageRectangle.width;
- height = imageRectangle.height;
- }
- var topRightX = bottomLeftX + width;
- var topRightY = bottomLeftY + height;
- var compressed0 =
- Math.floor(
- CesiumMath.clamp(pixelOffsetX, -UPPER_BOUND, UPPER_BOUND) + UPPER_BOUND
- ) * LEFT_SHIFT7;
- compressed0 += (horizontalOrigin + 1.0) * LEFT_SHIFT5;
- compressed0 += (verticalOrigin + 1.0) * LEFT_SHIFT3;
- compressed0 += (show ? 1.0 : 0.0) * LEFT_SHIFT2;
- var compressed1 =
- Math.floor(
- CesiumMath.clamp(pixelOffsetY, -UPPER_BOUND, UPPER_BOUND) + UPPER_BOUND
- ) * LEFT_SHIFT8;
- var compressed2 =
- Math.floor(
- CesiumMath.clamp(translateX, -UPPER_BOUND, UPPER_BOUND) + UPPER_BOUND
- ) * LEFT_SHIFT8;
- var tempTanslateY =
- (CesiumMath.clamp(translateY, -UPPER_BOUND, UPPER_BOUND) + UPPER_BOUND) *
- RIGHT_SHIFT8;
- var upperTranslateY = Math.floor(tempTanslateY);
- var lowerTranslateY = Math.floor(
- (tempTanslateY - upperTranslateY) * LEFT_SHIFT8
- );
- compressed1 += upperTranslateY;
- compressed2 += lowerTranslateY;
- scratchCartesian2.x = bottomLeftX;
- scratchCartesian2.y = bottomLeftY;
- var compressedTexCoordsLL = AttributeCompression.compressTextureCoordinates(
- scratchCartesian2
- );
- scratchCartesian2.x = topRightX;
- var compressedTexCoordsLR = AttributeCompression.compressTextureCoordinates(
- scratchCartesian2
- );
- scratchCartesian2.y = topRightY;
- var compressedTexCoordsUR = AttributeCompression.compressTextureCoordinates(
- scratchCartesian2
- );
- scratchCartesian2.x = bottomLeftX;
- var compressedTexCoordsUL = AttributeCompression.compressTextureCoordinates(
- scratchCartesian2
- );
- if (billboardCollection._instanced) {
- i = billboard._index;
- writer(i, compressed0, compressed1, compressed2, compressedTexCoordsLL);
- } else {
- i = billboard._index * 4;
- writer(
- i + 0,
- compressed0 + LOWER_LEFT,
- compressed1,
- compressed2,
- compressedTexCoordsLL
- );
- writer(
- i + 1,
- compressed0 + LOWER_RIGHT,
- compressed1,
- compressed2,
- compressedTexCoordsLR
- );
- writer(
- i + 2,
- compressed0 + UPPER_RIGHT,
- compressed1,
- compressed2,
- compressedTexCoordsUR
- );
- writer(
- i + 3,
- compressed0 + UPPER_LEFT,
- compressed1,
- compressed2,
- compressedTexCoordsUL
- );
- }
- }
- function writeCompressedAttrib1(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- ) {
- var i;
- var writer = vafWriters[attributeLocations.compressedAttribute1];
- var alignedAxis = billboard.alignedAxis;
- if (!Cartesian3.equals(alignedAxis, Cartesian3.ZERO)) {
- billboardCollection._shaderAlignedAxis = true;
- }
- var near = 0.0;
- var nearValue = 1.0;
- var far = 1.0;
- var farValue = 1.0;
- var translucency = billboard.translucencyByDistance;
- if (defined(translucency)) {
- near = translucency.near;
- nearValue = translucency.nearValue;
- far = translucency.far;
- farValue = translucency.farValue;
- if (nearValue !== 1.0 || farValue !== 1.0) {
-
-
- billboardCollection._shaderTranslucencyByDistance = true;
- }
- }
- var width = 0;
- var index = billboard._imageIndex;
- if (index !== -1) {
- var imageRectangle = textureAtlasCoordinates[index];
-
- if (!defined(imageRectangle)) {
- throw new DeveloperError("Invalid billboard image index: " + index);
- }
-
- width = imageRectangle.width;
- }
- var textureWidth = billboardCollection._textureAtlas.texture.width;
- var imageWidth = Math.round(
- defaultValue(billboard.width, textureWidth * width)
- );
- billboardCollection._maxSize = Math.max(
- billboardCollection._maxSize,
- imageWidth
- );
- var compressed0 = CesiumMath.clamp(imageWidth, 0.0, LEFT_SHIFT16);
- var compressed1 = 0.0;
- if (
- Math.abs(Cartesian3.magnitudeSquared(alignedAxis) - 1.0) <
- CesiumMath.EPSILON6
- ) {
- compressed1 = AttributeCompression.octEncodeFloat(alignedAxis);
- }
- nearValue = CesiumMath.clamp(nearValue, 0.0, 1.0);
- nearValue = nearValue === 1.0 ? 255.0 : (nearValue * 255.0) | 0;
- compressed0 = compressed0 * LEFT_SHIFT8 + nearValue;
- farValue = CesiumMath.clamp(farValue, 0.0, 1.0);
- farValue = farValue === 1.0 ? 255.0 : (farValue * 255.0) | 0;
- compressed1 = compressed1 * LEFT_SHIFT8 + farValue;
- if (billboardCollection._instanced) {
- i = billboard._index;
- writer(i, compressed0, compressed1, near, far);
- } else {
- i = billboard._index * 4;
- writer(i + 0, compressed0, compressed1, near, far);
- writer(i + 1, compressed0, compressed1, near, far);
- writer(i + 2, compressed0, compressed1, near, far);
- writer(i + 3, compressed0, compressed1, near, far);
- }
- }
- function writeCompressedAttrib2(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- ) {
- var i;
- var writer = vafWriters[attributeLocations.compressedAttribute2];
- var color = billboard.color;
- var pickColor = !defined(billboardCollection._batchTable)
- ? billboard.getPickId(frameState.context).color
- : Color.WHITE;
- var sizeInMeters = billboard.sizeInMeters ? 1.0 : 0.0;
- var validAlignedAxis =
- Math.abs(Cartesian3.magnitudeSquared(billboard.alignedAxis) - 1.0) <
- CesiumMath.EPSILON6
- ? 1.0
- : 0.0;
- billboardCollection._allSizedInMeters =
- billboardCollection._allSizedInMeters && sizeInMeters === 1.0;
- var height = 0;
- var index = billboard._imageIndex;
- if (index !== -1) {
- var imageRectangle = textureAtlasCoordinates[index];
-
- if (!defined(imageRectangle)) {
- throw new DeveloperError("Invalid billboard image index: " + index);
- }
-
- height = imageRectangle.height;
- }
- var dimensions = billboardCollection._textureAtlas.texture.dimensions;
- var imageHeight = Math.round(
- defaultValue(billboard.height, dimensions.y * height)
- );
- billboardCollection._maxSize = Math.max(
- billboardCollection._maxSize,
- imageHeight
- );
- var labelHorizontalOrigin = defaultValue(
- billboard._labelHorizontalOrigin,
- -2
- );
- labelHorizontalOrigin += 2;
- var compressed3 = imageHeight * LEFT_SHIFT2 + labelHorizontalOrigin;
- var red = Color.floatToByte(color.red);
- var green = Color.floatToByte(color.green);
- var blue = Color.floatToByte(color.blue);
- var compressed0 = red * LEFT_SHIFT16 + green * LEFT_SHIFT8 + blue;
- red = Color.floatToByte(pickColor.red);
- green = Color.floatToByte(pickColor.green);
- blue = Color.floatToByte(pickColor.blue);
- var compressed1 = red * LEFT_SHIFT16 + green * LEFT_SHIFT8 + blue;
- var compressed2 =
- Color.floatToByte(color.alpha) * LEFT_SHIFT16 +
- Color.floatToByte(pickColor.alpha) * LEFT_SHIFT8;
- compressed2 += sizeInMeters * 2.0 + validAlignedAxis;
- if (billboardCollection._instanced) {
- i = billboard._index;
- writer(i, compressed0, compressed1, compressed2, compressed3);
- } else {
- i = billboard._index * 4;
- writer(i + 0, compressed0, compressed1, compressed2, compressed3);
- writer(i + 1, compressed0, compressed1, compressed2, compressed3);
- writer(i + 2, compressed0, compressed1, compressed2, compressed3);
- writer(i + 3, compressed0, compressed1, compressed2, compressed3);
- }
- }
- function writeEyeOffset(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- ) {
- var i;
- var writer = vafWriters[attributeLocations.eyeOffset];
- var eyeOffset = billboard.eyeOffset;
-
- var eyeOffsetZ = eyeOffset.z;
- if (billboard._heightReference !== HeightReference.NONE) {
- eyeOffsetZ *= 1.005;
- }
- billboardCollection._maxEyeOffset = Math.max(
- billboardCollection._maxEyeOffset,
- Math.abs(eyeOffset.x),
- Math.abs(eyeOffset.y),
- Math.abs(eyeOffsetZ)
- );
- if (billboardCollection._instanced) {
- var width = 0;
- var height = 0;
- var index = billboard._imageIndex;
- if (index !== -1) {
- var imageRectangle = textureAtlasCoordinates[index];
-
- if (!defined(imageRectangle)) {
- throw new DeveloperError("Invalid billboard image index: " + index);
- }
-
- width = imageRectangle.width;
- height = imageRectangle.height;
- }
- scratchCartesian2.x = width;
- scratchCartesian2.y = height;
- var compressedTexCoordsRange = AttributeCompression.compressTextureCoordinates(
- scratchCartesian2
- );
- i = billboard._index;
- writer(i, eyeOffset.x, eyeOffset.y, eyeOffsetZ, compressedTexCoordsRange);
- } else {
- i = billboard._index * 4;
- writer(i + 0, eyeOffset.x, eyeOffset.y, eyeOffsetZ, 0.0);
- writer(i + 1, eyeOffset.x, eyeOffset.y, eyeOffsetZ, 0.0);
- writer(i + 2, eyeOffset.x, eyeOffset.y, eyeOffsetZ, 0.0);
- writer(i + 3, eyeOffset.x, eyeOffset.y, eyeOffsetZ, 0.0);
- }
- }
- function writeScaleByDistance(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- ) {
- var i;
- var writer = vafWriters[attributeLocations.scaleByDistance];
- var near = 0.0;
- var nearValue = 1.0;
- var far = 1.0;
- var farValue = 1.0;
- var scale = billboard.scaleByDistance;
- if (defined(scale)) {
- near = scale.near;
- nearValue = scale.nearValue;
- far = scale.far;
- farValue = scale.farValue;
- if (nearValue !== 1.0 || farValue !== 1.0) {
-
-
- billboardCollection._shaderScaleByDistance = true;
- }
- }
- if (billboardCollection._instanced) {
- i = billboard._index;
- writer(i, near, nearValue, far, farValue);
- } else {
- i = billboard._index * 4;
- writer(i + 0, near, nearValue, far, farValue);
- writer(i + 1, near, nearValue, far, farValue);
- writer(i + 2, near, nearValue, far, farValue);
- writer(i + 3, near, nearValue, far, farValue);
- }
- }
- function writePixelOffsetScaleByDistance(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- ) {
- var i;
- var writer = vafWriters[attributeLocations.pixelOffsetScaleByDistance];
- var near = 0.0;
- var nearValue = 1.0;
- var far = 1.0;
- var farValue = 1.0;
- var pixelOffsetScale = billboard.pixelOffsetScaleByDistance;
- if (defined(pixelOffsetScale)) {
- near = pixelOffsetScale.near;
- nearValue = pixelOffsetScale.nearValue;
- far = pixelOffsetScale.far;
- farValue = pixelOffsetScale.farValue;
- if (nearValue !== 1.0 || farValue !== 1.0) {
-
-
- billboardCollection._shaderPixelOffsetScaleByDistance = true;
- }
- }
- if (billboardCollection._instanced) {
- i = billboard._index;
- writer(i, near, nearValue, far, farValue);
- } else {
- i = billboard._index * 4;
- writer(i + 0, near, nearValue, far, farValue);
- writer(i + 1, near, nearValue, far, farValue);
- writer(i + 2, near, nearValue, far, farValue);
- writer(i + 3, near, nearValue, far, farValue);
- }
- }
- function writeCompressedAttribute3(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- ) {
- var i;
- var writer = vafWriters[attributeLocations.compressedAttribute3];
- var near = 0.0;
- var far = Number.MAX_VALUE;
- var distanceDisplayCondition = billboard.distanceDisplayCondition;
- if (defined(distanceDisplayCondition)) {
- near = distanceDisplayCondition.near;
- far = distanceDisplayCondition.far;
- near *= near;
- far *= far;
- billboardCollection._shaderDistanceDisplayCondition = true;
- }
- var disableDepthTestDistance = billboard.disableDepthTestDistance;
- var clampToGround =
- billboard.heightReference === HeightReference.CLAMP_TO_GROUND &&
- frameState.context.depthTexture;
- if (!defined(disableDepthTestDistance)) {
- disableDepthTestDistance = clampToGround ? 5000.0 : 0.0;
- }
- disableDepthTestDistance *= disableDepthTestDistance;
- if (clampToGround || disableDepthTestDistance > 0.0) {
- billboardCollection._shaderDisableDepthDistance = true;
- if (disableDepthTestDistance === Number.POSITIVE_INFINITY) {
- disableDepthTestDistance = -1.0;
- }
- }
- var imageHeight;
- var imageWidth;
- if (!defined(billboard._labelDimensions)) {
- var height = 0;
- var width = 0;
- var index = billboard._imageIndex;
- if (index !== -1) {
- var imageRectangle = textureAtlasCoordinates[index];
-
- if (!defined(imageRectangle)) {
- throw new DeveloperError("Invalid billboard image index: " + index);
- }
-
- height = imageRectangle.height;
- width = imageRectangle.width;
- }
- imageHeight = Math.round(
- defaultValue(
- billboard.height,
- billboardCollection._textureAtlas.texture.dimensions.y * height
- )
- );
- var textureWidth = billboardCollection._textureAtlas.texture.width;
- imageWidth = Math.round(
- defaultValue(billboard.width, textureWidth * width)
- );
- } else {
- imageWidth = billboard._labelDimensions.x;
- imageHeight = billboard._labelDimensions.y;
- }
- var w = Math.floor(CesiumMath.clamp(imageWidth, 0.0, LEFT_SHIFT12));
- var h = Math.floor(CesiumMath.clamp(imageHeight, 0.0, LEFT_SHIFT12));
- var dimensions = w * LEFT_SHIFT12 + h;
- if (billboardCollection._instanced) {
- i = billboard._index;
- writer(i, near, far, disableDepthTestDistance, dimensions);
- } else {
- i = billboard._index * 4;
- writer(i + 0, near, far, disableDepthTestDistance, dimensions);
- writer(i + 1, near, far, disableDepthTestDistance, dimensions);
- writer(i + 2, near, far, disableDepthTestDistance, dimensions);
- writer(i + 3, near, far, disableDepthTestDistance, dimensions);
- }
- }
- function writeTextureCoordinateBoundsOrLabelTranslate(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- ) {
- if (billboard.heightReference === HeightReference.CLAMP_TO_GROUND) {
- var scene = billboardCollection._scene;
- var context = frameState.context;
- var globeTranslucent = frameState.globeTranslucencyState.translucent;
- var depthTestAgainstTerrain =
- defined(scene.globe) && scene.globe.depthTestAgainstTerrain;
-
- billboardCollection._shaderClampToGround =
- context.depthTexture && !globeTranslucent && depthTestAgainstTerrain;
- }
- var i;
- var writer =
- vafWriters[attributeLocations.textureCoordinateBoundsOrLabelTranslate];
- if (ContextLimits.maximumVertexTextureImageUnits > 0) {
-
- var translateX = 0;
- var translateY = 0;
- if (defined(billboard._labelTranslate)) {
- translateX = billboard._labelTranslate.x;
- translateY = billboard._labelTranslate.y;
- }
- if (billboardCollection._instanced) {
- i = billboard._index;
- writer(i, translateX, translateY, 0.0, 0.0);
- } else {
- i = billboard._index * 4;
- writer(i + 0, translateX, translateY, 0.0, 0.0);
- writer(i + 1, translateX, translateY, 0.0, 0.0);
- writer(i + 2, translateX, translateY, 0.0, 0.0);
- writer(i + 3, translateX, translateY, 0.0, 0.0);
- }
- return;
- }
-
- var minX = 0;
- var minY = 0;
- var width = 0;
- var height = 0;
- var index = billboard._imageIndex;
- if (index !== -1) {
- var imageRectangle = textureAtlasCoordinates[index];
-
- if (!defined(imageRectangle)) {
- throw new DeveloperError("Invalid billboard image index: " + index);
- }
-
- minX = imageRectangle.x;
- minY = imageRectangle.y;
- width = imageRectangle.width;
- height = imageRectangle.height;
- }
- var maxX = minX + width;
- var maxY = minY + height;
- if (billboardCollection._instanced) {
- i = billboard._index;
- writer(i, minX, minY, maxX, maxY);
- } else {
- i = billboard._index * 4;
- writer(i + 0, minX, minY, maxX, maxY);
- writer(i + 1, minX, minY, maxX, maxY);
- writer(i + 2, minX, minY, maxX, maxY);
- writer(i + 3, minX, minY, maxX, maxY);
- }
- }
- function writeBatchId(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- ) {
- if (!defined(billboardCollection._batchTable)) {
- return;
- }
- var writer = vafWriters[attributeLocations.a_batchId];
- var id = billboard._batchIndex;
- var i;
- if (billboardCollection._instanced) {
- i = billboard._index;
- writer(i, id);
- } else {
- i = billboard._index * 4;
- writer(i + 0, id);
- writer(i + 1, id);
- writer(i + 2, id);
- writer(i + 3, id);
- }
- }
- function writeSDF(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- ) {
- if (!billboardCollection._sdf) {
- return;
- }
- var i;
- var writer = vafWriters[attributeLocations.sdf];
- var outlineColor = billboard.outlineColor;
- var outlineWidth = billboard.outlineWidth;
- var red = Color.floatToByte(outlineColor.red);
- var green = Color.floatToByte(outlineColor.green);
- var blue = Color.floatToByte(outlineColor.blue);
- var compressed0 = red * LEFT_SHIFT16 + green * LEFT_SHIFT8 + blue;
-
- var outlineDistance = outlineWidth / SDFSettings.RADIUS;
- var compressed1 =
- Color.floatToByte(outlineColor.alpha) * LEFT_SHIFT16 +
- Color.floatToByte(outlineDistance) * LEFT_SHIFT8;
- if (billboardCollection._instanced) {
- i = billboard._index;
- writer(i, compressed0, compressed1);
- } else {
- i = billboard._index * 4;
- writer(i + 0, compressed0 + LOWER_LEFT, compressed1);
- writer(i + 1, compressed0 + LOWER_RIGHT, compressed1);
- writer(i + 2, compressed0 + UPPER_RIGHT, compressed1);
- writer(i + 3, compressed0 + UPPER_LEFT, compressed1);
- }
- }
- function writeBillboard(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- ) {
- writePositionScaleAndRotation(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- );
- writeCompressedAttrib0(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- );
- writeCompressedAttrib1(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- );
- writeCompressedAttrib2(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- );
- writeEyeOffset(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- );
- writeScaleByDistance(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- );
- writePixelOffsetScaleByDistance(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- );
- writeCompressedAttribute3(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- );
- writeTextureCoordinateBoundsOrLabelTranslate(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- );
- writeBatchId(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- );
- writeSDF(
- billboardCollection,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- );
- }
- function recomputeActualPositions(
- billboardCollection,
- billboards,
- length,
- frameState,
- modelMatrix,
- recomputeBoundingVolume
- ) {
- var boundingVolume;
- if (frameState.mode === SceneMode.SCENE3D) {
- boundingVolume = billboardCollection._baseVolume;
- billboardCollection._boundingVolumeDirty = true;
- } else {
- boundingVolume = billboardCollection._baseVolume2D;
- }
- var positions = [];
- for (var i = 0; i < length; ++i) {
- var billboard = billboards[i];
- var position = billboard.position;
- var actualPosition = Billboard._computeActualPosition(
- billboard,
- position,
- frameState,
- modelMatrix
- );
- if (defined(actualPosition)) {
- billboard._setActualPosition(actualPosition);
- if (recomputeBoundingVolume) {
- positions.push(actualPosition);
- } else {
- BoundingSphere.expand(boundingVolume, actualPosition, boundingVolume);
- }
- }
- }
- if (recomputeBoundingVolume) {
- BoundingSphere.fromPoints(positions, boundingVolume);
- }
- }
- function updateMode(billboardCollection, frameState) {
- var mode = frameState.mode;
- var billboards = billboardCollection._billboards;
- var billboardsToUpdate = billboardCollection._billboardsToUpdate;
- var modelMatrix = billboardCollection._modelMatrix;
- if (
- billboardCollection._createVertexArray ||
- billboardCollection._mode !== mode ||
- (mode !== SceneMode.SCENE3D &&
- !Matrix4.equals(modelMatrix, billboardCollection.modelMatrix))
- ) {
- billboardCollection._mode = mode;
- Matrix4.clone(billboardCollection.modelMatrix, modelMatrix);
- billboardCollection._createVertexArray = true;
- if (
- mode === SceneMode.SCENE3D ||
- mode === SceneMode.SCENE2D ||
- mode === SceneMode.COLUMBUS_VIEW
- ) {
- recomputeActualPositions(
- billboardCollection,
- billboards,
- billboards.length,
- frameState,
- modelMatrix,
- true
- );
- }
- } else if (mode === SceneMode.MORPHING) {
- recomputeActualPositions(
- billboardCollection,
- billboards,
- billboards.length,
- frameState,
- modelMatrix,
- true
- );
- } else if (mode === SceneMode.SCENE2D || mode === SceneMode.COLUMBUS_VIEW) {
- recomputeActualPositions(
- billboardCollection,
- billboardsToUpdate,
- billboardCollection._billboardsToUpdateIndex,
- frameState,
- modelMatrix,
- false
- );
- }
- }
- function updateBoundingVolume(collection, frameState, boundingVolume) {
- var pixelScale = 1.0;
- if (!collection._allSizedInMeters || collection._maxPixelOffset !== 0.0) {
- pixelScale = frameState.camera.getPixelSize(
- boundingVolume,
- frameState.context.drawingBufferWidth,
- frameState.context.drawingBufferHeight
- );
- }
- var size = pixelScale * collection._maxScale * collection._maxSize * 2.0;
- if (collection._allHorizontalCenter && collection._allVerticalCenter) {
- size *= 0.5;
- }
- var offset =
- pixelScale * collection._maxPixelOffset + collection._maxEyeOffset;
- boundingVolume.radius += size + offset;
- }
- function createDebugCommand(billboardCollection, context) {
- var fs;
- fs =
- "uniform sampler2D billboard_texture; \n" +
- "varying vec2 v_textureCoordinates; \n" +
- "void main() \n" +
- "{ \n" +
- " gl_FragColor = texture2D(billboard_texture, v_textureCoordinates); \n" +
- "} \n";
- var drawCommand = context.createViewportQuadCommand(fs, {
- uniformMap: {
- billboard_texture: function () {
- return billboardCollection._textureAtlas.texture;
- },
- },
- });
- drawCommand.pass = Pass.OVERLAY;
- return drawCommand;
- }
- var scratchWriterArray = [];
- BillboardCollection.prototype.update = function (frameState) {
- removeBillboards(this);
- var billboards = this._billboards;
- var billboardsLength = billboards.length;
- var context = frameState.context;
- this._instanced = context.instancedArrays;
- attributeLocations = this._instanced
- ? attributeLocationsInstanced
- : attributeLocationsBatched;
- getIndexBuffer = this._instanced
- ? getIndexBufferInstanced
- : getIndexBufferBatched;
- var textureAtlas = this._textureAtlas;
- if (!defined(textureAtlas)) {
- textureAtlas = this._textureAtlas = new TextureAtlas({
- context: context,
- });
- for (var ii = 0; ii < billboardsLength; ++ii) {
- billboards[ii]._loadImage();
- }
- }
- var textureAtlasCoordinates = textureAtlas.textureCoordinates;
- if (textureAtlasCoordinates.length === 0) {
-
-
- return;
- }
- updateMode(this, frameState);
- billboards = this._billboards;
- billboardsLength = billboards.length;
- var billboardsToUpdate = this._billboardsToUpdate;
- var billboardsToUpdateLength = this._billboardsToUpdateIndex;
- var properties = this._propertiesChanged;
- var textureAtlasGUID = textureAtlas.guid;
- var createVertexArray =
- this._createVertexArray || this._textureAtlasGUID !== textureAtlasGUID;
- this._textureAtlasGUID = textureAtlasGUID;
- var vafWriters;
- var pass = frameState.passes;
- var picking = pass.pick;
-
- if (createVertexArray || (!picking && this.computeNewBuffersUsage())) {
- this._createVertexArray = false;
- for (var k = 0; k < NUMBER_OF_PROPERTIES; ++k) {
- properties[k] = 0;
- }
- this._vaf = this._vaf && this._vaf.destroy();
- if (billboardsLength > 0) {
-
- this._vaf = createVAF(
- context,
- billboardsLength,
- this._buffersUsage,
- this._instanced,
- this._batchTable,
- this._sdf
- );
- vafWriters = this._vaf.writers;
-
- for (var i = 0; i < billboardsLength; ++i) {
- var billboard = this._billboards[i];
- billboard._dirty = false;
- writeBillboard(
- this,
- frameState,
- textureAtlasCoordinates,
- vafWriters,
- billboard
- );
- }
-
- this._vaf.commit(getIndexBuffer(context));
- }
- this._billboardsToUpdateIndex = 0;
- } else if (billboardsToUpdateLength > 0) {
-
- var writers = scratchWriterArray;
- writers.length = 0;
- if (
- properties[POSITION_INDEX] ||
- properties[ROTATION_INDEX] ||
- properties[SCALE_INDEX]
- ) {
- writers.push(writePositionScaleAndRotation);
- }
- if (
- properties[IMAGE_INDEX_INDEX] ||
- properties[PIXEL_OFFSET_INDEX] ||
- properties[HORIZONTAL_ORIGIN_INDEX] ||
- properties[VERTICAL_ORIGIN_INDEX] ||
- properties[SHOW_INDEX]
- ) {
- writers.push(writeCompressedAttrib0);
- if (this._instanced) {
- writers.push(writeEyeOffset);
- }
- }
- if (
- properties[IMAGE_INDEX_INDEX] ||
- properties[ALIGNED_AXIS_INDEX] ||
- properties[TRANSLUCENCY_BY_DISTANCE_INDEX]
- ) {
- writers.push(writeCompressedAttrib1);
- writers.push(writeCompressedAttrib2);
- }
- if (properties[IMAGE_INDEX_INDEX] || properties[COLOR_INDEX]) {
- writers.push(writeCompressedAttrib2);
- }
- if (properties[EYE_OFFSET_INDEX]) {
- writers.push(writeEyeOffset);
- }
- if (properties[SCALE_BY_DISTANCE_INDEX]) {
- writers.push(writeScaleByDistance);
- }
- if (properties[PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX]) {
- writers.push(writePixelOffsetScaleByDistance);
- }
- if (
- properties[DISTANCE_DISPLAY_CONDITION_INDEX] ||
- properties[DISABLE_DEPTH_DISTANCE] ||
- properties[IMAGE_INDEX_INDEX] ||
- properties[POSITION_INDEX]
- ) {
- writers.push(writeCompressedAttribute3);
- }
- if (properties[IMAGE_INDEX_INDEX] || properties[POSITION_INDEX]) {
- writers.push(writeTextureCoordinateBoundsOrLabelTranslate);
- }
- if (properties[SDF_INDEX]) {
- writers.push(writeSDF);
- }
- var numWriters = writers.length;
- vafWriters = this._vaf.writers;
- if (billboardsToUpdateLength / billboardsLength > 0.1) {
-
-
- for (var m = 0; m < billboardsToUpdateLength; ++m) {
- var b = billboardsToUpdate[m];
- b._dirty = false;
- for (var n = 0; n < numWriters; ++n) {
- writers[n](this, frameState, textureAtlasCoordinates, vafWriters, b);
- }
- }
- this._vaf.commit(getIndexBuffer(context));
- } else {
- for (var h = 0; h < billboardsToUpdateLength; ++h) {
- var bb = billboardsToUpdate[h];
- bb._dirty = false;
- for (var o = 0; o < numWriters; ++o) {
- writers[o](this, frameState, textureAtlasCoordinates, vafWriters, bb);
- }
- if (this._instanced) {
- this._vaf.subCommit(bb._index, 1);
- } else {
- this._vaf.subCommit(bb._index * 4, 4);
- }
- }
- this._vaf.endSubCommits();
- }
- this._billboardsToUpdateIndex = 0;
- }
-
-
-
- if (billboardsToUpdateLength > billboardsLength * 1.5) {
- billboardsToUpdate.length = billboardsLength;
- }
- if (!defined(this._vaf) || !defined(this._vaf.va)) {
- return;
- }
- if (this._boundingVolumeDirty) {
- this._boundingVolumeDirty = false;
- BoundingSphere.transform(
- this._baseVolume,
- this.modelMatrix,
- this._baseVolumeWC
- );
- }
- var boundingVolume;
- var modelMatrix = Matrix4.IDENTITY;
- if (frameState.mode === SceneMode.SCENE3D) {
- modelMatrix = this.modelMatrix;
- boundingVolume = BoundingSphere.clone(
- this._baseVolumeWC,
- this._boundingVolume
- );
- } else {
- boundingVolume = BoundingSphere.clone(
- this._baseVolume2D,
- this._boundingVolume
- );
- }
- updateBoundingVolume(this, frameState, boundingVolume);
- var blendOptionChanged = this._blendOption !== this.blendOption;
- this._blendOption = this.blendOption;
- if (blendOptionChanged) {
- if (
- this._blendOption === BlendOption.OPAQUE ||
- this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT
- ) {
- this._rsOpaque = RenderState.fromCache({
- depthTest: {
- enabled: true,
- func: WebGLConstants.LESS,
- },
- depthMask: true,
- });
- } else {
- this._rsOpaque = undefined;
- }
-
-
-
-
- var useTranslucentDepthMask = this._blendOption === BlendOption.TRANSLUCENT;
- if (
- this._blendOption === BlendOption.TRANSLUCENT ||
- this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT
- ) {
- this._rsTranslucent = RenderState.fromCache({
- depthTest: {
- enabled: true,
- func: useTranslucentDepthMask
- ? WebGLConstants.LEQUAL
- : WebGLConstants.LESS,
- },
- depthMask: useTranslucentDepthMask,
- blending: BlendingState.ALPHA_BLEND,
- });
- } else {
- this._rsTranslucent = undefined;
- }
- }
- this._shaderDisableDepthDistance =
- this._shaderDisableDepthDistance ||
- frameState.minimumDisableDepthTestDistance !== 0.0;
- var vsSource;
- var fsSource;
- var vs;
- var fs;
- var vertDefines;
- var supportVSTextureReads = ContextLimits.maximumVertexTextureImageUnits > 0;
- if (
- blendOptionChanged ||
- this._shaderRotation !== this._compiledShaderRotation ||
- this._shaderAlignedAxis !== this._compiledShaderAlignedAxis ||
- this._shaderScaleByDistance !== this._compiledShaderScaleByDistance ||
- this._shaderTranslucencyByDistance !==
- this._compiledShaderTranslucencyByDistance ||
- this._shaderPixelOffsetScaleByDistance !==
- this._compiledShaderPixelOffsetScaleByDistance ||
- this._shaderDistanceDisplayCondition !==
- this._compiledShaderDistanceDisplayCondition ||
- this._shaderDisableDepthDistance !==
- this._compiledShaderDisableDepthDistance ||
- this._shaderClampToGround !== this._compiledShaderClampToGround ||
- this._sdf !== this._compiledSDF
- ) {
- vsSource = BillboardCollectionVS;
- fsSource = BillboardCollectionFS;
- vertDefines = [];
- if (defined(this._batchTable)) {
- vertDefines.push("VECTOR_TILE");
- vsSource = this._batchTable.getVertexShaderCallback(
- false,
- "a_batchId",
- undefined
- )(vsSource);
- fsSource = this._batchTable.getFragmentShaderCallback(
- false,
- undefined
- )(fsSource);
- }
- vs = new ShaderSource({
- defines: vertDefines,
- sources: [vsSource],
- });
- if (this._instanced) {
- vs.defines.push("INSTANCED");
- }
- if (this._shaderRotation) {
- vs.defines.push("ROTATION");
- }
- if (this._shaderAlignedAxis) {
- vs.defines.push("ALIGNED_AXIS");
- }
- if (this._shaderScaleByDistance) {
- vs.defines.push("EYE_DISTANCE_SCALING");
- }
- if (this._shaderTranslucencyByDistance) {
- vs.defines.push("EYE_DISTANCE_TRANSLUCENCY");
- }
- if (this._shaderPixelOffsetScaleByDistance) {
- vs.defines.push("EYE_DISTANCE_PIXEL_OFFSET");
- }
- if (this._shaderDistanceDisplayCondition) {
- vs.defines.push("DISTANCE_DISPLAY_CONDITION");
- }
- if (this._shaderDisableDepthDistance) {
- vs.defines.push("DISABLE_DEPTH_DISTANCE");
- }
- if (this._shaderClampToGround) {
- if (supportVSTextureReads) {
- vs.defines.push("VERTEX_DEPTH_CHECK");
- } else {
- vs.defines.push("FRAGMENT_DEPTH_CHECK");
- }
- }
- var sdfEdge = 1.0 - SDFSettings.CUTOFF;
- if (this._sdf) {
- vs.defines.push("SDF");
- }
- var vectorFragDefine = defined(this._batchTable) ? "VECTOR_TILE" : "";
- if (this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {
- fs = new ShaderSource({
- defines: ["OPAQUE", vectorFragDefine],
- sources: [fsSource],
- });
- if (this._shaderClampToGround) {
- if (supportVSTextureReads) {
- fs.defines.push("VERTEX_DEPTH_CHECK");
- } else {
- fs.defines.push("FRAGMENT_DEPTH_CHECK");
- }
- }
- if (this._sdf) {
- fs.defines.push("SDF");
- fs.defines.push("SDF_EDGE " + sdfEdge);
- }
- this._sp = ShaderProgram.replaceCache({
- context: context,
- shaderProgram: this._sp,
- vertexShaderSource: vs,
- fragmentShaderSource: fs,
- attributeLocations: attributeLocations,
- });
- fs = new ShaderSource({
- defines: ["TRANSLUCENT", vectorFragDefine],
- sources: [fsSource],
- });
- if (this._shaderClampToGround) {
- if (supportVSTextureReads) {
- fs.defines.push("VERTEX_DEPTH_CHECK");
- } else {
- fs.defines.push("FRAGMENT_DEPTH_CHECK");
- }
- }
- if (this._sdf) {
- fs.defines.push("SDF");
- fs.defines.push("SDF_EDGE " + sdfEdge);
- }
- this._spTranslucent = ShaderProgram.replaceCache({
- context: context,
- shaderProgram: this._spTranslucent,
- vertexShaderSource: vs,
- fragmentShaderSource: fs,
- attributeLocations: attributeLocations,
- });
- }
- if (this._blendOption === BlendOption.OPAQUE) {
- fs = new ShaderSource({
- defines: [vectorFragDefine],
- sources: [fsSource],
- });
- if (this._shaderClampToGround) {
- if (supportVSTextureReads) {
- fs.defines.push("VERTEX_DEPTH_CHECK");
- } else {
- fs.defines.push("FRAGMENT_DEPTH_CHECK");
- }
- }
- if (this._sdf) {
- fs.defines.push("SDF");
- fs.defines.push("SDF_EDGE " + sdfEdge);
- }
- this._sp = ShaderProgram.replaceCache({
- context: context,
- shaderProgram: this._sp,
- vertexShaderSource: vs,
- fragmentShaderSource: fs,
- attributeLocations: attributeLocations,
- });
- }
- if (this._blendOption === BlendOption.TRANSLUCENT) {
- fs = new ShaderSource({
- defines: [vectorFragDefine],
- sources: [fsSource],
- });
- if (this._shaderClampToGround) {
- if (supportVSTextureReads) {
- fs.defines.push("VERTEX_DEPTH_CHECK");
- } else {
- fs.defines.push("FRAGMENT_DEPTH_CHECK");
- }
- }
- if (this._sdf) {
- fs.defines.push("SDF");
- fs.defines.push("SDF_EDGE " + sdfEdge);
- }
- this._spTranslucent = ShaderProgram.replaceCache({
- context: context,
- shaderProgram: this._spTranslucent,
- vertexShaderSource: vs,
- fragmentShaderSource: fs,
- attributeLocations: attributeLocations,
- });
- }
- this._compiledShaderRotation = this._shaderRotation;
- this._compiledShaderAlignedAxis = this._shaderAlignedAxis;
- this._compiledShaderScaleByDistance = this._shaderScaleByDistance;
- this._compiledShaderTranslucencyByDistance = this._shaderTranslucencyByDistance;
- this._compiledShaderPixelOffsetScaleByDistance = this._shaderPixelOffsetScaleByDistance;
- this._compiledShaderDistanceDisplayCondition = this._shaderDistanceDisplayCondition;
- this._compiledShaderDisableDepthDistance = this._shaderDisableDepthDistance;
- this._compiledShaderClampToGround = this._shaderClampToGround;
- this._compiledSDF = this._sdf;
- }
- var commandList = frameState.commandList;
- if (pass.render || pass.pick) {
- var colorList = this._colorCommands;
- var opaque = this._blendOption === BlendOption.OPAQUE;
- var opaqueAndTranslucent =
- this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT;
- var va = this._vaf.va;
- var vaLength = va.length;
- var uniforms = this._uniforms;
- var pickId;
- if (defined(this._batchTable)) {
- uniforms = this._batchTable.getUniformMapCallback()(uniforms);
- pickId = this._batchTable.getPickId();
- } else {
- pickId = "v_pickColor";
- }
- colorList.length = vaLength;
- var totalLength = opaqueAndTranslucent ? vaLength * 2 : vaLength;
- for (var j = 0; j < totalLength; ++j) {
- var command = colorList[j];
- if (!defined(command)) {
- command = colorList[j] = new DrawCommand();
- }
- var opaqueCommand = opaque || (opaqueAndTranslucent && j % 2 === 0);
- command.pass =
- opaqueCommand || !opaqueAndTranslucent ? Pass.OPAQUE : Pass.TRANSLUCENT;
- command.owner = this;
- var index = opaqueAndTranslucent ? Math.floor(j / 2.0) : j;
- command.boundingVolume = boundingVolume;
- command.modelMatrix = modelMatrix;
- command.count = va[index].indicesCount;
- command.shaderProgram = opaqueCommand ? this._sp : this._spTranslucent;
- command.uniformMap = uniforms;
- command.vertexArray = va[index].va;
- command.renderState = opaqueCommand
- ? this._rsOpaque
- : this._rsTranslucent;
- command.debugShowBoundingVolume = this.debugShowBoundingVolume;
- command.pickId = pickId;
- if (this._instanced) {
- command.count = 6;
- command.instanceCount = billboardsLength;
- }
- commandList.push(command);
- }
- if (this.debugShowTextureAtlas) {
- if (!defined(this.debugCommand)) {
- this.debugCommand = createDebugCommand(this, frameState.context);
- }
- commandList.push(this.debugCommand);
- }
- }
- };
- BillboardCollection.prototype.isDestroyed = function () {
- return false;
- };
- BillboardCollection.prototype.destroy = function () {
- if (defined(this._removeCallbackFunc)) {
- this._removeCallbackFunc();
- this._removeCallbackFunc = undefined;
- }
- this._textureAtlas =
- this._destroyTextureAtlas &&
- this._textureAtlas &&
- this._textureAtlas.destroy();
- this._sp = this._sp && this._sp.destroy();
- this._spTranslucent = this._spTranslucent && this._spTranslucent.destroy();
- this._vaf = this._vaf && this._vaf.destroy();
- destroyBillboards(this._billboards);
- return destroyObject(this);
- };
- export default BillboardCollection;
|