createVectorTileGeometries.js 5.98 KB
Newer Older
Patrick's avatar
Patrick committed
1
/**
Patrick's avatar
Patrick committed
2
 * Cesium - https://github.com/CesiumGS/cesium
Patrick's avatar
Patrick committed
3
 *
Patrick's avatar
Patrick committed
4
 * Copyright 2011-2020 Cesium Contributors
Patrick's avatar
Patrick committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Columbus View (Pat. Pend.)
 *
 * Portions licensed separately.
Patrick's avatar
Patrick committed
21
 * See https://github.com/CesiumGS/cesium/blob/master/LICENSE.md for full licensing details.
Patrick's avatar
Patrick committed
22
 */
Patrick's avatar
Patrick committed
23
define(["./when-60b00257","./Check-4274a1fd","./Math-9d37f659","./Cartesian2-2951f601","./Transforms-53ff6d12","./RuntimeError-027c380a","./WebGLConstants-779bf0bc","./ComponentDatatype-a29c6075","./GeometryAttribute-2f728681","./GeometryAttributes-130e4d69","./IndexDatatype-527cbd94","./createTaskProcessorWorker","./GeometryOffsetAttribute-8756c94a","./VertexFormat-6af5bab1","./BoxGeometry-d455b6dd","./CylinderGeometryLibrary-4f028ebf","./CylinderGeometry-268e0ea7","./EllipsoidGeometry-a1c1e12f","./Color-9e90e2b0"],function(D,e,t,P,q,n,r,a,i,o,W,d,s,c,_,f,N,Y,S){"use strict";function T(e){this.offset=e.offset,this.count=e.count,this.color=e.color,this.batchIds=e.batchIds}var l=new P.Cartesian3,u=q.Matrix4.packedLength+P.Cartesian3.packedLength,h=q.Matrix4.packedLength+2,b=q.Matrix4.packedLength+P.Cartesian3.packedLength,p=P.Cartesian3.packedLength+1,y={modelMatrix:new q.Matrix4,boundingVolume:new q.BoundingSphere};function j(e,t){var n=t*u,r=P.Cartesian3.unpack(e,n,l);n+=P.Cartesian3.packedLength;var a=q.Matrix4.unpack(e,n,y.modelMatrix);q.Matrix4.multiplyByScale(a,r,a);var i=y.boundingVolume;return P.Cartesian3.clone(P.Cartesian3.ZERO,i.center),i.radius=Math.sqrt(3),y}function z(e,t){var n=t*h,r=e[n++],a=e[n++],i=P.Cartesian3.fromElements(r,r,a,l),o=q.Matrix4.unpack(e,n,y.modelMatrix);q.Matrix4.multiplyByScale(o,i,o);var d=y.boundingVolume;return P.Cartesian3.clone(P.Cartesian3.ZERO,d.center),d.radius=Math.sqrt(2),y}function H(e,t){var n=t*b,r=P.Cartesian3.unpack(e,n,l);n+=P.Cartesian3.packedLength;var a=q.Matrix4.unpack(e,n,y.modelMatrix);q.Matrix4.multiplyByScale(a,r,a);var i=y.boundingVolume;return P.Cartesian3.clone(P.Cartesian3.ZERO,i.center),i.radius=1,y}function J(e,t){var n=t*p,r=e[n++],a=P.Cartesian3.unpack(e,n,l),i=q.Matrix4.fromTranslation(a,y.modelMatrix);q.Matrix4.multiplyByUniformScale(i,r,i);var o=y.boundingVolume;return P.Cartesian3.clone(P.Cartesian3.ZERO,o.center),o.radius=1,y}var V=new P.Cartesian3;function K(e,t,n,r,a){if(D.defined(t)){for(var i=n.length,o=r.attributes.position.values,d=r.indices,s=e.positions,c=e.vertexBatchIds,f=e.indices,l=e.batchIds,u=e.batchTableColors,h=e.batchedIndices,b=e.indexOffsets,p=e.indexCounts,y=e.boundingVolumes,x=e.modelMatrix,g=e.center,v=e.positionOffset,C=e.batchIdIndex,m=e.indexOffset,I=e.batchedIndicesOffset,k=0;k<i;++k){var M=a(t,k),B=M.modelMatrix;q.Matrix4.multiply(x,B,B);for(var w=n[k],A=o.length,O=0;O<A;O+=3){var L=P.Cartesian3.unpack(o,O,V);q.Matrix4.multiplyByPoint(B,L,L),P.Cartesian3.subtract(L,g,L),P.Cartesian3.pack(L,s,3*v+O),c[C++]=w}for(var E=d.length,U=0;U<E;++U)f[m+U]=d[U]+v;var G=k+I;h[G]=new T({offset:m,count:E,color:S.Color.fromRgba(u[w]),batchIds:[w]}),l[G]=w,b[G]=m,p[G]=E,y[G]=q.BoundingSphere.transform(M.boundingVolume,B),v+=A/3,m+=E}e.positionOffset=v,e.batchIdIndex=C,e.indexOffset=m,e.batchedIndicesOffset+=i}}var Q=new P.Cartesian3,X=new q.Matrix4;function $(e,t,n){var r=n.length,a=2+r*q.BoundingSphere.packedLength+1+function(e){for(var t=e.length,n=0,r=0;r<t;++r)n+=S.Color.packedLength+3+e[r].batchIds.length;return n}(t),i=new Float64Array(a),o=0;i[o++]=e,i[o++]=r;for(var d=0;d<r;++d)q.BoundingSphere.pack(n[d],i,o),o+=q.BoundingSphere.packedLength;var s=t.length;i[o++]=s;for(var c=0;c<s;++c){var f=t[c];S.Color.pack(f.color,i,o),o+=S.Color.packedLength,i[o++]=f.offset,i[o++]=f.count;var l=f.batchIds,u=l.length;i[o++]=u;for(var h=0;h<u;++h)i[o++]=l[h]}return i}return d(function(e,t){var n=D.defined(e.boxes)?new Float32Array(e.boxes):void 0,r=D.defined(e.boxBatchIds)?new Uint16Array(e.boxBatchIds):void 0,a=D.defined(e.cylinders)?new Float32Array(e.cylinders):void 0,i=D.defined(e.cylinderBatchIds)?new Uint16Array(e.cylinderBatchIds):void 0,o=D.defined(e.ellipsoids)?new Float32Array(e.ellipsoids):void 0,d=D.defined(e.ellipsoidBatchIds)?new Uint16Array(e.ellipsoidBatchIds):void 0,s=D.defined(e.spheres)?new Float32Array(e.spheres):void 0,c=D.defined(e.sphereBatchIds)?new Uint16Array(e.sphereBatchIds):void 0,f=D.defined(n)?r.length:0,l=D.defined(a)?i.length:0,u=D.defined(o)?d.length:0,h=D.defined(s)?c.length:0,b=_.BoxGeometry.getUnitBox(),p=N.CylinderGeometry.getUnitCylinder(),y=Y.EllipsoidGeometry.getUnitEllipsoid(),x=b.attributes.position.values,g=p.attributes.position.values,v=y.attributes.position.values,C=x.length*f;C+=g.length*l,C+=v.length*(u+h);var m=b.indices,I=p.indices,k=y.indices,M=m.length*f;M+=I.length*l,M+=k.length*(u+h);var B,w,A,O=new Float32Array(C),L=new Uint16Array(C/3),E=W.IndexDatatype.createTypedArray(C/3,M),U=f+l+u+h,G=new Uint16Array(U),S=new Array(U),T=new Uint32Array(U),V=new Uint32Array(U),F=new Array(U);B=e.packedBuffer,w=new Float64Array(B),A=0,P.Cartesian3.unpack(w,A,Q),A+=P.Cartesian3.packedLength,q.Matrix4.unpack(w,A,X);var R={batchTableColors:new Uint32Array(e.batchTableColors),positions:O,vertexBatchIds:L,indices:E,batchIds:G,batchedIndices:S,indexOffsets:T,indexCounts:V,boundingVolumes:F,positionOffset:0,batchIdIndex:0,indexOffset:0,batchedIndicesOffset:0,modelMatrix:X,center:Q};K(R,n,r,b,j),K(R,a,i,p,z),K(R,o,d,y,H),K(R,s,c,y,J);var Z=$(E.BYTES_PER_ELEMENT,S,F);return t.push(O.buffer,L.buffer,E.buffer),t.push(G.buffer,T.buffer,V.buffer),t.push(Z.buffer),{positions:O.buffer,vertexBatchIds:L.buffer,indices:E.buffer,indexOffsets:T.buffer,indexCounts:V.buffer,batchIds:G.buffer,packedBuffer:Z.buffer}})});