S3MTilesParser.js 11 KB

1
  1. define(["./createTaskProcessorWorker","./ComponentDatatype-c140a87d","./Color-5008547b","./S3MCompressType-25e9ba65","./Cartographic-3309dd0d","./Matrix4-cde86d0e","./pako_inflate-f73548c4","./when-b60132fc","./Check-7b2a090c","./WebGLConstants-4ae0db90","./FeatureDetection-c3b71206","./Math-119be1a3","./RuntimeError-4a5c8994","./Cartesian4-3ca25aab"],(function(t,e,r,n,a,i,o,E,s,y,p,T,u,A){"use strict";function l(t,e,r,n,a,i){this.left=t,this.bottom=e,this.right=r,this.top=n,this.minHeight=a,this.maxHeight=i,this.width=r-t,this.length=n-e,this.height=i-a}function _(t,r,n,o,E,s,y){var p=E.getUint32(s,!0);s+=Uint32Array.BYTES_PER_ELEMENT;var T=0,u={},A=u.vertexAttributes=[],l=u.attrLocation={};u.instanceCount=0,u.instanceMode=0;var _=0;E.getUint32(s,!0),s+=Uint32Array.BYTES_PER_ELEMENT;var v=E.getUint16(s,!0);s+=Uint32Array.BYTES_PER_ELEMENT;var c=v;v>4&&(c=v>>8,v&=15);var m=E.getUint32(s,!0);s+=Uint32Array.BYTES_PER_ELEMENT;var d=void 0,f=void 0;if(m>0){var B=E.getUint16(s,!0);B=v*Float32Array.BYTES_PER_ELEMENT,s+=Uint32Array.BYTES_PER_ELEMENT,T=m*B;var g=o.subarray(s,s+T);if(n){var U=new a.Cartesian3,P=new a.Cartesian3,L=new Float32Array(g.buffer,g.byteOffset,g.byteLength/4),h=new a.Cartographic;d=new a.Cartographic,f=new a.Cartographic;for(var M=new Float32Array(2*m),N=new Float64Array(2*m),S=0;S<m;S++)i.Matrix4.multiplyByPoint(r,a.Cartesian3.fromElements(L[3*S],L[3*S+1],L[3*S+2],U),P),h=a.Cartographic.fromCartesian(P),N[2*S]=h.longitude,N[2*S+1]=h.latitude,0===S?(d.longitude=h.longitude,d.latitude=h.latitude,f.longitude=h.longitude,f.latitude=h.latitude):(d.longitude=Math.max(h.longitude,d.longitude),d.latitude=Math.max(h.latitude,d.latitude),f.longitude=Math.min(h.longitude,f.longitude),f.latitude=Math.min(h.latitude,f.latitude));for(S=0;S<m;S++)M[2*S]=N[2*S]-f.longitude,M[2*S+1]=N[2*S+1]-f.latitude;l.img=_,A.push({index:l.img,typedArray:M,componentsPerAttribute:2,componentDatatype:e.ComponentDatatype.FLOAT,offsetInBytes:0,strideInBytes:2*Float32Array.BYTES_PER_ELEMENT,normalize:!1}),_++}l.aPosition=_,A.push({index:l.aPosition,typedArray:g,componentsPerAttribute:v,componentDatatype:e.ComponentDatatype.FLOAT,offsetInBytes:0,strideInBytes:B,normalize:!1}),_++,s+=T}var R=E.getUint32(s,!0);if(s+=Uint32Array.BYTES_PER_ELEMENT,R>0){var Y=E.getUint16(s,!0);Y=c*Float32Array.BYTES_PER_ELEMENT,s+=Uint32Array.BYTES_PER_ELEMENT,T=R*Y,t.ignoreNormal||(l.aNormal=_,A.push({index:l.aNormal,typedArray:o.subarray(s,s+T),componentsPerAttribute:c,componentDatatype:e.ComponentDatatype.FLOAT,offsetInBytes:0,strideInBytes:Y,normalize:!1}),_++),s+=T}var D=E.getUint32(s,!0);if(s+=Uint32Array.BYTES_PER_ELEMENT,D>0){var C=new Uint8Array(4*D);y.push(C.buffer);var b=E.getUint32(s,!0);b=4*Float32Array.BYTES_PER_ELEMENT,s+=Uint32Array.BYTES_PER_ELEMENT,T=D*b;for(var x=new Float32Array(o.buffer,s,4*m),F=0;F<m;F++)C[4*F]=255*x[4*F],C[4*F+1]=255*x[4*F+1],C[4*F+2]=255*x[4*F+2],C[4*F+3]=255*x[4*F+3];s+=T,l.aColor=_,A.push({index:l.aColor,typedArray:C,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.UNSIGNED_BYTE,offsetInBytes:0,strideInBytes:4,normalize:!0}),_++}var I=E.getUint32(s,!0);s+=Uint32Array.BYTES_PER_ELEMENT,I>0&&(s+=T=16*I);var w=E.getUint32(s,!0);s+=Uint32Array.BYTES_PER_ELEMENT;for(var O,k,z=-1,H=0;H<w;H++){O=E.getUint32(s,!0),s+=Uint32Array.BYTES_PER_ELEMENT,k=E.getUint16(s,!0),s+=Uint16Array.BYTES_PER_ELEMENT,E.getUint16(s,!0),s+=Uint16Array.BYTES_PER_ELEMENT,T=O*k*Float32Array.BYTES_PER_ELEMENT;var G,W=o.subarray(s,s+T);if(-1!=z||20!=k&&35!=k)if(-1!==z)u.instanceBounds=new Float32Array(o.buffer,s,O*k);else{var V="aTexCoord"+H;l[V]=_++,A.push({index:l[V],typedArray:W,componentsPerAttribute:k,componentDatatype:e.ComponentDatatype.FLOAT,offsetInBytes:0,strideInBytes:k*Float32Array.BYTES_PER_ELEMENT,normalize:!1})}else z=H,u.instanceCount=O,u.instanceMode=k,u.instanceBuffer=W,20===k?(G=20*Float32Array.BYTES_PER_ELEMENT,l.uv2=_++,A.push({index:l.uv2,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:0,strideInBytes:G,instanceDivisor:1}),l.uv3=_++,A.push({index:l.uv3,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:4*Float32Array.BYTES_PER_ELEMENT,strideInBytes:G,instanceDivisor:1}),l.uv4=_++,A.push({index:l.uv4,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:8*Float32Array.BYTES_PER_ELEMENT,strideInBytes:G,instanceDivisor:1}),l.secondary_colour=_++,A.push({index:l.secondary_colour,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:12*Float32Array.BYTES_PER_ELEMENT,strideInBytes:G,instanceDivisor:1}),l.uv6=_++,A.push({index:l.uv6,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:16*Float32Array.BYTES_PER_ELEMENT,strideInBytes:G,instanceDivisor:1})):35===k&&(G=35*Float32Array.BYTES_PER_ELEMENT,l.uv1=_++,A.push({index:l.uv1,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:0,strideInBytes:G,instanceDivisor:1,byteLength:T}),l.uv2=_++,A.push({index:l.uv2,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:4*Float32Array.BYTES_PER_ELEMENT,strideInBytes:G,instanceDivisor:1}),l.uv3=_++,A.push({index:l.uv3,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:8*Float32Array.BYTES_PER_ELEMENT,strideInBytes:G,instanceDivisor:1}),l.uv4=_++,A.push({index:l.uv4,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:12*Float32Array.BYTES_PER_ELEMENT,strideInBytes:G,instanceDivisor:1}),l.uv5=_++,A.push({index:l.uv5,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:16*Float32Array.BYTES_PER_ELEMENT,strideInBytes:G,instanceDivisor:1}),l.uv6=_++,A.push({index:l.uv6,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:20*Float32Array.BYTES_PER_ELEMENT,strideInBytes:G,instanceDivisor:1}),l.uv7=_++,A.push({index:l.uv7,componentsPerAttribute:3,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:24*Float32Array.BYTES_PER_ELEMENT,strideInBytes:G,instanceDivisor:1}),l.secondary_colour=_++,A.push({index:l.secondary_colour,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:27*Float32Array.BYTES_PER_ELEMENT,strideInBytes:G,instanceDivisor:1}),l.uv9=_++,A.push({index:l.uv9,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,normalize:!1,offsetInBytes:31*Float32Array.BYTES_PER_ELEMENT,strideInBytes:G,instanceDivisor:1}));s+=T}u.verticesCount=m,u.instanceIndex=z;var X=E.getUint32(s,!0);s+=Uint32Array.BYTES_PER_ELEMENT;var j=[];for(H=0;H<X;H++){var q={},J=E.getUint32(s,!0);s+=Uint32Array.BYTES_PER_ELEMENT;var K=E.getUint8(s,!0);s+=Uint8Array.BYTES_PER_ELEMENT,E.getUint8(s,!0),s+=Uint8Array.BYTES_PER_ELEMENT;var Q=E.getUint8(s,!0);s+=Uint8Array.BYTES_PER_ELEMENT,s+=1,q.indicesCount=J,q.indexType=K,q.primitiveType=Q;var Z=s;J>0&&(0==K?(s+=T=J*Uint16Array.BYTES_PER_ELEMENT,J%2==1&&(s+=2)):s+=T=4*J),q.indicesTypedArray=o.subarray(Z,Z+T);var $=E.getUint32(s,!0);s+=Uint32Array.BYTES_PER_ELEMENT;var tt=E.getUint32(s,!0);s+=Uint32Array.BYTES_PER_ELEMENT*$,q.materialCode=tt,j.push(q)}return t[p]={vertexPackage:u,arrIndexPackage:j,cartographicBounds:{max:d,min:f}},s}function v(t,r,n){var a=t.vertexAttributes,i=t.attrLocation,o=a.length;i[1===n?"instanceId":"batchId"]=o,a.push({index:o,typedArray:r,componentsPerAttribute:1,componentDatatype:e.ComponentDatatype.FLOAT,offsetInBytes:0,strideInBytes:0,instanceDivisor:n})}return new r.Color,t((function(t,e){var r=t.buffer,a=t.supportCompressType,i=t.bVolume,E=null,s=null,y=null,p=t.isCoverImageryLayer,T=t.modelMatrix;if(i&&t.volbuffer.byteLength<8&&(i=!1),i){var u=t.volbuffer,A=new Uint8Array(u,8),c=o.pako.inflate(A).buffer,m=new Float64Array(c,0,1),d=new Uint32Array(c,48,1);if(0===m[0]||3200===d[0]||3201===d[0]){var f=0;0===m[0]&&(f=8),e.push(c);var B=new Float64Array(c,f,6),g=B[0],U=B[1],P=B[2],L=B[3],h=B[4]<B[5]?B[4]:B[5],M=B[4]>B[5]?B[4]:B[5];s={left:g,top:U,right:P,bottom:L,minHeight:h,maxHeight:M,width:(E=new l(g,L,P,U,h,M)).width,length:E.length,height:E.height};var N=new Uint32Array(c,48+f,7),S=N[0],R=N[1],Y=N[2],D=N[3];y={nFormat:S,nSideBlockCount:R,nBlockLength:Y,nLength:D,nWidth:N[4],nHeight:N[5],nDepth:N[6],imageArray:new Uint8Array(c,76+f,D*D*4)}}}var C=0,b=new Uint8Array(r,0,4);if(115!==b[0]||51!==b[1]||109!==b[2])return{result:!1};var x=b[3],F=(A=new Uint8Array(r,4),o.pako.inflate(A).buffer),I=new Uint8Array(F);e.push(I.buffer);var w=new DataView(F),O=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;var k=new Uint8Array(F,C,O),z=O%4;z&&(z=4-z),C+=O+z;var H=n.getStringFromTypedArray(k,void 0,void 0,"gbk");H=(H=H.replace(new RegExp("\r\n","gm"),"")).replace(new RegExp(":","gm"),""),w.getUint32(C,!0),C+=Uint32Array.BYTES_PER_ELEMENT;var G=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;var W={};W.ignoreNormal=t.ignoreNormal;for(var V=0;V<G;V++)C=_(W,T,p,I,w,C,e);w.getUint32(C,!0),C+=Uint32Array.BYTES_PER_ELEMENT;var X=w.getUint32(C,!0);for(C+=Uint32Array.BYTES_PER_ELEMENT,V=0;V<X;V++){var j=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;var q=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;var J={};if(-1==W[j].vertexPackage.instanceIndex){for(var K=new Float32Array(W[j].vertexPackage.verticesCount),Q=0;Q<q;Q++){var Z=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;var $=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;var tt=0,et=0;J[Z]={batchId:Q};for(var rt=0;rt<$;rt++)if(et=w.getUint32(C,!0),C+=Uint32Array.BYTES_PER_ELEMENT,tt=w.getUint32(C,!0),C+=Uint32Array.BYTES_PER_ELEMENT,K.fill)K.fill(Q,et,et+tt);else for(var nt=et+et,at=et;at<nt;at++)K[at]=Q;J[Z].vertexColorOffset=et,J[Z].vertexColorCount=tt}v(W[j].vertexPackage,K,void 0)}else{var it=W[j].vertexPackage.instanceCount;W[j].vertexPackage.instanceBuffer,W[j].vertexPackage.instanceMode;var ot=new Float32Array(it),Et=0;for(Q=0;Q<q;Q++){Z=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;$=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;for(rt=0;rt<$;rt++){var st=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT,ot[Et]=Et,void 0===J[Z]&&(J[Z]={vertexColorCount:1,instanceIds:[],vertexColorOffset:Et}),J[Z].instanceIds.push(st),Et++}}v(W[j].vertexPackage,ot,1)}W[j].pickInfo=J}w.getUint32(C,!0),C+=Uint32Array.BYTES_PER_ELEMENT;var yt=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;var pt={};for(V=0;V<yt;V++){var Tt=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;var ut=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;var At=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;var lt=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;$=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;var _t=w.getUint32(C,!0);C+=Uint32Array.BYTES_PER_ELEMENT;var vt=null;if(lt===n.S3MCompressType.enrS3TCDXTN&&1!==a){var ct=null;_t>n.S3MPixelFormat.BGR||_t===n.S3MPixelFormat.LUMINANCE_ALPHA?(ct=new Uint8Array(F,C,ut*At),vt=new Uint8Array(ut*At*4)):(ct=new Uint16Array(F,C,$/2),vt=new Uint16Array(ut*At)),n.DXTTextureDecode.decode(vt,ut,At,ct,_t),e.push(vt.buffer),lt=0}else vt=new Uint8Array(F,C,$);pt[Tt]={id:Tt,width:ut,height:At,compressType:lt,nFormat:_t,imageBuffer:vt},C+=$}return{result:!0,version:x,xmlDoc:H,geoPackage:W,texturePackage:pt,volImageBuffer:y,volBounds:s}}))}));