@loaders.gl/terrain 3.1.0-alpha.3 → 4.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/decode-quantized-mesh.js.map +1 -1
- package/dist/lib/delatin/index.js.map +1 -1
- package/dist/lib/helpers/skirt.js +1 -1
- package/dist/lib/helpers/skirt.js.map +1 -1
- package/dist/lib/parse-quantized-mesh.js.map +1 -1
- package/dist/lib/parse-terrain.js.map +1 -1
- package/dist/lib/utils/version.js +1 -1
- package/dist/quantized-mesh-worker.js +1218 -2
- package/dist/terrain-worker.js +1218 -2
- package/dist/workers/quantized-mesh-worker.js +3 -3
- package/dist/workers/quantized-mesh-worker.js.map +1 -0
- package/dist/workers/terrain-worker.js +3 -3
- package/dist/workers/terrain-worker.js.map +1 -0
- package/package.json +7 -7
- package/src/lib/decode-quantized-mesh.ts +325 -0
- package/src/lib/delatin/index.js +2 -0
- package/src/lib/helpers/skirt.ts +168 -0
- package/src/lib/parse-quantized-mesh.ts +98 -0
- package/src/lib/parse-terrain.ts +212 -0
- package/src/workers/quantized-mesh-worker.ts +4 -0
- package/src/workers/terrain-worker.ts +4 -0
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/quantized-mesh-worker.js.map +0 -1
- package/dist/terrain-worker.js.map +0 -1
package/dist/terrain-worker.js
CHANGED
|
@@ -1,2 +1,1218 @@
|
|
|
1
|
-
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=20)}([function(e,t,r){e.exports=r(13)},function(e,t){function r(e,t,r,n,i,o,a){try{var s=e[o](a),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,i)}e.exports=function(e){return function(){var t=this,n=arguments;return new Promise((function(i,o){var a=e.apply(t,n);function s(e){r(a,i,o,s,u,"next",e)}function u(e){r(a,i,o,s,u,"throw",e)}s(void 0)}))}},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){function r(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(e.exports=r=function(e){return typeof e},e.exports.default=e.exports,e.exports.__esModule=!0):(e.exports=r=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.default=e.exports,e.exports.__esModule=!0),r(t)}e.exports=r,e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t,r){var n=r(14),i=r(15),o=r(9),a=r(16);e.exports=function(e,t){return n(e)||i(e,t)||o(e,t)||a()},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t,r){var n=r(17),i=r(18),o=r(9),a=r(19);e.exports=function(e){return n(e)||i(e)||o(e)||a()},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}e.exports=function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){},function(e,t,r){var n=r(10);e.exports=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n},e.exports.default=e.exports,e.exports.__esModule=!0},,,function(e,t,r){var n=function(e){"use strict";var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var i=t&&t.prototype instanceof h?t:h,o=Object.create(i.prototype),a=new w(n||[]);return o._invoke=function(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return S()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var s=E(a,r);if(s){if(s===l)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(e,r,a),o}function c(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var l={};function h(){}function f(){}function d(){}var p={};p[i]=function(){return this};var v=Object.getPrototypeOf,g=v&&v(v(T([])));g&&g!==t&&r.call(g,i)&&(p=g);var y=d.prototype=h.prototype=Object.create(p);function _(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function m(e,t){var n;this._invoke=function(i,o){function a(){return new t((function(n,a){!function n(i,o,a,s){var u=c(e[i],e,o);if("throw"!==u.type){var l=u.arg,h=l.value;return h&&"object"==typeof h&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(h).then((function(e){l.value=e,a(l)}),(function(e){return n("throw",e,a,s)}))}s(u.arg)}(i,o,n,a)}))}return n=n?n.then(a,a):a()}}function E(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,E(e,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=c(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,l;var i=n.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function b(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function x(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function w(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function T(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:S}}function S(){return{value:void 0,done:!0}}return f.prototype=y.constructor=d,d.constructor=f,f.displayName=s(d,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===f||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,s(e,a,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},_(m.prototype),m.prototype[o]=function(){return this},e.AsyncIterator=m,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var a=new m(u(t,r,n,i),o);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},_(y),s(y,a,"Generator"),y[i]=function(){return this},y.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=T,w.prototype={constructor:w,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var s=r.call(o,"catchLoc"),u=r.call(o,"finallyLoc");if(s&&u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,l):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),l},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),x(r),l}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;x(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:T(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},e}(e.exports);try{regeneratorRuntime=n}catch(e){Function("r","regeneratorRuntime = r")(n)}},function(e,t){e.exports=function(e){if(Array.isArray(e))return e},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(e,t){var r=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t,r){var n=r(10);e.exports=function(e){if(Array.isArray(e))return n(e)},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t,r){"use strict";r.r(t);var n=r(5),i=r.n(n),o=r(1),a=r.n(o),s=r(0),u=r.n(s),c=r(6),l=r.n(c),h=r(7),f=r.n(h),d=r(2),p=r.n(d);function v(e){return!!e&&(e instanceof ArrayBuffer||("undefined"!=typeof MessagePort&&e instanceof MessagePort||("undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas)))}var g=new Map,y=function(){function e(){l()(this,e)}return f()(e,null,[{key:"onmessage",set:function(e){self.onmessage=function(t){if(_(t)){var r=t.data,n=r.type,i=r.payload;e(n,i)}}}},{key:"addEventListener",value:function(e){var t=g.get(e);t||(t=function(t){if(_(t)){var r=t.data,n=r.type,i=r.payload;e(n,i)}}),self.addEventListener("message",t)}},{key:"removeEventListener",value:function(e){var t=g.get(e);g.delete(e),self.removeEventListener("message",t)}},{key:"postMessage",value:function(e,t){if(self){var r={source:"loaders.gl",type:e,payload:t},n=function e(t){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=arguments.length>2?arguments[2]:void 0,i=n||new Set;if(t){if(v(t))i.add(t);else if(v(t.buffer))i.add(t.buffer);else if(ArrayBuffer.isView(t));else if(r&&"object"===p()(t))for(var o in t)e(t[o],r,i)}else;return void 0===n?Array.from(i):[]}(t);self.postMessage(r,n)}}}]),e}();function _(e){var t=e.type,r=e.data;return"message"===t&&r&&"string"==typeof r.source&&r.source.startsWith("loaders.gl")}function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function E(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?m(Object(r),!0).forEach((function(t){i()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var b=0;function x(e,t){return new Promise((function(r,n){var i=b++;y.addEventListener((function e(t,o){if(o.id===i)switch(t){case"done":y.removeEventListener(e),r(o.result);break;case"error":y.removeEventListener(e),n(o.error)}}));var o={id:i,input:e,options:t};y.postMessage("process",o)}))}function w(e){return T.apply(this,arguments)}function T(){return(T=a()(u.a.mark((function e(t){var r,n,i,o,a,s,c;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.loader,n=t.arrayBuffer,i=t.options,o=t.context,!r.parseSync&&!r.parse){e.next=6;break}a=n,s=r.parseSync||r.parse,e.next=13;break;case 6:if(!r.parseTextSync){e.next=12;break}c=new TextDecoder,a=c.decode(n),s=r.parseTextSync,e.next=13;break;case 12:throw new Error("Could not load data with ".concat(r.name," loader"));case 13:return i=E(E({},i),{},{modules:r&&r.options&&r.options.modules||{},worker:!1}),e.next=16,s(a,E({},i),o,r);case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var S=r(3),O=r.n(S);function P(e){for(var t=1/0,r=1/0,n=1/0,i=-1/0,o=-1/0,a=-1/0,s=e.POSITION?e.POSITION.value:[],u=s&&s.length,c=0;c<u;c+=3){var l=s[c],h=s[c+1],f=s[c+2];t=l<t?l:t,r=h<r?h:r,n=f<n?f:n,i=l>i?l:i,o=h>o?h:o,a=f>a?f:a}return[[t,r,n],[i,o,a]]}function M(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return I(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return I(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function I(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var L=new Map([["centerX",Float64Array.BYTES_PER_ELEMENT],["centerY",Float64Array.BYTES_PER_ELEMENT],["centerZ",Float64Array.BYTES_PER_ELEMENT],["minHeight",Float32Array.BYTES_PER_ELEMENT],["maxHeight",Float32Array.BYTES_PER_ELEMENT],["boundingSphereCenterX",Float64Array.BYTES_PER_ELEMENT],["boundingSphereCenterY",Float64Array.BYTES_PER_ELEMENT],["boundingSphereCenterZ",Float64Array.BYTES_PER_ELEMENT],["boundingSphereRadius",Float64Array.BYTES_PER_ELEMENT],["horizonOcclusionPointX",Float64Array.BYTES_PER_ELEMENT],["horizonOcclusionPointY",Float64Array.BYTES_PER_ELEMENT],["horizonOcclusionPointZ",Float64Array.BYTES_PER_ELEMENT]]);function k(e){return e>>1^-(1&e)}function A(e,t,r,n){var i,o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4];if(i=2===n?new Uint16Array(e,t,r):new Uint32Array(e,t,r),!o)return i;for(var a=0,s=0;s<i.length;++s){var u=i[s];i[s]=a-u,0===u&&++a}return i}function j(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}var q=1,N=2,D=3,R=4,U={maxDecodingStep:R};function B(e,t){var r=Object.assign({},U,t),n=new DataView(e),i=function(e){var t,r=0,n={},i=M(L);try{for(i.s();!(t=i.n()).done;){var o=O()(t.value,2),a=o[0],s=o[1],u=8===s?e.getFloat64:e.getFloat32;n[a]=u.call(e,r,!0),r+=s}}catch(e){i.e(e)}finally{i.f()}return{header:n,headerEndPosition:r}}(n),o=i.header,a=i.headerEndPosition;if(r.maxDecodingStep<q)return{header:o};var s=function(e,t){var r=t,n=e.getUint32(r,!0),i=new Uint16Array(3*n);r+=Uint32Array.BYTES_PER_ELEMENT;for(var o=Uint16Array.BYTES_PER_ELEMENT,a=n*o,s=r,u=s+a,c=u+a,l=0,h=0,f=0,d=0;d<n;d++)l+=k(e.getUint16(s+o*d,!0)),h+=k(e.getUint16(u+o*d,!0)),f+=k(e.getUint16(c+o*d,!0)),i[d]=l,i[d+n]=h,i[d+2*n]=f;return{vertexData:i,vertexDataEndPosition:r+=3*a}}(n,a),u=s.vertexData,c=s.vertexDataEndPosition;if(r.maxDecodingStep<N)return{header:o,vertexData:u};var l=function(e,t,r){var n=r,i=t.length/3>65536?Uint32Array.BYTES_PER_ELEMENT:Uint16Array.BYTES_PER_ELEMENT;n%i!=0&&(n+=i-n%i);var o=e.getUint32(n,!0);n+=Uint32Array.BYTES_PER_ELEMENT;var a=3*o,s=A(e.buffer,n,a,i);return{triangleIndicesEndPosition:n+=a*i,triangleIndices:s}}(n,u,c),h=l.triangleIndices,f=l.triangleIndicesEndPosition;if(r.maxDecodingStep<D)return{header:o,vertexData:u,triangleIndices:h};var d=function(e,t,r){var n=r,i=t.length/3>65536?Uint32Array.BYTES_PER_ELEMENT:Uint16Array.BYTES_PER_ELEMENT,o=e.getUint32(n,!0);n+=Uint32Array.BYTES_PER_ELEMENT;var a=A(e.buffer,n,o,i,!1);n+=o*i;var s=e.getUint32(n,!0);n+=Uint32Array.BYTES_PER_ELEMENT;var u=A(e.buffer,n,s,i,!1);n+=s*i;var c=e.getUint32(n,!0);n+=Uint32Array.BYTES_PER_ELEMENT;var l=A(e.buffer,n,c,i,!1);n+=c*i;var h=e.getUint32(n,!0);n+=Uint32Array.BYTES_PER_ELEMENT;var f=A(e.buffer,n,h,i,!1);return{edgeIndicesEndPosition:n+=h*i,westIndices:a,southIndices:u,eastIndices:l,northIndices:f}}(n,u,f),p=d.westIndices,v=d.southIndices,g=d.eastIndices,y=d.northIndices,_=d.edgeIndicesEndPosition;return r.maxDecodingStep<R?{header:o,vertexData:u,triangleIndices:h,westIndices:p,northIndices:y,eastIndices:g,southIndices:v}:{header:o,vertexData:u,triangleIndices:h,westIndices:p,northIndices:y,eastIndices:g,southIndices:v,extensions:function(e,t){var r={};if(e.byteLength<=t)return{extensions:r,extensionsEndPosition:t};for(var n,i=t;i<e.byteLength;){var o=e.getUint8(i,!0);i+=Uint8Array.BYTES_PER_ELEMENT;var a=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;var s=new DataView(e.buffer,i,a);switch(o){case 1:r.vertexNormals=(n=s,new Uint8Array(n.buffer,n.byteOffset,n.byteLength));break;case 2:r.waterMask=j(s)}i+=a}return{extensions:r,extensionsEndPosition:i}}(n,_).extensions}}var z=r(4),Y=r.n(z);r(8);function F(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=t,i=n&&n.length>1&&n[0].constructor||null;if(!i)throw new Error('"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types');for(var o=n.reduce((function(e,t){return e+t.length}),0),a=new i(o),s=0,u=0,c=n;u<c.length;u++){var l=c[u];a.set(l,s),s+=l.length}return a}function C(e,t,r){for(var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=n?X(n,e.POSITION.value):H(t),o=new e.POSITION.value.constructor(6*i.length),a=new e.TEXCOORD_0.value.constructor(4*i.length),s=new t.constructor(6*i.length),u=0;u<i.length;u++){var c=i[u];G({edge:c,edgeIndex:u,attributes:e,skirtHeight:r,newPosition:o,newTexcoord0:a,newTriangles:s})}e.POSITION.value=F(e.POSITION.value,o),e.TEXCOORD_0.value=F(e.TEXCOORD_0.value,a);var l=t instanceof Array?t.concat(s):F(t,s);return{attributes:e,triangles:l}}function H(e){for(var t=[],r=0;r<e.length;r+=3)t.push([e[r],e[r+1]]),t.push([e[r+1],e[r+2]]),t.push([e[r+2],e[r]]);t.sort((function(e,t){return Math.min.apply(Math,Y()(e))-Math.min.apply(Math,Y()(t))||Math.max.apply(Math,Y()(e))-Math.max.apply(Math,Y()(t))}));for(var n=[],i=1;i<t.length;)t[i][0]===t[i-1][1]&&t[i][1]===t[i-1][0]?i+=2:(n.push(t[i-1]),i++);return n}function X(e,t){e.westIndices.sort((function(e,r){return t[3*e+1]-t[3*r+1]})),e.eastIndices.sort((function(e,r){return t[3*r+1]-t[3*e+1]})),e.southIndices.sort((function(e,r){return t[3*r]-t[3*e]})),e.northIndices.sort((function(e,r){return t[3*e]-t[3*r]}));var r=[];for(var n in e)for(var i=e[n],o=0;o<i.length-1;o++)r.push([i[o],i[o+1]]);return r}function G(e){var t=e.edge,r=e.edgeIndex,n=e.attributes,i=e.skirtHeight,o=e.newPosition,a=e.newTexcoord0,s=e.newTriangles,u=n.POSITION.value.length,c=2*r,l=2*r+1;o.set(n.POSITION.value.subarray(3*t[0],3*t[0]+3),3*c),o[3*c+2]=o[3*c+2]-i,o.set(n.POSITION.value.subarray(3*t[1],3*t[1]+3),3*l),o[3*l+2]=o[3*l+2]-i,a.set(n.TEXCOORD_0.value.subarray(2*t[0],2*t[0]+2),2*c),a.set(n.TEXCOORD_0.value.subarray(2*t[1],2*t[1]+2),2*l);var h=2*r*3;s[h]=t[0],s[h+1]=t[1],s[h+2]=u/3+l,s[h+3]=u/3+l,s[h+4]=u/3+c,s[h+5]=t[0]}function $(e,t){if(!e)return null;var r=t.bounds,n=B(e,N),i=n.header,o=n.vertexData,a=n.triangleIndices,s=n.westIndices,u=n.northIndices,c=n.eastIndices,l=n.southIndices,h=a,f=function(e,t,r){for(var n=t.minHeight,i=t.maxHeight,o=r||[0,0,1,1],a=O()(o,4),s=a[0],u=a[1],c=a[2]-s,l=a[3]-u,h=i-n,f=e.length/3,d=new Float32Array(3*f),p=new Float32Array(2*f),v=0;v<f;v++){var g=e[v]/32767,y=e[v+f]/32767,_=e[v+2*f]/32767;d[3*v+0]=g*c+s,d[3*v+1]=y*l+u,d[3*v+2]=_*h+n,p[2*v+0]=g,p[2*v+1]=y}return{POSITION:{value:d,size:3},TEXCOORD_0:{value:p,size:2}}}(o,i,r),d=P(f);if(t.skirtHeight){var p=C(f,h,t.skirtHeight,{westIndices:s,northIndices:u,eastIndices:c,southIndices:l});f=p.attributes,h=p.triangles}return{loaderData:{header:{}},header:{vertexCount:h.length,boundingBox:d},mode:4,indices:{value:h,size:1},attributes:f}}function V(e,t){return $(e,t["quantized-mesh"])}class Z{constructor(e=257){this.gridSize=e;const t=e-1;if(t&t-1)throw new Error(`Expected grid size to be 2^n+1, got ${e}.`);this.numTriangles=t*t*2-2,this.numParentTriangles=this.numTriangles-t*t,this.indices=new Uint32Array(this.gridSize*this.gridSize),this.coords=new Uint16Array(4*this.numTriangles);for(let e=0;e<this.numTriangles;e++){let r=e+2,n=0,i=0,o=0,a=0,s=0,u=0;for(1&r?o=a=s=t:n=i=u=t;(r>>=1)>1;){const e=n+o>>1,t=i+a>>1;1&r?(o=n,a=i,n=s,i=u):(n=o,i=a,o=s,a=u),s=e,u=t}const c=4*e;this.coords[c+0]=n,this.coords[c+1]=i,this.coords[c+2]=o,this.coords[c+3]=a}}createTile(e){return new Q(e,this)}}class Q{constructor(e,t){const r=t.gridSize;if(e.length!==r*r)throw new Error(`Expected terrain data of length ${r*r} (${r} x ${r}), got ${e.length}.`);this.terrain=e,this.martini=t,this.errors=new Float32Array(e.length),this.update()}update(){const{numTriangles:e,numParentTriangles:t,coords:r,gridSize:n}=this.martini,{terrain:i,errors:o}=this;for(let a=e-1;a>=0;a--){const e=4*a,s=r[e+0],u=r[e+1],c=r[e+2],l=r[e+3],h=s+c>>1,f=u+l>>1,d=h+f-u,p=f+s-h,v=(i[u*n+s]+i[l*n+c])/2,g=f*n+h,y=Math.abs(v-i[g]);if(o[g]=Math.max(o[g],y),a<t){const e=(u+p>>1)*n+(s+d>>1),t=(l+p>>1)*n+(c+d>>1);o[g]=Math.max(o[g],o[e],o[t])}}}getMesh(e=0){const{gridSize:t,indices:r}=this.martini,{errors:n}=this;let i=0,o=0;const a=t-1;function s(a,u,c,l,h,f){const d=a+c>>1,p=u+l>>1;Math.abs(a-h)+Math.abs(u-f)>1&&n[p*t+d]>e?(s(h,f,a,u,d,p),s(c,l,h,f,d,p)):(r[u*t+a]=r[u*t+a]||++i,r[l*t+c]=r[l*t+c]||++i,r[f*t+h]=r[f*t+h]||++i,o++)}r.fill(0),s(0,0,a,a,a,0),s(a,a,0,0,0,a);const u=new Uint16Array(2*i),c=new Uint32Array(3*o);let l=0;function h(i,o,a,s,f,d){const p=i+a>>1,v=o+s>>1;if(Math.abs(i-f)+Math.abs(o-d)>1&&n[v*t+p]>e)h(f,d,i,o,p,v),h(a,s,f,d,p,v);else{const e=r[o*t+i]-1,n=r[s*t+a]-1,h=r[d*t+f]-1;u[2*e]=i,u[2*e+1]=o,u[2*n]=a,u[2*n+1]=s,u[2*h]=f,u[2*h+1]=d,c[l++]=e,c[l++]=n,c[l++]=h}}return h(0,0,a,a,a,0),h(a,a,0,0,0,a),{vertices:u,triangles:c}}}var W=function(){function e(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r;l()(this,e),this.data=t,this.width=r,this.height=n,this.coords=[],this.triangles=[],this._halfedges=[],this._candidates=[],this._queueIndices=[],this._queue=[],this._errors=[],this._rms=[],this._pending=[],this._pendingLen=0,this._rmsSum=0;var i=r-1,o=n-1,a=this._addPoint(0,0),s=this._addPoint(i,0),u=this._addPoint(0,o),c=this._addPoint(i,o),h=this._addTriangle(c,a,u,-1,-1,-1);this._addTriangle(a,c,s,h,-1,-1),this._flush()}return f()(e,[{key:"run",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;this.getMaxError()>e;)this.refine()}},{key:"refine",value:function(){this._step(),this._flush()}},{key:"getMaxError",value:function(){return this._errors[0]}},{key:"getRMSD",value:function(){return this._rmsSum>0?Math.sqrt(this._rmsSum/(this.width*this.height)):0}},{key:"heightAt",value:function(e,t){return this.data[this.width*t+e]}},{key:"_flush",value:function(){for(var e=this.coords,t=0;t<this._pendingLen;t++){var r=this._pending[t],n=2*this.triangles[3*r+0],i=2*this.triangles[3*r+1],o=2*this.triangles[3*r+2];this._findCandidate(e[n],e[n+1],e[i],e[i+1],e[o],e[o+1],r)}this._pendingLen=0}},{key:"_findCandidate",value:function(e,t,r,n,i,o,a){for(var s=Math.min(e,r,i),u=Math.min(t,n,o),c=Math.max(e,r,i),l=Math.max(t,n,o),h=J(r,n,i,o,s,u),f=J(i,o,e,t,s,u),d=J(e,t,r,n,s,u),p=n-t,v=e-r,g=o-n,y=r-i,_=t-o,m=i-e,E=J(e,t,r,n,i,o),b=this.heightAt(e,t)/E,x=this.heightAt(r,n)/E,w=this.heightAt(i,o)/E,T=0,S=0,O=0,P=0,M=u;M<=l;M++){var I=0;h<0&&0!==g&&(I=Math.max(I,Math.floor(-h/g))),f<0&&0!==_&&(I=Math.max(I,Math.floor(-f/_))),d<0&&0!==p&&(I=Math.max(I,Math.floor(-d/p)));for(var L=h+g*I,k=f+_*I,A=d+p*I,j=!1,q=s+I;q<=c;q++){if(L>=0&&k>=0&&A>=0){j=!0;var N=b*L+x*k+w*A,D=Math.abs(N-this.heightAt(q,M));P+=D*D,D>T&&(T=D,S=q,O=M)}else if(j)break;L+=g,k+=_,A+=p}h+=y,f+=m,d+=v}(S===e&&O===t||S===r&&O===n||S===i&&O===o)&&(T=0),this._candidates[2*a]=S,this._candidates[2*a+1]=O,this._rms[a]=P,this._queuePush(a,T,P)}},{key:"_step",value:function(){var e=this._queuePop(),t=3*e+0,r=3*e+1,n=3*e+2,i=this.triangles[t],o=this.triangles[r],a=this.triangles[n],s=this.coords[2*i],u=this.coords[2*i+1],c=this.coords[2*o],l=this.coords[2*o+1],h=this.coords[2*a],f=this.coords[2*a+1],d=this._candidates[2*e],p=this._candidates[2*e+1],v=this._addPoint(d,p);if(0===J(s,u,c,l,d,p))this._handleCollinear(v,t);else if(0===J(c,l,h,f,d,p))this._handleCollinear(v,r);else if(0===J(h,f,s,u,d,p))this._handleCollinear(v,n);else{var g=this._halfedges[t],y=this._halfedges[r],_=this._halfedges[n],m=this._addTriangle(i,o,v,g,-1,-1,t),E=this._addTriangle(o,a,v,y,-1,m+1),b=this._addTriangle(a,i,v,_,m+2,E+1);this._legalize(m),this._legalize(E),this._legalize(b)}}},{key:"_addPoint",value:function(e,t){var r=this.coords.length>>1;return this.coords.push(e,t),r}},{key:"_addTriangle",value:function(e,t,r,n,i,o){var a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:this.triangles.length,s=a/3;return this.triangles[a+0]=e,this.triangles[a+1]=t,this.triangles[a+2]=r,this._halfedges[a+0]=n,this._halfedges[a+1]=i,this._halfedges[a+2]=o,n>=0&&(this._halfedges[n]=a+0),i>=0&&(this._halfedges[i]=a+1),o>=0&&(this._halfedges[o]=a+2),this._candidates[2*s+0]=0,this._candidates[2*s+1]=0,this._queueIndices[s]=-1,this._rms[s]=0,this._pending[this._pendingLen++]=s,a}},{key:"_legalize",value:function(e){var t=this._halfedges[e];if(!(t<0)){var r=e-e%3,n=t-t%3,i=r+(e+1)%3,o=r+(e+2)%3,a=n+(t+2)%3,s=n+(t+1)%3,u=this.triangles[o],c=this.triangles[e],l=this.triangles[i],h=this.triangles[a],f=this.coords;if(d=f[2*u],p=f[2*u+1],v=f[2*c],g=f[2*c+1],y=f[2*l],_=f[2*l+1],m=f[2*h],E=f[2*h+1],(b=d-m)*((T=g-E)*(M=(S=y-m)*S+(O=_-E)*O)-(P=(w=v-m)*w+T*T)*O)-(x=p-E)*(w*M-P*S)+(b*b+x*x)*(w*O-T*S)<0){var d,p,v,g,y,_,m,E,b,x,w,T,S,O,P,M,I=this._halfedges[i],L=this._halfedges[o],k=this._halfedges[a],A=this._halfedges[s];this._queueRemove(r/3),this._queueRemove(n/3);var j=this._addTriangle(u,h,l,-1,k,I,r),q=this._addTriangle(h,u,c,j,L,A,n);this._legalize(j+1),this._legalize(q+2)}}}},{key:"_handleCollinear",value:function(e,t){var r=t-t%3,n=r+(t+1)%3,i=r+(t+2)%3,o=this.triangles[i],a=this.triangles[t],s=this.triangles[n],u=this._halfedges[n],c=this._halfedges[i],l=this._halfedges[t];if(l<0){var h=this._addTriangle(e,o,a,-1,c,-1,r),f=this._addTriangle(o,e,s,h,-1,u);return this._legalize(h+1),void this._legalize(f+2)}var d=l-l%3,p=d+(l+2)%3,v=d+(l+1)%3,g=this.triangles[p],y=this._halfedges[p],_=this._halfedges[v];this._queueRemove(d/3);var m=this._addTriangle(o,a,e,c,-1,-1,r),E=this._addTriangle(a,g,e,_,-1,m+1,d),b=this._addTriangle(g,s,e,y,-1,E+1),x=this._addTriangle(s,o,e,u,m+2,b+1);this._legalize(m),this._legalize(E),this._legalize(b),this._legalize(x)}},{key:"_queuePush",value:function(e,t,r){var n=this._queue.length;this._queueIndices[e]=n,this._queue.push(e),this._errors.push(t),this._rmsSum+=r,this._queueUp(n)}},{key:"_queuePop",value:function(){var e=this._queue.length-1;return this._queueSwap(0,e),this._queueDown(0,e),this._queuePopBack()}},{key:"_queuePopBack",value:function(){var e=this._queue.pop();return this._errors.pop(),this._rmsSum-=this._rms[e],this._queueIndices[e]=-1,e}},{key:"_queueRemove",value:function(e){var t=this._queueIndices[e];if(t<0){var r=this._pending.indexOf(e);if(-1===r)throw new Error("Broken triangulation (something went wrong).");this._pending[r]=this._pending[--this._pendingLen]}else{var n=this._queue.length-1;n!==t&&(this._queueSwap(t,n),this._queueDown(t,n)||this._queueUp(t)),this._queuePopBack()}}},{key:"_queueLess",value:function(e,t){return this._errors[e]>this._errors[t]}},{key:"_queueSwap",value:function(e,t){var r=this._queue[e],n=this._queue[t];this._queue[e]=n,this._queue[t]=r,this._queueIndices[r]=t,this._queueIndices[n]=e;var i=this._errors[e];this._errors[e]=this._errors[t],this._errors[t]=i}},{key:"_queueUp",value:function(e){for(var t=e;;){var r=t-1>>1;if(r===t||!this._queueLess(t,r))break;this._queueSwap(r,t),t=r}}},{key:"_queueDown",value:function(e,t){for(var r=e;;){var n=2*r+1;if(n>=t||n<0)break;var i=n+1,o=n;if(i<t&&this._queueLess(i,n)&&(o=i),!this._queueLess(o,r))break;this._queueSwap(r,o),r=o}return r>e}}]),e}();function J(e,t,r,n,i,o){return(r-i)*(t-o)-(n-o)*(e-i)}function K(e,t,r,n,i){for(var o=n.rScaler,a=n.bScaler,s=n.gScaler,u=n.offset,c=new Float32Array((t+1)*(r+1)),l=0,h=0;h<r;h++)for(var f=0;f<t;f++,l++){var d=4*l,p=e[d+0],v=e[d+1],g=e[d+2];c[l+h]=p*o+v*s+g*a+u}if("martini"===i){for(var y=(t+1)*t,_=0;_<t;_++,y++)c[y]=c[y-t-1];for(var m=r,E=0;E<r+1;E++,m+=r+1)c[m]=c[m-1]}return c}function ee(e,t){if(null===e)return null;var r,n,i=t.meshMaxError,o=t.bounds,a=t.elevationDecoder,s=e.data,u=e.width,c=e.height;switch(t.tesselator){case"martini":n=te(i,u,r=K(s,u,c,a,t.tesselator));break;case"delatin":n=re(i,u,c,r=K(s,u,c,a,t.tesselator));break;default:n=u!==c||c&u-1?re(i,u,c,r=K(s,u,c,a,"delatin")):te(i,u,r=K(s,u,c,a,"martini"))}var l=n.vertices,h=n.triangles,f=function(e,t,r,n,i){for(var o=r+1,a=e.length/2,s=new Float32Array(3*a),u=new Float32Array(2*a),c=i||[0,0,r,n],l=O()(c,4),h=l[0],f=l[1],d=l[2],p=l[3],v=(d-h)/r,g=(p-f)/n,y=0;y<a;y++){var _=e[2*y],m=e[2*y+1],E=m*o+_;s[3*y+0]=_*v+h,s[3*y+1]=-m*g+p,s[3*y+2]=t[E],u[2*y+0]=_/r,u[2*y+1]=m/n}return{POSITION:{value:s,size:3},TEXCOORD_0:{value:u,size:2}}}(l,r,u,c,o),d=P(f);if(t.skirtHeight){var p=C(f,h,t.skirtHeight);f=p.attributes,h=p.triangles}return{loaderData:{header:{}},header:{vertexCount:h.length,boundingBox:d},mode:4,indices:{value:Uint32Array.from(h),size:1},attributes:f}}function te(e,t,r){var n=new Z(t+1).createTile(r).getMesh(e);return{vertices:n.vertices,triangles:n.triangles}}function re(e,t,r,n){var i=new W(n,t+1,r+1);return i.run(e),{vertices:i.coords,triangles:i.triangles}}function ne(){return(ne=a()(u.a.mark((function e(t,r,n){var i;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r.image=r.image||{},r.image.type="data",e.next=4,n.parse(t,r,r.baseUri);case 4:return i=e.sent,e.abrupt("return",ee(i,r.terrain));case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var ie={name:"Terrain",id:"terrain",module:"terrain",version:"3.1.0-alpha.3",worker:!0,extensions:["png","pngraw"],mimeTypes:["image/png"],options:{terrain:{tesselator:"auto",bounds:null,meshMaxError:10,elevationDecoder:{rScaler:1,gScaler:0,bScaler:0,offset:0},skirtHeight:null}}},oe={name:"Quantized Mesh",id:"quantized-mesh",module:"terrain",version:"3.1.0-alpha.3",worker:!0,extensions:["terrain"],mimeTypes:["application/vnd.quantized-mesh"],options:{"quantized-mesh":{bounds:[0,0,1,1],skirtHeight:null}}};function ae(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function se(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ae(Object(r),!0).forEach((function(t){i()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ae(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var ue,ce,le=se(se({},ie),{},{parse:function(e,t,r){return ne.apply(this,arguments)}});se(se({},oe),{},{parseSync:V,parse:(ue=a()(u.a.mark((function e(t,r){return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",V(t,r));case 1:case"end":return e.stop()}}),e)}))),function(e,t){return ue.apply(this,arguments)})});ce=le,"undefined"!=typeof self&&(y.onmessage=function(){var e=a()(u.a.mark((function e(t,r){var n,i,o,a,s;return u.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.t0=t,e.next="process"===e.t0?3:16;break;case 3:return e.prev=3,n=r.input,i=r.options,o=void 0===i?{}:i,e.next=7,w({loader:ce,arrayBuffer:n,options:o,context:{parse:x}});case 7:a=e.sent,y.postMessage("done",{result:a}),e.next=15;break;case 11:e.prev=11,e.t1=e.catch(3),s=e.t1 instanceof Error?e.t1.message:"",y.postMessage("error",{error:s});case 15:return e.abrupt("break",16);case 16:case"end":return e.stop()}}),e,null,[[3,11]])})));return function(t,r){return e.apply(this,arguments)}}())}]);
|
|
2
|
-
|
|
1
|
+
(() => {
|
|
2
|
+
// ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
|
|
3
|
+
function getTransferList(object, recursive = true, transfers) {
|
|
4
|
+
const transfersSet = transfers || new Set();
|
|
5
|
+
if (!object) {
|
|
6
|
+
} else if (isTransferable(object)) {
|
|
7
|
+
transfersSet.add(object);
|
|
8
|
+
} else if (isTransferable(object.buffer)) {
|
|
9
|
+
transfersSet.add(object.buffer);
|
|
10
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
11
|
+
} else if (recursive && typeof object === "object") {
|
|
12
|
+
for (const key in object) {
|
|
13
|
+
getTransferList(object[key], recursive, transfersSet);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
17
|
+
}
|
|
18
|
+
function isTransferable(object) {
|
|
19
|
+
if (!object) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (object instanceof ArrayBuffer) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ../worker-utils/src/lib/worker-farm/worker-body.ts
|
|
38
|
+
var onMessageWrapperMap = new Map();
|
|
39
|
+
var WorkerBody = class {
|
|
40
|
+
static set onmessage(onMessage) {
|
|
41
|
+
self.onmessage = (message) => {
|
|
42
|
+
if (!isKnownMessage(message)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const { type, payload } = message.data;
|
|
46
|
+
onMessage(type, payload);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
static addEventListener(onMessage) {
|
|
50
|
+
let onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
51
|
+
if (!onMessageWrapper) {
|
|
52
|
+
onMessageWrapper = (message) => {
|
|
53
|
+
if (!isKnownMessage(message)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { type, payload } = message.data;
|
|
57
|
+
onMessage(type, payload);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
self.addEventListener("message", onMessageWrapper);
|
|
61
|
+
}
|
|
62
|
+
static removeEventListener(onMessage) {
|
|
63
|
+
const onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
64
|
+
onMessageWrapperMap.delete(onMessage);
|
|
65
|
+
self.removeEventListener("message", onMessageWrapper);
|
|
66
|
+
}
|
|
67
|
+
static postMessage(type, payload) {
|
|
68
|
+
if (self) {
|
|
69
|
+
const data = { source: "loaders.gl", type, payload };
|
|
70
|
+
const transferList = getTransferList(payload);
|
|
71
|
+
self.postMessage(data, transferList);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function isKnownMessage(message) {
|
|
76
|
+
const { type, data } = message;
|
|
77
|
+
return type === "message" && data && typeof data.source === "string" && data.source.startsWith("loaders.gl");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
|
|
81
|
+
var requestId = 0;
|
|
82
|
+
function createLoaderWorker(loader) {
|
|
83
|
+
if (typeof self === "undefined") {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
WorkerBody.onmessage = async (type, payload) => {
|
|
87
|
+
switch (type) {
|
|
88
|
+
case "process":
|
|
89
|
+
try {
|
|
90
|
+
const { input, options = {} } = payload;
|
|
91
|
+
const result = await parseData({
|
|
92
|
+
loader,
|
|
93
|
+
arrayBuffer: input,
|
|
94
|
+
options,
|
|
95
|
+
context: {
|
|
96
|
+
parse: parseOnMainThread
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
WorkerBody.postMessage("done", { result });
|
|
100
|
+
} catch (error) {
|
|
101
|
+
const message = error instanceof Error ? error.message : "";
|
|
102
|
+
WorkerBody.postMessage("error", { error: message });
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function parseOnMainThread(arrayBuffer, options) {
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
const id = requestId++;
|
|
112
|
+
const onMessage = (type, payload2) => {
|
|
113
|
+
if (payload2.id !== id) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
switch (type) {
|
|
117
|
+
case "done":
|
|
118
|
+
WorkerBody.removeEventListener(onMessage);
|
|
119
|
+
resolve(payload2.result);
|
|
120
|
+
break;
|
|
121
|
+
case "error":
|
|
122
|
+
WorkerBody.removeEventListener(onMessage);
|
|
123
|
+
reject(payload2.error);
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
WorkerBody.addEventListener(onMessage);
|
|
129
|
+
const payload = { id, input: arrayBuffer, options };
|
|
130
|
+
WorkerBody.postMessage("process", payload);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
async function parseData({ loader, arrayBuffer, options, context }) {
|
|
134
|
+
let data;
|
|
135
|
+
let parser;
|
|
136
|
+
if (loader.parseSync || loader.parse) {
|
|
137
|
+
data = arrayBuffer;
|
|
138
|
+
parser = loader.parseSync || loader.parse;
|
|
139
|
+
} else if (loader.parseTextSync) {
|
|
140
|
+
const textDecoder = new TextDecoder();
|
|
141
|
+
data = textDecoder.decode(arrayBuffer);
|
|
142
|
+
parser = loader.parseTextSync;
|
|
143
|
+
} else {
|
|
144
|
+
throw new Error(`Could not load data with ${loader.name} loader`);
|
|
145
|
+
}
|
|
146
|
+
options = {
|
|
147
|
+
...options,
|
|
148
|
+
modules: loader && loader.options && loader.options.modules || {},
|
|
149
|
+
worker: false
|
|
150
|
+
};
|
|
151
|
+
return await parser(data, { ...options }, context, loader);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
|
|
155
|
+
function concatenateTypedArrays(...typedArrays) {
|
|
156
|
+
const arrays = typedArrays;
|
|
157
|
+
const TypedArrayConstructor = arrays && arrays.length > 1 && arrays[0].constructor || null;
|
|
158
|
+
if (!TypedArrayConstructor) {
|
|
159
|
+
throw new Error('"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types');
|
|
160
|
+
}
|
|
161
|
+
const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);
|
|
162
|
+
const result = new TypedArrayConstructor(sumLength);
|
|
163
|
+
let offset = 0;
|
|
164
|
+
for (const array of arrays) {
|
|
165
|
+
result.set(array, offset);
|
|
166
|
+
offset += array.length;
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ../schema/src/category/mesh/mesh-utils.ts
|
|
172
|
+
function getMeshBoundingBox(attributes) {
|
|
173
|
+
let minX = Infinity;
|
|
174
|
+
let minY = Infinity;
|
|
175
|
+
let minZ = Infinity;
|
|
176
|
+
let maxX = -Infinity;
|
|
177
|
+
let maxY = -Infinity;
|
|
178
|
+
let maxZ = -Infinity;
|
|
179
|
+
const positions = attributes.POSITION ? attributes.POSITION.value : [];
|
|
180
|
+
const len = positions && positions.length;
|
|
181
|
+
for (let i = 0; i < len; i += 3) {
|
|
182
|
+
const x = positions[i];
|
|
183
|
+
const y = positions[i + 1];
|
|
184
|
+
const z = positions[i + 2];
|
|
185
|
+
minX = x < minX ? x : minX;
|
|
186
|
+
minY = y < minY ? y : minY;
|
|
187
|
+
minZ = z < minZ ? z : minZ;
|
|
188
|
+
maxX = x > maxX ? x : maxX;
|
|
189
|
+
maxY = y > maxY ? y : maxY;
|
|
190
|
+
maxZ = z > maxZ ? z : maxZ;
|
|
191
|
+
}
|
|
192
|
+
return [
|
|
193
|
+
[minX, minY, minZ],
|
|
194
|
+
[maxX, maxY, maxZ]
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/lib/decode-quantized-mesh.ts
|
|
199
|
+
var QUANTIZED_MESH_HEADER = new Map([
|
|
200
|
+
["centerX", Float64Array.BYTES_PER_ELEMENT],
|
|
201
|
+
["centerY", Float64Array.BYTES_PER_ELEMENT],
|
|
202
|
+
["centerZ", Float64Array.BYTES_PER_ELEMENT],
|
|
203
|
+
["minHeight", Float32Array.BYTES_PER_ELEMENT],
|
|
204
|
+
["maxHeight", Float32Array.BYTES_PER_ELEMENT],
|
|
205
|
+
["boundingSphereCenterX", Float64Array.BYTES_PER_ELEMENT],
|
|
206
|
+
["boundingSphereCenterY", Float64Array.BYTES_PER_ELEMENT],
|
|
207
|
+
["boundingSphereCenterZ", Float64Array.BYTES_PER_ELEMENT],
|
|
208
|
+
["boundingSphereRadius", Float64Array.BYTES_PER_ELEMENT],
|
|
209
|
+
["horizonOcclusionPointX", Float64Array.BYTES_PER_ELEMENT],
|
|
210
|
+
["horizonOcclusionPointY", Float64Array.BYTES_PER_ELEMENT],
|
|
211
|
+
["horizonOcclusionPointZ", Float64Array.BYTES_PER_ELEMENT]
|
|
212
|
+
]);
|
|
213
|
+
function decodeZigZag(value) {
|
|
214
|
+
return value >> 1 ^ -(value & 1);
|
|
215
|
+
}
|
|
216
|
+
function decodeHeader(dataView) {
|
|
217
|
+
let position = 0;
|
|
218
|
+
const header = {};
|
|
219
|
+
for (const [key, bytesCount] of QUANTIZED_MESH_HEADER) {
|
|
220
|
+
const getter = bytesCount === 8 ? dataView.getFloat64 : dataView.getFloat32;
|
|
221
|
+
header[key] = getter.call(dataView, position, true);
|
|
222
|
+
position += bytesCount;
|
|
223
|
+
}
|
|
224
|
+
return { header, headerEndPosition: position };
|
|
225
|
+
}
|
|
226
|
+
function decodeVertexData(dataView, headerEndPosition) {
|
|
227
|
+
let position = headerEndPosition;
|
|
228
|
+
const elementsPerVertex = 3;
|
|
229
|
+
const vertexCount = dataView.getUint32(position, true);
|
|
230
|
+
const vertexData = new Uint16Array(vertexCount * elementsPerVertex);
|
|
231
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
232
|
+
const bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;
|
|
233
|
+
const elementArrayLength = vertexCount * bytesPerArrayElement;
|
|
234
|
+
const uArrayStartPosition = position;
|
|
235
|
+
const vArrayStartPosition = uArrayStartPosition + elementArrayLength;
|
|
236
|
+
const heightArrayStartPosition = vArrayStartPosition + elementArrayLength;
|
|
237
|
+
let u = 0;
|
|
238
|
+
let v = 0;
|
|
239
|
+
let height = 0;
|
|
240
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
241
|
+
u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));
|
|
242
|
+
v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));
|
|
243
|
+
height += decodeZigZag(dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true));
|
|
244
|
+
vertexData[i] = u;
|
|
245
|
+
vertexData[i + vertexCount] = v;
|
|
246
|
+
vertexData[i + vertexCount * 2] = height;
|
|
247
|
+
}
|
|
248
|
+
position += elementArrayLength * 3;
|
|
249
|
+
return { vertexData, vertexDataEndPosition: position };
|
|
250
|
+
}
|
|
251
|
+
function decodeIndex(buffer, position, indicesCount, bytesPerIndex, encoded = true) {
|
|
252
|
+
let indices;
|
|
253
|
+
if (bytesPerIndex === 2) {
|
|
254
|
+
indices = new Uint16Array(buffer, position, indicesCount);
|
|
255
|
+
} else {
|
|
256
|
+
indices = new Uint32Array(buffer, position, indicesCount);
|
|
257
|
+
}
|
|
258
|
+
if (!encoded) {
|
|
259
|
+
return indices;
|
|
260
|
+
}
|
|
261
|
+
let highest = 0;
|
|
262
|
+
for (let i = 0; i < indices.length; ++i) {
|
|
263
|
+
const code = indices[i];
|
|
264
|
+
indices[i] = highest - code;
|
|
265
|
+
if (code === 0) {
|
|
266
|
+
++highest;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return indices;
|
|
270
|
+
}
|
|
271
|
+
function decodeTriangleIndices(dataView, vertexData, vertexDataEndPosition) {
|
|
272
|
+
let position = vertexDataEndPosition;
|
|
273
|
+
const elementsPerVertex = 3;
|
|
274
|
+
const vertexCount = vertexData.length / elementsPerVertex;
|
|
275
|
+
const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
|
|
276
|
+
if (position % bytesPerIndex !== 0) {
|
|
277
|
+
position += bytesPerIndex - position % bytesPerIndex;
|
|
278
|
+
}
|
|
279
|
+
const triangleCount = dataView.getUint32(position, true);
|
|
280
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
281
|
+
const triangleIndicesCount = triangleCount * 3;
|
|
282
|
+
const triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex);
|
|
283
|
+
position += triangleIndicesCount * bytesPerIndex;
|
|
284
|
+
return {
|
|
285
|
+
triangleIndicesEndPosition: position,
|
|
286
|
+
triangleIndices
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function decodeEdgeIndices(dataView, vertexData, triangleIndicesEndPosition) {
|
|
290
|
+
let position = triangleIndicesEndPosition;
|
|
291
|
+
const elementsPerVertex = 3;
|
|
292
|
+
const vertexCount = vertexData.length / elementsPerVertex;
|
|
293
|
+
const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
|
|
294
|
+
const westVertexCount = dataView.getUint32(position, true);
|
|
295
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
296
|
+
const westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);
|
|
297
|
+
position += westVertexCount * bytesPerIndex;
|
|
298
|
+
const southVertexCount = dataView.getUint32(position, true);
|
|
299
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
300
|
+
const southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false);
|
|
301
|
+
position += southVertexCount * bytesPerIndex;
|
|
302
|
+
const eastVertexCount = dataView.getUint32(position, true);
|
|
303
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
304
|
+
const eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);
|
|
305
|
+
position += eastVertexCount * bytesPerIndex;
|
|
306
|
+
const northVertexCount = dataView.getUint32(position, true);
|
|
307
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
308
|
+
const northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false);
|
|
309
|
+
position += northVertexCount * bytesPerIndex;
|
|
310
|
+
return {
|
|
311
|
+
edgeIndicesEndPosition: position,
|
|
312
|
+
westIndices,
|
|
313
|
+
southIndices,
|
|
314
|
+
eastIndices,
|
|
315
|
+
northIndices
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function decodeVertexNormalsExtension(extensionDataView) {
|
|
319
|
+
return new Uint8Array(extensionDataView.buffer, extensionDataView.byteOffset, extensionDataView.byteLength);
|
|
320
|
+
}
|
|
321
|
+
function decodeWaterMaskExtension(extensionDataView) {
|
|
322
|
+
return extensionDataView.buffer.slice(extensionDataView.byteOffset, extensionDataView.byteOffset + extensionDataView.byteLength);
|
|
323
|
+
}
|
|
324
|
+
function decodeExtensions(dataView, indicesEndPosition) {
|
|
325
|
+
const extensions = {};
|
|
326
|
+
if (dataView.byteLength <= indicesEndPosition) {
|
|
327
|
+
return { extensions, extensionsEndPosition: indicesEndPosition };
|
|
328
|
+
}
|
|
329
|
+
let position = indicesEndPosition;
|
|
330
|
+
while (position < dataView.byteLength) {
|
|
331
|
+
const extensionId = dataView.getUint8(position, true);
|
|
332
|
+
position += Uint8Array.BYTES_PER_ELEMENT;
|
|
333
|
+
const extensionLength = dataView.getUint32(position, true);
|
|
334
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
335
|
+
const extensionView = new DataView(dataView.buffer, position, extensionLength);
|
|
336
|
+
switch (extensionId) {
|
|
337
|
+
case 1: {
|
|
338
|
+
extensions.vertexNormals = decodeVertexNormalsExtension(extensionView);
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
case 2: {
|
|
342
|
+
extensions.waterMask = decodeWaterMaskExtension(extensionView);
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
default: {
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
position += extensionLength;
|
|
349
|
+
}
|
|
350
|
+
return { extensions, extensionsEndPosition: position };
|
|
351
|
+
}
|
|
352
|
+
var DECODING_STEPS = {
|
|
353
|
+
header: 0,
|
|
354
|
+
vertices: 1,
|
|
355
|
+
triangleIndices: 2,
|
|
356
|
+
edgeIndices: 3,
|
|
357
|
+
extensions: 4
|
|
358
|
+
};
|
|
359
|
+
var DEFAULT_OPTIONS = {
|
|
360
|
+
maxDecodingStep: DECODING_STEPS.extensions
|
|
361
|
+
};
|
|
362
|
+
function decode(data, userOptions) {
|
|
363
|
+
const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
|
|
364
|
+
const view = new DataView(data);
|
|
365
|
+
const { header, headerEndPosition } = decodeHeader(view);
|
|
366
|
+
if (options.maxDecodingStep < DECODING_STEPS.vertices) {
|
|
367
|
+
return { header };
|
|
368
|
+
}
|
|
369
|
+
const { vertexData, vertexDataEndPosition } = decodeVertexData(view, headerEndPosition);
|
|
370
|
+
if (options.maxDecodingStep < DECODING_STEPS.triangleIndices) {
|
|
371
|
+
return { header, vertexData };
|
|
372
|
+
}
|
|
373
|
+
const { triangleIndices, triangleIndicesEndPosition } = decodeTriangleIndices(view, vertexData, vertexDataEndPosition);
|
|
374
|
+
if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {
|
|
375
|
+
return { header, vertexData, triangleIndices };
|
|
376
|
+
}
|
|
377
|
+
const { westIndices, southIndices, eastIndices, northIndices, edgeIndicesEndPosition } = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
|
|
378
|
+
if (options.maxDecodingStep < DECODING_STEPS.extensions) {
|
|
379
|
+
return {
|
|
380
|
+
header,
|
|
381
|
+
vertexData,
|
|
382
|
+
triangleIndices,
|
|
383
|
+
westIndices,
|
|
384
|
+
northIndices,
|
|
385
|
+
eastIndices,
|
|
386
|
+
southIndices
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
const { extensions } = decodeExtensions(view, edgeIndicesEndPosition);
|
|
390
|
+
return {
|
|
391
|
+
header,
|
|
392
|
+
vertexData,
|
|
393
|
+
triangleIndices,
|
|
394
|
+
westIndices,
|
|
395
|
+
northIndices,
|
|
396
|
+
eastIndices,
|
|
397
|
+
southIndices,
|
|
398
|
+
extensions
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// src/lib/helpers/skirt.ts
|
|
403
|
+
function addSkirt(attributes, triangles, skirtHeight, outsideIndices) {
|
|
404
|
+
const outsideEdges = outsideIndices ? getOutsideEdgesFromIndices(outsideIndices, attributes.POSITION.value) : getOutsideEdgesFromTriangles(triangles);
|
|
405
|
+
const newPosition = new attributes.POSITION.value.constructor(outsideEdges.length * 6);
|
|
406
|
+
const newTexcoord0 = new attributes.TEXCOORD_0.value.constructor(outsideEdges.length * 4);
|
|
407
|
+
const newTriangles = new triangles.constructor(outsideEdges.length * 6);
|
|
408
|
+
for (let i = 0; i < outsideEdges.length; i++) {
|
|
409
|
+
const edge = outsideEdges[i];
|
|
410
|
+
updateAttributesForNewEdge({
|
|
411
|
+
edge,
|
|
412
|
+
edgeIndex: i,
|
|
413
|
+
attributes,
|
|
414
|
+
skirtHeight,
|
|
415
|
+
newPosition,
|
|
416
|
+
newTexcoord0,
|
|
417
|
+
newTriangles
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
attributes.POSITION.value = concatenateTypedArrays(attributes.POSITION.value, newPosition);
|
|
421
|
+
attributes.TEXCOORD_0.value = concatenateTypedArrays(attributes.TEXCOORD_0.value, newTexcoord0);
|
|
422
|
+
const resultTriangles = triangles instanceof Array ? triangles.concat(newTriangles) : concatenateTypedArrays(triangles, newTriangles);
|
|
423
|
+
return {
|
|
424
|
+
attributes,
|
|
425
|
+
triangles: resultTriangles
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function getOutsideEdgesFromTriangles(triangles) {
|
|
429
|
+
const edges = [];
|
|
430
|
+
for (let i = 0; i < triangles.length; i += 3) {
|
|
431
|
+
edges.push([triangles[i], triangles[i + 1]]);
|
|
432
|
+
edges.push([triangles[i + 1], triangles[i + 2]]);
|
|
433
|
+
edges.push([triangles[i + 2], triangles[i]]);
|
|
434
|
+
}
|
|
435
|
+
edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
|
|
436
|
+
const outsideEdges = [];
|
|
437
|
+
let index = 1;
|
|
438
|
+
while (index < edges.length) {
|
|
439
|
+
if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {
|
|
440
|
+
index += 2;
|
|
441
|
+
} else {
|
|
442
|
+
outsideEdges.push(edges[index - 1]);
|
|
443
|
+
index++;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return outsideEdges;
|
|
447
|
+
}
|
|
448
|
+
function getOutsideEdgesFromIndices(indices, position) {
|
|
449
|
+
indices.westIndices.sort((a, b) => position[3 * a + 1] - position[3 * b + 1]);
|
|
450
|
+
indices.eastIndices.sort((a, b) => position[3 * b + 1] - position[3 * a + 1]);
|
|
451
|
+
indices.southIndices.sort((a, b) => position[3 * b] - position[3 * a]);
|
|
452
|
+
indices.northIndices.sort((a, b) => position[3 * a] - position[3 * b]);
|
|
453
|
+
const edges = [];
|
|
454
|
+
for (const index in indices) {
|
|
455
|
+
const indexGroup = indices[index];
|
|
456
|
+
for (let i = 0; i < indexGroup.length - 1; i++) {
|
|
457
|
+
edges.push([indexGroup[i], indexGroup[i + 1]]);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return edges;
|
|
461
|
+
}
|
|
462
|
+
function updateAttributesForNewEdge({
|
|
463
|
+
edge,
|
|
464
|
+
edgeIndex,
|
|
465
|
+
attributes,
|
|
466
|
+
skirtHeight,
|
|
467
|
+
newPosition,
|
|
468
|
+
newTexcoord0,
|
|
469
|
+
newTriangles
|
|
470
|
+
}) {
|
|
471
|
+
const positionsLength = attributes.POSITION.value.length;
|
|
472
|
+
const vertex1Offset = edgeIndex * 2;
|
|
473
|
+
const vertex2Offset = edgeIndex * 2 + 1;
|
|
474
|
+
newPosition.set(attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3), vertex1Offset * 3);
|
|
475
|
+
newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight;
|
|
476
|
+
newPosition.set(attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3), vertex2Offset * 3);
|
|
477
|
+
newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight;
|
|
478
|
+
newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2), vertex1Offset * 2);
|
|
479
|
+
newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2), vertex2Offset * 2);
|
|
480
|
+
const triangle1Offset = edgeIndex * 2 * 3;
|
|
481
|
+
newTriangles[triangle1Offset] = edge[0];
|
|
482
|
+
newTriangles[triangle1Offset + 1] = edge[1];
|
|
483
|
+
newTriangles[triangle1Offset + 2] = positionsLength / 3 + vertex2Offset;
|
|
484
|
+
newTriangles[triangle1Offset + 3] = positionsLength / 3 + vertex2Offset;
|
|
485
|
+
newTriangles[triangle1Offset + 4] = positionsLength / 3 + vertex1Offset;
|
|
486
|
+
newTriangles[triangle1Offset + 5] = edge[0];
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// src/lib/parse-quantized-mesh.ts
|
|
490
|
+
function getMeshAttributes(vertexData, header, bounds) {
|
|
491
|
+
const { minHeight, maxHeight } = header;
|
|
492
|
+
const [minX, minY, maxX, maxY] = bounds || [0, 0, 1, 1];
|
|
493
|
+
const xScale = maxX - minX;
|
|
494
|
+
const yScale = maxY - minY;
|
|
495
|
+
const zScale = maxHeight - minHeight;
|
|
496
|
+
const nCoords = vertexData.length / 3;
|
|
497
|
+
const positions = new Float32Array(nCoords * 3);
|
|
498
|
+
const texCoords = new Float32Array(nCoords * 2);
|
|
499
|
+
for (let i = 0; i < nCoords; i++) {
|
|
500
|
+
const x = vertexData[i] / 32767;
|
|
501
|
+
const y = vertexData[i + nCoords] / 32767;
|
|
502
|
+
const z = vertexData[i + nCoords * 2] / 32767;
|
|
503
|
+
positions[3 * i + 0] = x * xScale + minX;
|
|
504
|
+
positions[3 * i + 1] = y * yScale + minY;
|
|
505
|
+
positions[3 * i + 2] = z * zScale + minHeight;
|
|
506
|
+
texCoords[2 * i + 0] = x;
|
|
507
|
+
texCoords[2 * i + 1] = y;
|
|
508
|
+
}
|
|
509
|
+
return {
|
|
510
|
+
POSITION: { value: positions, size: 3 },
|
|
511
|
+
TEXCOORD_0: { value: texCoords, size: 2 }
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function getTileMesh(arrayBuffer, options) {
|
|
515
|
+
if (!arrayBuffer) {
|
|
516
|
+
return null;
|
|
517
|
+
}
|
|
518
|
+
const { bounds } = options;
|
|
519
|
+
const {
|
|
520
|
+
header,
|
|
521
|
+
vertexData,
|
|
522
|
+
triangleIndices: originalTriangleIndices,
|
|
523
|
+
westIndices,
|
|
524
|
+
northIndices,
|
|
525
|
+
eastIndices,
|
|
526
|
+
southIndices
|
|
527
|
+
} = decode(arrayBuffer, DECODING_STEPS.triangleIndices);
|
|
528
|
+
let triangleIndices = originalTriangleIndices;
|
|
529
|
+
let attributes = getMeshAttributes(vertexData, header, bounds);
|
|
530
|
+
const boundingBox = getMeshBoundingBox(attributes);
|
|
531
|
+
if (options.skirtHeight) {
|
|
532
|
+
const { attributes: newAttributes, triangles: newTriangles } = addSkirt(attributes, triangleIndices, options.skirtHeight, {
|
|
533
|
+
westIndices,
|
|
534
|
+
northIndices,
|
|
535
|
+
eastIndices,
|
|
536
|
+
southIndices
|
|
537
|
+
});
|
|
538
|
+
attributes = newAttributes;
|
|
539
|
+
triangleIndices = newTriangles;
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
loaderData: {
|
|
543
|
+
header: {}
|
|
544
|
+
},
|
|
545
|
+
header: {
|
|
546
|
+
vertexCount: triangleIndices.length,
|
|
547
|
+
boundingBox
|
|
548
|
+
},
|
|
549
|
+
mode: 4,
|
|
550
|
+
indices: { value: triangleIndices, size: 1 },
|
|
551
|
+
attributes
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
function loadQuantizedMesh(arrayBuffer, options) {
|
|
555
|
+
return getTileMesh(arrayBuffer, options["quantized-mesh"]);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// ../../node_modules/@mapbox/martini/index.js
|
|
559
|
+
var Martini = class {
|
|
560
|
+
constructor(gridSize = 257) {
|
|
561
|
+
this.gridSize = gridSize;
|
|
562
|
+
const tileSize = gridSize - 1;
|
|
563
|
+
if (tileSize & tileSize - 1)
|
|
564
|
+
throw new Error(`Expected grid size to be 2^n+1, got ${gridSize}.`);
|
|
565
|
+
this.numTriangles = tileSize * tileSize * 2 - 2;
|
|
566
|
+
this.numParentTriangles = this.numTriangles - tileSize * tileSize;
|
|
567
|
+
this.indices = new Uint32Array(this.gridSize * this.gridSize);
|
|
568
|
+
this.coords = new Uint16Array(this.numTriangles * 4);
|
|
569
|
+
for (let i = 0; i < this.numTriangles; i++) {
|
|
570
|
+
let id = i + 2;
|
|
571
|
+
let ax = 0, ay = 0, bx = 0, by = 0, cx = 0, cy = 0;
|
|
572
|
+
if (id & 1) {
|
|
573
|
+
bx = by = cx = tileSize;
|
|
574
|
+
} else {
|
|
575
|
+
ax = ay = cy = tileSize;
|
|
576
|
+
}
|
|
577
|
+
while ((id >>= 1) > 1) {
|
|
578
|
+
const mx = ax + bx >> 1;
|
|
579
|
+
const my = ay + by >> 1;
|
|
580
|
+
if (id & 1) {
|
|
581
|
+
bx = ax;
|
|
582
|
+
by = ay;
|
|
583
|
+
ax = cx;
|
|
584
|
+
ay = cy;
|
|
585
|
+
} else {
|
|
586
|
+
ax = bx;
|
|
587
|
+
ay = by;
|
|
588
|
+
bx = cx;
|
|
589
|
+
by = cy;
|
|
590
|
+
}
|
|
591
|
+
cx = mx;
|
|
592
|
+
cy = my;
|
|
593
|
+
}
|
|
594
|
+
const k = i * 4;
|
|
595
|
+
this.coords[k + 0] = ax;
|
|
596
|
+
this.coords[k + 1] = ay;
|
|
597
|
+
this.coords[k + 2] = bx;
|
|
598
|
+
this.coords[k + 3] = by;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
createTile(terrain) {
|
|
602
|
+
return new Tile(terrain, this);
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
var Tile = class {
|
|
606
|
+
constructor(terrain, martini) {
|
|
607
|
+
const size = martini.gridSize;
|
|
608
|
+
if (terrain.length !== size * size)
|
|
609
|
+
throw new Error(`Expected terrain data of length ${size * size} (${size} x ${size}), got ${terrain.length}.`);
|
|
610
|
+
this.terrain = terrain;
|
|
611
|
+
this.martini = martini;
|
|
612
|
+
this.errors = new Float32Array(terrain.length);
|
|
613
|
+
this.update();
|
|
614
|
+
}
|
|
615
|
+
update() {
|
|
616
|
+
const { numTriangles, numParentTriangles, coords, gridSize: size } = this.martini;
|
|
617
|
+
const { terrain, errors } = this;
|
|
618
|
+
for (let i = numTriangles - 1; i >= 0; i--) {
|
|
619
|
+
const k = i * 4;
|
|
620
|
+
const ax = coords[k + 0];
|
|
621
|
+
const ay = coords[k + 1];
|
|
622
|
+
const bx = coords[k + 2];
|
|
623
|
+
const by = coords[k + 3];
|
|
624
|
+
const mx = ax + bx >> 1;
|
|
625
|
+
const my = ay + by >> 1;
|
|
626
|
+
const cx = mx + my - ay;
|
|
627
|
+
const cy = my + ax - mx;
|
|
628
|
+
const interpolatedHeight = (terrain[ay * size + ax] + terrain[by * size + bx]) / 2;
|
|
629
|
+
const middleIndex = my * size + mx;
|
|
630
|
+
const middleError = Math.abs(interpolatedHeight - terrain[middleIndex]);
|
|
631
|
+
errors[middleIndex] = Math.max(errors[middleIndex], middleError);
|
|
632
|
+
if (i < numParentTriangles) {
|
|
633
|
+
const leftChildIndex = (ay + cy >> 1) * size + (ax + cx >> 1);
|
|
634
|
+
const rightChildIndex = (by + cy >> 1) * size + (bx + cx >> 1);
|
|
635
|
+
errors[middleIndex] = Math.max(errors[middleIndex], errors[leftChildIndex], errors[rightChildIndex]);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
getMesh(maxError = 0) {
|
|
640
|
+
const { gridSize: size, indices } = this.martini;
|
|
641
|
+
const { errors } = this;
|
|
642
|
+
let numVertices = 0;
|
|
643
|
+
let numTriangles = 0;
|
|
644
|
+
const max = size - 1;
|
|
645
|
+
indices.fill(0);
|
|
646
|
+
function countElements(ax, ay, bx, by, cx, cy) {
|
|
647
|
+
const mx = ax + bx >> 1;
|
|
648
|
+
const my = ay + by >> 1;
|
|
649
|
+
if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {
|
|
650
|
+
countElements(cx, cy, ax, ay, mx, my);
|
|
651
|
+
countElements(bx, by, cx, cy, mx, my);
|
|
652
|
+
} else {
|
|
653
|
+
indices[ay * size + ax] = indices[ay * size + ax] || ++numVertices;
|
|
654
|
+
indices[by * size + bx] = indices[by * size + bx] || ++numVertices;
|
|
655
|
+
indices[cy * size + cx] = indices[cy * size + cx] || ++numVertices;
|
|
656
|
+
numTriangles++;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
countElements(0, 0, max, max, max, 0);
|
|
660
|
+
countElements(max, max, 0, 0, 0, max);
|
|
661
|
+
const vertices = new Uint16Array(numVertices * 2);
|
|
662
|
+
const triangles = new Uint32Array(numTriangles * 3);
|
|
663
|
+
let triIndex = 0;
|
|
664
|
+
function processTriangle(ax, ay, bx, by, cx, cy) {
|
|
665
|
+
const mx = ax + bx >> 1;
|
|
666
|
+
const my = ay + by >> 1;
|
|
667
|
+
if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {
|
|
668
|
+
processTriangle(cx, cy, ax, ay, mx, my);
|
|
669
|
+
processTriangle(bx, by, cx, cy, mx, my);
|
|
670
|
+
} else {
|
|
671
|
+
const a = indices[ay * size + ax] - 1;
|
|
672
|
+
const b = indices[by * size + bx] - 1;
|
|
673
|
+
const c = indices[cy * size + cx] - 1;
|
|
674
|
+
vertices[2 * a] = ax;
|
|
675
|
+
vertices[2 * a + 1] = ay;
|
|
676
|
+
vertices[2 * b] = bx;
|
|
677
|
+
vertices[2 * b + 1] = by;
|
|
678
|
+
vertices[2 * c] = cx;
|
|
679
|
+
vertices[2 * c + 1] = cy;
|
|
680
|
+
triangles[triIndex++] = a;
|
|
681
|
+
triangles[triIndex++] = b;
|
|
682
|
+
triangles[triIndex++] = c;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
processTriangle(0, 0, max, max, max, 0);
|
|
686
|
+
processTriangle(max, max, 0, 0, 0, max);
|
|
687
|
+
return { vertices, triangles };
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
// src/lib/delatin/index.js
|
|
692
|
+
var Delatin = class {
|
|
693
|
+
constructor(data, width, height = width) {
|
|
694
|
+
this.data = data;
|
|
695
|
+
this.width = width;
|
|
696
|
+
this.height = height;
|
|
697
|
+
this.coords = [];
|
|
698
|
+
this.triangles = [];
|
|
699
|
+
this._halfedges = [];
|
|
700
|
+
this._candidates = [];
|
|
701
|
+
this._queueIndices = [];
|
|
702
|
+
this._queue = [];
|
|
703
|
+
this._errors = [];
|
|
704
|
+
this._rms = [];
|
|
705
|
+
this._pending = [];
|
|
706
|
+
this._pendingLen = 0;
|
|
707
|
+
this._rmsSum = 0;
|
|
708
|
+
const x1 = width - 1;
|
|
709
|
+
const y1 = height - 1;
|
|
710
|
+
const p0 = this._addPoint(0, 0);
|
|
711
|
+
const p1 = this._addPoint(x1, 0);
|
|
712
|
+
const p2 = this._addPoint(0, y1);
|
|
713
|
+
const p3 = this._addPoint(x1, y1);
|
|
714
|
+
const t0 = this._addTriangle(p3, p0, p2, -1, -1, -1);
|
|
715
|
+
this._addTriangle(p0, p3, p1, t0, -1, -1);
|
|
716
|
+
this._flush();
|
|
717
|
+
}
|
|
718
|
+
run(maxError = 1) {
|
|
719
|
+
while (this.getMaxError() > maxError) {
|
|
720
|
+
this.refine();
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
refine() {
|
|
724
|
+
this._step();
|
|
725
|
+
this._flush();
|
|
726
|
+
}
|
|
727
|
+
getMaxError() {
|
|
728
|
+
return this._errors[0];
|
|
729
|
+
}
|
|
730
|
+
getRMSD() {
|
|
731
|
+
return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;
|
|
732
|
+
}
|
|
733
|
+
heightAt(x, y) {
|
|
734
|
+
return this.data[this.width * y + x];
|
|
735
|
+
}
|
|
736
|
+
_flush() {
|
|
737
|
+
const coords = this.coords;
|
|
738
|
+
for (let i = 0; i < this._pendingLen; i++) {
|
|
739
|
+
const t = this._pending[i];
|
|
740
|
+
const a = 2 * this.triangles[t * 3 + 0];
|
|
741
|
+
const b = 2 * this.triangles[t * 3 + 1];
|
|
742
|
+
const c = 2 * this.triangles[t * 3 + 2];
|
|
743
|
+
this._findCandidate(coords[a], coords[a + 1], coords[b], coords[b + 1], coords[c], coords[c + 1], t);
|
|
744
|
+
}
|
|
745
|
+
this._pendingLen = 0;
|
|
746
|
+
}
|
|
747
|
+
_findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {
|
|
748
|
+
const minX = Math.min(p0x, p1x, p2x);
|
|
749
|
+
const minY = Math.min(p0y, p1y, p2y);
|
|
750
|
+
const maxX = Math.max(p0x, p1x, p2x);
|
|
751
|
+
const maxY = Math.max(p0y, p1y, p2y);
|
|
752
|
+
let w00 = orient(p1x, p1y, p2x, p2y, minX, minY);
|
|
753
|
+
let w01 = orient(p2x, p2y, p0x, p0y, minX, minY);
|
|
754
|
+
let w02 = orient(p0x, p0y, p1x, p1y, minX, minY);
|
|
755
|
+
const a01 = p1y - p0y;
|
|
756
|
+
const b01 = p0x - p1x;
|
|
757
|
+
const a12 = p2y - p1y;
|
|
758
|
+
const b12 = p1x - p2x;
|
|
759
|
+
const a20 = p0y - p2y;
|
|
760
|
+
const b20 = p2x - p0x;
|
|
761
|
+
const a = orient(p0x, p0y, p1x, p1y, p2x, p2y);
|
|
762
|
+
const z0 = this.heightAt(p0x, p0y) / a;
|
|
763
|
+
const z1 = this.heightAt(p1x, p1y) / a;
|
|
764
|
+
const z2 = this.heightAt(p2x, p2y) / a;
|
|
765
|
+
let maxError = 0;
|
|
766
|
+
let mx = 0;
|
|
767
|
+
let my = 0;
|
|
768
|
+
let rms = 0;
|
|
769
|
+
for (let y = minY; y <= maxY; y++) {
|
|
770
|
+
let dx = 0;
|
|
771
|
+
if (w00 < 0 && a12 !== 0) {
|
|
772
|
+
dx = Math.max(dx, Math.floor(-w00 / a12));
|
|
773
|
+
}
|
|
774
|
+
if (w01 < 0 && a20 !== 0) {
|
|
775
|
+
dx = Math.max(dx, Math.floor(-w01 / a20));
|
|
776
|
+
}
|
|
777
|
+
if (w02 < 0 && a01 !== 0) {
|
|
778
|
+
dx = Math.max(dx, Math.floor(-w02 / a01));
|
|
779
|
+
}
|
|
780
|
+
let w0 = w00 + a12 * dx;
|
|
781
|
+
let w1 = w01 + a20 * dx;
|
|
782
|
+
let w2 = w02 + a01 * dx;
|
|
783
|
+
let wasInside = false;
|
|
784
|
+
for (let x = minX + dx; x <= maxX; x++) {
|
|
785
|
+
if (w0 >= 0 && w1 >= 0 && w2 >= 0) {
|
|
786
|
+
wasInside = true;
|
|
787
|
+
const z = z0 * w0 + z1 * w1 + z2 * w2;
|
|
788
|
+
const dz = Math.abs(z - this.heightAt(x, y));
|
|
789
|
+
rms += dz * dz;
|
|
790
|
+
if (dz > maxError) {
|
|
791
|
+
maxError = dz;
|
|
792
|
+
mx = x;
|
|
793
|
+
my = y;
|
|
794
|
+
}
|
|
795
|
+
} else if (wasInside) {
|
|
796
|
+
break;
|
|
797
|
+
}
|
|
798
|
+
w0 += a12;
|
|
799
|
+
w1 += a20;
|
|
800
|
+
w2 += a01;
|
|
801
|
+
}
|
|
802
|
+
w00 += b12;
|
|
803
|
+
w01 += b20;
|
|
804
|
+
w02 += b01;
|
|
805
|
+
}
|
|
806
|
+
if (mx === p0x && my === p0y || mx === p1x && my === p1y || mx === p2x && my === p2y) {
|
|
807
|
+
maxError = 0;
|
|
808
|
+
}
|
|
809
|
+
this._candidates[2 * t] = mx;
|
|
810
|
+
this._candidates[2 * t + 1] = my;
|
|
811
|
+
this._rms[t] = rms;
|
|
812
|
+
this._queuePush(t, maxError, rms);
|
|
813
|
+
}
|
|
814
|
+
_step() {
|
|
815
|
+
const t = this._queuePop();
|
|
816
|
+
const e0 = t * 3 + 0;
|
|
817
|
+
const e1 = t * 3 + 1;
|
|
818
|
+
const e2 = t * 3 + 2;
|
|
819
|
+
const p0 = this.triangles[e0];
|
|
820
|
+
const p1 = this.triangles[e1];
|
|
821
|
+
const p2 = this.triangles[e2];
|
|
822
|
+
const ax = this.coords[2 * p0];
|
|
823
|
+
const ay = this.coords[2 * p0 + 1];
|
|
824
|
+
const bx = this.coords[2 * p1];
|
|
825
|
+
const by = this.coords[2 * p1 + 1];
|
|
826
|
+
const cx = this.coords[2 * p2];
|
|
827
|
+
const cy = this.coords[2 * p2 + 1];
|
|
828
|
+
const px = this._candidates[2 * t];
|
|
829
|
+
const py = this._candidates[2 * t + 1];
|
|
830
|
+
const pn = this._addPoint(px, py);
|
|
831
|
+
if (orient(ax, ay, bx, by, px, py) === 0) {
|
|
832
|
+
this._handleCollinear(pn, e0);
|
|
833
|
+
} else if (orient(bx, by, cx, cy, px, py) === 0) {
|
|
834
|
+
this._handleCollinear(pn, e1);
|
|
835
|
+
} else if (orient(cx, cy, ax, ay, px, py) === 0) {
|
|
836
|
+
this._handleCollinear(pn, e2);
|
|
837
|
+
} else {
|
|
838
|
+
const h0 = this._halfedges[e0];
|
|
839
|
+
const h1 = this._halfedges[e1];
|
|
840
|
+
const h2 = this._halfedges[e2];
|
|
841
|
+
const t0 = this._addTriangle(p0, p1, pn, h0, -1, -1, e0);
|
|
842
|
+
const t1 = this._addTriangle(p1, p2, pn, h1, -1, t0 + 1);
|
|
843
|
+
const t2 = this._addTriangle(p2, p0, pn, h2, t0 + 2, t1 + 1);
|
|
844
|
+
this._legalize(t0);
|
|
845
|
+
this._legalize(t1);
|
|
846
|
+
this._legalize(t2);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
_addPoint(x, y) {
|
|
850
|
+
const i = this.coords.length >> 1;
|
|
851
|
+
this.coords.push(x, y);
|
|
852
|
+
return i;
|
|
853
|
+
}
|
|
854
|
+
_addTriangle(a, b, c, ab, bc, ca, e = this.triangles.length) {
|
|
855
|
+
const t = e / 3;
|
|
856
|
+
this.triangles[e + 0] = a;
|
|
857
|
+
this.triangles[e + 1] = b;
|
|
858
|
+
this.triangles[e + 2] = c;
|
|
859
|
+
this._halfedges[e + 0] = ab;
|
|
860
|
+
this._halfedges[e + 1] = bc;
|
|
861
|
+
this._halfedges[e + 2] = ca;
|
|
862
|
+
if (ab >= 0) {
|
|
863
|
+
this._halfedges[ab] = e + 0;
|
|
864
|
+
}
|
|
865
|
+
if (bc >= 0) {
|
|
866
|
+
this._halfedges[bc] = e + 1;
|
|
867
|
+
}
|
|
868
|
+
if (ca >= 0) {
|
|
869
|
+
this._halfedges[ca] = e + 2;
|
|
870
|
+
}
|
|
871
|
+
this._candidates[2 * t + 0] = 0;
|
|
872
|
+
this._candidates[2 * t + 1] = 0;
|
|
873
|
+
this._queueIndices[t] = -1;
|
|
874
|
+
this._rms[t] = 0;
|
|
875
|
+
this._pending[this._pendingLen++] = t;
|
|
876
|
+
return e;
|
|
877
|
+
}
|
|
878
|
+
_legalize(a) {
|
|
879
|
+
const b = this._halfedges[a];
|
|
880
|
+
if (b < 0) {
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
const a0 = a - a % 3;
|
|
884
|
+
const b0 = b - b % 3;
|
|
885
|
+
const al = a0 + (a + 1) % 3;
|
|
886
|
+
const ar = a0 + (a + 2) % 3;
|
|
887
|
+
const bl = b0 + (b + 2) % 3;
|
|
888
|
+
const br = b0 + (b + 1) % 3;
|
|
889
|
+
const p0 = this.triangles[ar];
|
|
890
|
+
const pr = this.triangles[a];
|
|
891
|
+
const pl = this.triangles[al];
|
|
892
|
+
const p1 = this.triangles[bl];
|
|
893
|
+
const coords = this.coords;
|
|
894
|
+
if (!inCircle(coords[2 * p0], coords[2 * p0 + 1], coords[2 * pr], coords[2 * pr + 1], coords[2 * pl], coords[2 * pl + 1], coords[2 * p1], coords[2 * p1 + 1])) {
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
const hal = this._halfedges[al];
|
|
898
|
+
const har = this._halfedges[ar];
|
|
899
|
+
const hbl = this._halfedges[bl];
|
|
900
|
+
const hbr = this._halfedges[br];
|
|
901
|
+
this._queueRemove(a0 / 3);
|
|
902
|
+
this._queueRemove(b0 / 3);
|
|
903
|
+
const t0 = this._addTriangle(p0, p1, pl, -1, hbl, hal, a0);
|
|
904
|
+
const t1 = this._addTriangle(p1, p0, pr, t0, har, hbr, b0);
|
|
905
|
+
this._legalize(t0 + 1);
|
|
906
|
+
this._legalize(t1 + 2);
|
|
907
|
+
}
|
|
908
|
+
_handleCollinear(pn, a) {
|
|
909
|
+
const a0 = a - a % 3;
|
|
910
|
+
const al = a0 + (a + 1) % 3;
|
|
911
|
+
const ar = a0 + (a + 2) % 3;
|
|
912
|
+
const p0 = this.triangles[ar];
|
|
913
|
+
const pr = this.triangles[a];
|
|
914
|
+
const pl = this.triangles[al];
|
|
915
|
+
const hal = this._halfedges[al];
|
|
916
|
+
const har = this._halfedges[ar];
|
|
917
|
+
const b = this._halfedges[a];
|
|
918
|
+
if (b < 0) {
|
|
919
|
+
const t02 = this._addTriangle(pn, p0, pr, -1, har, -1, a0);
|
|
920
|
+
const t12 = this._addTriangle(p0, pn, pl, t02, -1, hal);
|
|
921
|
+
this._legalize(t02 + 1);
|
|
922
|
+
this._legalize(t12 + 2);
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
const b0 = b - b % 3;
|
|
926
|
+
const bl = b0 + (b + 2) % 3;
|
|
927
|
+
const br = b0 + (b + 1) % 3;
|
|
928
|
+
const p1 = this.triangles[bl];
|
|
929
|
+
const hbl = this._halfedges[bl];
|
|
930
|
+
const hbr = this._halfedges[br];
|
|
931
|
+
this._queueRemove(b0 / 3);
|
|
932
|
+
const t0 = this._addTriangle(p0, pr, pn, har, -1, -1, a0);
|
|
933
|
+
const t1 = this._addTriangle(pr, p1, pn, hbr, -1, t0 + 1, b0);
|
|
934
|
+
const t2 = this._addTriangle(p1, pl, pn, hbl, -1, t1 + 1);
|
|
935
|
+
const t3 = this._addTriangle(pl, p0, pn, hal, t0 + 2, t2 + 1);
|
|
936
|
+
this._legalize(t0);
|
|
937
|
+
this._legalize(t1);
|
|
938
|
+
this._legalize(t2);
|
|
939
|
+
this._legalize(t3);
|
|
940
|
+
}
|
|
941
|
+
_queuePush(t, error, rms) {
|
|
942
|
+
const i = this._queue.length;
|
|
943
|
+
this._queueIndices[t] = i;
|
|
944
|
+
this._queue.push(t);
|
|
945
|
+
this._errors.push(error);
|
|
946
|
+
this._rmsSum += rms;
|
|
947
|
+
this._queueUp(i);
|
|
948
|
+
}
|
|
949
|
+
_queuePop() {
|
|
950
|
+
const n = this._queue.length - 1;
|
|
951
|
+
this._queueSwap(0, n);
|
|
952
|
+
this._queueDown(0, n);
|
|
953
|
+
return this._queuePopBack();
|
|
954
|
+
}
|
|
955
|
+
_queuePopBack() {
|
|
956
|
+
const t = this._queue.pop();
|
|
957
|
+
this._errors.pop();
|
|
958
|
+
this._rmsSum -= this._rms[t];
|
|
959
|
+
this._queueIndices[t] = -1;
|
|
960
|
+
return t;
|
|
961
|
+
}
|
|
962
|
+
_queueRemove(t) {
|
|
963
|
+
const i = this._queueIndices[t];
|
|
964
|
+
if (i < 0) {
|
|
965
|
+
const it = this._pending.indexOf(t);
|
|
966
|
+
if (it !== -1) {
|
|
967
|
+
this._pending[it] = this._pending[--this._pendingLen];
|
|
968
|
+
} else {
|
|
969
|
+
throw new Error("Broken triangulation (something went wrong).");
|
|
970
|
+
}
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
const n = this._queue.length - 1;
|
|
974
|
+
if (n !== i) {
|
|
975
|
+
this._queueSwap(i, n);
|
|
976
|
+
if (!this._queueDown(i, n)) {
|
|
977
|
+
this._queueUp(i);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
this._queuePopBack();
|
|
981
|
+
}
|
|
982
|
+
_queueLess(i, j) {
|
|
983
|
+
return this._errors[i] > this._errors[j];
|
|
984
|
+
}
|
|
985
|
+
_queueSwap(i, j) {
|
|
986
|
+
const pi = this._queue[i];
|
|
987
|
+
const pj = this._queue[j];
|
|
988
|
+
this._queue[i] = pj;
|
|
989
|
+
this._queue[j] = pi;
|
|
990
|
+
this._queueIndices[pi] = j;
|
|
991
|
+
this._queueIndices[pj] = i;
|
|
992
|
+
const e = this._errors[i];
|
|
993
|
+
this._errors[i] = this._errors[j];
|
|
994
|
+
this._errors[j] = e;
|
|
995
|
+
}
|
|
996
|
+
_queueUp(j0) {
|
|
997
|
+
let j = j0;
|
|
998
|
+
while (true) {
|
|
999
|
+
const i = j - 1 >> 1;
|
|
1000
|
+
if (i === j || !this._queueLess(j, i)) {
|
|
1001
|
+
break;
|
|
1002
|
+
}
|
|
1003
|
+
this._queueSwap(i, j);
|
|
1004
|
+
j = i;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
_queueDown(i0, n) {
|
|
1008
|
+
let i = i0;
|
|
1009
|
+
while (true) {
|
|
1010
|
+
const j1 = 2 * i + 1;
|
|
1011
|
+
if (j1 >= n || j1 < 0) {
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
const j2 = j1 + 1;
|
|
1015
|
+
let j = j1;
|
|
1016
|
+
if (j2 < n && this._queueLess(j2, j1)) {
|
|
1017
|
+
j = j2;
|
|
1018
|
+
}
|
|
1019
|
+
if (!this._queueLess(j, i)) {
|
|
1020
|
+
break;
|
|
1021
|
+
}
|
|
1022
|
+
this._queueSwap(i, j);
|
|
1023
|
+
i = j;
|
|
1024
|
+
}
|
|
1025
|
+
return i > i0;
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
function orient(ax, ay, bx, by, cx, cy) {
|
|
1029
|
+
return (bx - cx) * (ay - cy) - (by - cy) * (ax - cx);
|
|
1030
|
+
}
|
|
1031
|
+
function inCircle(ax, ay, bx, by, cx, cy, px, py) {
|
|
1032
|
+
const dx = ax - px;
|
|
1033
|
+
const dy = ay - py;
|
|
1034
|
+
const ex = bx - px;
|
|
1035
|
+
const ey = by - py;
|
|
1036
|
+
const fx = cx - px;
|
|
1037
|
+
const fy = cy - py;
|
|
1038
|
+
const ap = dx * dx + dy * dy;
|
|
1039
|
+
const bp = ex * ex + ey * ey;
|
|
1040
|
+
const cp = fx * fx + fy * fy;
|
|
1041
|
+
return dx * (ey * cp - bp * fy) - dy * (ex * cp - bp * fx) + ap * (ex * fy - ey * fx) < 0;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// src/lib/parse-terrain.ts
|
|
1045
|
+
function getTerrain(imageData, width, height, elevationDecoder, tesselator) {
|
|
1046
|
+
const { rScaler, bScaler, gScaler, offset } = elevationDecoder;
|
|
1047
|
+
const terrain = new Float32Array((width + 1) * (height + 1));
|
|
1048
|
+
for (let i = 0, y = 0; y < height; y++) {
|
|
1049
|
+
for (let x = 0; x < width; x++, i++) {
|
|
1050
|
+
const k = i * 4;
|
|
1051
|
+
const r = imageData[k + 0];
|
|
1052
|
+
const g = imageData[k + 1];
|
|
1053
|
+
const b = imageData[k + 2];
|
|
1054
|
+
terrain[i + y] = r * rScaler + g * gScaler + b * bScaler + offset;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
if (tesselator === "martini") {
|
|
1058
|
+
for (let i = (width + 1) * width, x = 0; x < width; x++, i++) {
|
|
1059
|
+
terrain[i] = terrain[i - width - 1];
|
|
1060
|
+
}
|
|
1061
|
+
for (let i = height, y = 0; y < height + 1; y++, i += height + 1) {
|
|
1062
|
+
terrain[i] = terrain[i - 1];
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
return terrain;
|
|
1066
|
+
}
|
|
1067
|
+
function getMeshAttributes2(vertices, terrain, width, height, bounds) {
|
|
1068
|
+
const gridSize = width + 1;
|
|
1069
|
+
const numOfVerticies = vertices.length / 2;
|
|
1070
|
+
const positions = new Float32Array(numOfVerticies * 3);
|
|
1071
|
+
const texCoords = new Float32Array(numOfVerticies * 2);
|
|
1072
|
+
const [minX, minY, maxX, maxY] = bounds || [0, 0, width, height];
|
|
1073
|
+
const xScale = (maxX - minX) / width;
|
|
1074
|
+
const yScale = (maxY - minY) / height;
|
|
1075
|
+
for (let i = 0; i < numOfVerticies; i++) {
|
|
1076
|
+
const x = vertices[i * 2];
|
|
1077
|
+
const y = vertices[i * 2 + 1];
|
|
1078
|
+
const pixelIdx = y * gridSize + x;
|
|
1079
|
+
positions[3 * i + 0] = x * xScale + minX;
|
|
1080
|
+
positions[3 * i + 1] = -y * yScale + maxY;
|
|
1081
|
+
positions[3 * i + 2] = terrain[pixelIdx];
|
|
1082
|
+
texCoords[2 * i + 0] = x / width;
|
|
1083
|
+
texCoords[2 * i + 1] = y / height;
|
|
1084
|
+
}
|
|
1085
|
+
return {
|
|
1086
|
+
POSITION: { value: positions, size: 3 },
|
|
1087
|
+
TEXCOORD_0: { value: texCoords, size: 2 }
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
function getMesh(terrainImage, terrainOptions) {
|
|
1091
|
+
if (terrainImage === null) {
|
|
1092
|
+
return null;
|
|
1093
|
+
}
|
|
1094
|
+
const { meshMaxError, bounds, elevationDecoder } = terrainOptions;
|
|
1095
|
+
const { data, width, height } = terrainImage;
|
|
1096
|
+
let terrain;
|
|
1097
|
+
let mesh;
|
|
1098
|
+
switch (terrainOptions.tesselator) {
|
|
1099
|
+
case "martini":
|
|
1100
|
+
terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);
|
|
1101
|
+
mesh = getMartiniTileMesh(meshMaxError, width, terrain);
|
|
1102
|
+
break;
|
|
1103
|
+
case "delatin":
|
|
1104
|
+
terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);
|
|
1105
|
+
mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);
|
|
1106
|
+
break;
|
|
1107
|
+
default:
|
|
1108
|
+
if (width === height && !(height & width - 1)) {
|
|
1109
|
+
terrain = getTerrain(data, width, height, elevationDecoder, "martini");
|
|
1110
|
+
mesh = getMartiniTileMesh(meshMaxError, width, terrain);
|
|
1111
|
+
} else {
|
|
1112
|
+
terrain = getTerrain(data, width, height, elevationDecoder, "delatin");
|
|
1113
|
+
mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);
|
|
1114
|
+
}
|
|
1115
|
+
break;
|
|
1116
|
+
}
|
|
1117
|
+
const { vertices } = mesh;
|
|
1118
|
+
let { triangles } = mesh;
|
|
1119
|
+
let attributes = getMeshAttributes2(vertices, terrain, width, height, bounds);
|
|
1120
|
+
const boundingBox = getMeshBoundingBox(attributes);
|
|
1121
|
+
if (terrainOptions.skirtHeight) {
|
|
1122
|
+
const { attributes: newAttributes, triangles: newTriangles } = addSkirt(attributes, triangles, terrainOptions.skirtHeight);
|
|
1123
|
+
attributes = newAttributes;
|
|
1124
|
+
triangles = newTriangles;
|
|
1125
|
+
}
|
|
1126
|
+
return {
|
|
1127
|
+
loaderData: {
|
|
1128
|
+
header: {}
|
|
1129
|
+
},
|
|
1130
|
+
header: {
|
|
1131
|
+
vertexCount: triangles.length,
|
|
1132
|
+
boundingBox
|
|
1133
|
+
},
|
|
1134
|
+
mode: 4,
|
|
1135
|
+
indices: { value: Uint32Array.from(triangles), size: 1 },
|
|
1136
|
+
attributes
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
function getMartiniTileMesh(meshMaxError, width, terrain) {
|
|
1140
|
+
const gridSize = width + 1;
|
|
1141
|
+
const martini = new Martini(gridSize);
|
|
1142
|
+
const tile = martini.createTile(terrain);
|
|
1143
|
+
const { vertices, triangles } = tile.getMesh(meshMaxError);
|
|
1144
|
+
return { vertices, triangles };
|
|
1145
|
+
}
|
|
1146
|
+
function getDelatinTileMesh(meshMaxError, width, height, terrain) {
|
|
1147
|
+
const tin = new Delatin(terrain, width + 1, height + 1);
|
|
1148
|
+
tin.run(meshMaxError);
|
|
1149
|
+
const { coords, triangles } = tin;
|
|
1150
|
+
const vertices = coords;
|
|
1151
|
+
return { vertices, triangles };
|
|
1152
|
+
}
|
|
1153
|
+
async function loadTerrain(arrayBuffer, options, context) {
|
|
1154
|
+
options.image = options.image || {};
|
|
1155
|
+
options.image.type = "data";
|
|
1156
|
+
const image = await context.parse(arrayBuffer, options, options.baseUri);
|
|
1157
|
+
return getMesh(image, options.terrain);
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// src/lib/utils/version.js
|
|
1161
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1162
|
+
|
|
1163
|
+
// src/terrain-loader.ts
|
|
1164
|
+
var TerrainLoader = {
|
|
1165
|
+
name: "Terrain",
|
|
1166
|
+
id: "terrain",
|
|
1167
|
+
module: "terrain",
|
|
1168
|
+
version: VERSION,
|
|
1169
|
+
worker: true,
|
|
1170
|
+
extensions: ["png", "pngraw"],
|
|
1171
|
+
mimeTypes: ["image/png"],
|
|
1172
|
+
options: {
|
|
1173
|
+
terrain: {
|
|
1174
|
+
tesselator: "auto",
|
|
1175
|
+
bounds: null,
|
|
1176
|
+
meshMaxError: 10,
|
|
1177
|
+
elevationDecoder: {
|
|
1178
|
+
rScaler: 1,
|
|
1179
|
+
gScaler: 0,
|
|
1180
|
+
bScaler: 0,
|
|
1181
|
+
offset: 0
|
|
1182
|
+
},
|
|
1183
|
+
skirtHeight: null
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
|
|
1188
|
+
// src/quantized-mesh-loader.ts
|
|
1189
|
+
var QuantizedMeshLoader = {
|
|
1190
|
+
name: "Quantized Mesh",
|
|
1191
|
+
id: "quantized-mesh",
|
|
1192
|
+
module: "terrain",
|
|
1193
|
+
version: VERSION,
|
|
1194
|
+
worker: true,
|
|
1195
|
+
extensions: ["terrain"],
|
|
1196
|
+
mimeTypes: ["application/vnd.quantized-mesh"],
|
|
1197
|
+
options: {
|
|
1198
|
+
"quantized-mesh": {
|
|
1199
|
+
bounds: [0, 0, 1, 1],
|
|
1200
|
+
skirtHeight: null
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
|
|
1205
|
+
// src/index.ts
|
|
1206
|
+
var TerrainLoader2 = {
|
|
1207
|
+
...TerrainLoader,
|
|
1208
|
+
parse: loadTerrain
|
|
1209
|
+
};
|
|
1210
|
+
var QuantizedMeshLoader2 = {
|
|
1211
|
+
...QuantizedMeshLoader,
|
|
1212
|
+
parseSync: loadQuantizedMesh,
|
|
1213
|
+
parse: async (arrayBuffer, options) => loadQuantizedMesh(arrayBuffer, options)
|
|
1214
|
+
};
|
|
1215
|
+
|
|
1216
|
+
// src/workers/terrain-worker.js
|
|
1217
|
+
createLoaderWorker(TerrainLoader2);
|
|
1218
|
+
})();
|