@loaders.gl/obj 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/parse-obj.js +1 -1
- package/dist/lib/parse-obj.js.map +1 -1
- package/dist/obj-loader.js +1 -1
- package/dist/obj-worker.js +1134 -2
- package/package.json +6 -6
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/obj-worker.js.map +0 -1
package/dist/obj-worker.js
CHANGED
|
@@ -1,2 +1,1134 @@
|
|
|
1
|
-
!function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=19)}([function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(18);t.exports=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){function r(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}t.exports=function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){t.exports=r(13)},function(t,e){function r(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}t.exports=function(t){return function(){var e=this,n=arguments;return new Promise((function(o,i){var a=t.apply(e,n);function s(t){r(a,o,i,s,u,"next",t)}function u(t){r(a,o,i,s,u,"throw",t)}s(void 0)}))}},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){function r(e){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(t.exports=r=function(t){return typeof t},t.exports.default=t.exports,t.exports.__esModule=!0):(t.exports=r=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.default=t.exports,t.exports.__esModule=!0),r(e)}t.exports=r,t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(14),o=r(15),i=r(16),a=r(17);t.exports=function(t){return n(t)||o(t)||i(t)||a()},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){function r(e){return t.exports=r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},t.exports.default=t.exports,t.exports.__esModule=!0,r(e)}t.exports=r,t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(7).default,o=r(4);t.exports=function(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?o(t):e},t.exports.default=t.exports,t.exports.__esModule=!0},,function(t,e,r){var n=function(t){"use strict";var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=e&&e.prototype instanceof f?e:f,i=Object.create(o.prototype),a=new S(n||[]);return i._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return I()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=x(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(t,e,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)}}}(t,r,a),i}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l={};function f(){}function p(){}function h(){}var d={};d[o]=function(){return this};var v=Object.getPrototypeOf,y=v&&v(v(j([])));y&&y!==e&&r.call(y,o)&&(d=y);var m=h.prototype=f.prototype=Object.create(d);function g(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,s){var u=c(t[o],t,i);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,a,s)}),(function(t){n("throw",t,a,s)})):e.resolve(f).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,s)}))}s(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function w(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(w,this),this.reset(!0)}function j(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:I}}function I(){return{value:void 0,done:!0}}return p.prototype=m.constructor=h,h.constructor=p,p.displayName=s(h,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,s(t,a,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},g(b.prototype),b.prototype[i]=function(){return this},t.AsyncIterator=b,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new b(u(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},g(m),s(m,a,"Generator"),m[o]=function(){return this},m.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=j,S.prototype={constructor:S,reset:function(t){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(O),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(s&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;O(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=n}catch(t){Function("r","regeneratorRuntime = r")(n)}},function(t,e,r){var n=r(10);t.exports=function(t){if(Array.isArray(t))return n(t)},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.exports=function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){var n=r(10);t.exports=function(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){t.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.")},t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e){function r(e,n){return t.exports=r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},t.exports.default=t.exports,t.exports.__esModule=!0,r(e,n)}t.exports=r,t.exports.default=t.exports,t.exports.__esModule=!0},function(t,e,r){"use strict";r.r(e);var n=r(2),o=r.n(n),i=r(6),a=r.n(i),s=r(5),u=r.n(s),c=r(0),l=r.n(c),f=r(3),p=r.n(f),h=r(7),d=r.n(h);function v(t){return!!t&&(t instanceof ArrayBuffer||("undefined"!=typeof MessagePort&&t instanceof MessagePort||("undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap||"undefined"!=typeof OffscreenCanvas&&t instanceof OffscreenCanvas)))}var y=new Map,m=function(){function t(){l()(this,t)}return p()(t,null,[{key:"onmessage",set:function(t){self.onmessage=function(e){if(g(e)){var r=e.data,n=r.type,o=r.payload;t(n,o)}}}},{key:"addEventListener",value:function(t){var e=y.get(t);e||(e=function(e){if(g(e)){var r=e.data,n=r.type,o=r.payload;t(n,o)}}),self.addEventListener("message",e)}},{key:"removeEventListener",value:function(t){var e=y.get(t);y.delete(t),self.removeEventListener("message",e)}},{key:"postMessage",value:function(t,e){if(self){var r={source:"loaders.gl",type:t,payload:e},n=function t(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=arguments.length>2?arguments[2]:void 0,o=n||new Set;if(e){if(v(e))o.add(e);else if(v(e.buffer))o.add(e.buffer);else if(ArrayBuffer.isView(e));else if(r&&"object"===d()(e))for(var i in e)t(e[i],r,o)}else;return void 0===n?Array.from(o):[]}(e);self.postMessage(r,n)}}}]),t}();function g(t){var e=t.type,r=t.data;return"message"===e&&r&&"string"==typeof r.source&&r.source.startsWith("loaders.gl")}function b(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function x(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?b(Object(r),!0).forEach((function(e){o()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):b(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var w=0;function O(t,e){return new Promise((function(r,n){var o=w++;m.addEventListener((function t(e,i){if(i.id===o)switch(e){case"done":m.removeEventListener(t),r(i.result);break;case"error":m.removeEventListener(t),n(i.error)}}));var i={id:o,input:t,options:e};m.postMessage("process",i)}))}function S(t){return j.apply(this,arguments)}function j(){return(j=a()(u.a.mark((function t(e){var r,n,o,i,a,s,c;return u.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.loader,n=e.arrayBuffer,o=e.options,i=e.context,!r.parseSync&&!r.parse){t.next=6;break}a=n,s=r.parseSync||r.parse,t.next=13;break;case 6:if(!r.parseTextSync){t.next=12;break}c=new TextDecoder,a=c.decode(n),s=r.parseTextSync,t.next=13;break;case 12:throw new Error("Could not load data with ".concat(r.name," loader"));case 13:return o=x(x({},o),{},{modules:r&&r.options&&r.options.modules||{},worker:!1}),t.next=16,s(a,x({},o),i,r);case 16:return t.abrupt("return",t.sent);case 17:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function I(t){for(var e=1/0,r=1/0,n=1/0,o=-1/0,i=-1/0,a=-1/0,s=t.POSITION?t.POSITION.value:[],u=s&&s.length,c=0;c<u;c+=3){var l=s[c],f=s[c+1],p=s[c+2];e=l<e?l:e,r=f<r?f:r,n=p<n?p:n,o=l>o?l:o,i=f>i?f:i,a=p>a?p:a}return[[e,r,n],[o,i,a]]}function k(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return _(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return _(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}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 i,a=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}function _(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var M=/^[og]\s*(.+)?/,T=/^mtllib /,L=/^usemtl /,A=function(){function t(e){var r=e.index,n=e.name,o=void 0===n?"":n,i=e.mtllib,a=e.smooth,s=e.groupStart;l()(this,t),this.index=r,this.name=o,this.mtllib=i,this.smooth=a,this.groupStart=s,this.groupEnd=-1,this.groupCount=-1,this.inherited=!1}return p()(t,[{key:"clone",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.index;return new t({index:e,name:this.name,mtllib:this.mtllib,smooth:this.smooth,groupStart:0})}}]),t}(),E=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";l()(this,t),this.name=e,this.geometry={vertices:[],normals:[],colors:[],uvs:[]},this.materials=[],this.smooth=!0,this.fromDeclaration=null}return p()(t,[{key:"startMaterial",value:function(t,e){var r=this._finalize(!1);r&&(r.inherited||r.groupCount<=0)&&this.materials.splice(r.index,1);var n=new A({index:this.materials.length,name:t,mtllib:Array.isArray(e)&&e.length>0?e[e.length-1]:"",smooth:void 0!==r?r.smooth:this.smooth,groupStart:void 0!==r?r.groupEnd:0});return this.materials.push(n),n}},{key:"currentMaterial",value:function(){if(this.materials.length>0)return this.materials[this.materials.length-1]}},{key:"_finalize",value:function(t){var e=this.currentMaterial();if(e&&-1===e.groupEnd&&(e.groupEnd=this.geometry.vertices.length/3,e.groupCount=e.groupEnd-e.groupStart,e.inherited=!1),t&&this.materials.length>1)for(var r=this.materials.length-1;r>=0;r--)this.materials[r].groupCount<=0&&this.materials.splice(r,1);return t&&0===this.materials.length&&this.materials.push({name:"",smooth:this.smooth}),e}}]),t}(),F=function(){function t(){l()(this,t),this.objects=[],this.object=null,this.vertices=[],this.normals=[],this.colors=[],this.uvs=[],this.materialLibraries=[],this.startObject("",!1)}return p()(t,[{key:"startObject",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(this.object&&!this.object.fromDeclaration)return this.object.name=t,void(this.object.fromDeclaration=e);var r=this.object&&"function"==typeof this.object.currentMaterial?this.object.currentMaterial():void 0;if(this.object&&"function"==typeof this.object._finalize&&this.object._finalize(!0),this.object=new E(t),this.object.fromDeclaration=e,r&&r.name&&"function"==typeof r.clone){var n=r.clone(0);n.inherited=!0,this.object.materials.push(n)}this.objects.push(this.object)}},{key:"finalize",value:function(){this.object&&"function"==typeof this.object._finalize&&this.object._finalize(!0)}},{key:"parseVertexIndex",value:function(t,e){var r=parseInt(t);return 3*(r>=0?r-1:r+e/3)}},{key:"parseNormalIndex",value:function(t,e){var r=parseInt(t);return 3*(r>=0?r-1:r+e/3)}},{key:"parseUVIndex",value:function(t,e){var r=parseInt(t);return 2*(r>=0?r-1:r+e/2)}},{key:"addVertex",value:function(t,e,r){var n=this.vertices,o=this.object.geometry.vertices;o.push(n[t+0],n[t+1],n[t+2]),o.push(n[e+0],n[e+1],n[e+2]),o.push(n[r+0],n[r+1],n[r+2])}},{key:"addVertexPoint",value:function(t){var e=this.vertices;this.object.geometry.vertices.push(e[t+0],e[t+1],e[t+2])}},{key:"addVertexLine",value:function(t){var e=this.vertices;this.object.geometry.vertices.push(e[t+0],e[t+1],e[t+2])}},{key:"addNormal",value:function(t,e,r){var n=this.normals,o=this.object.geometry.normals;o.push(n[t+0],n[t+1],n[t+2]),o.push(n[e+0],n[e+1],n[e+2]),o.push(n[r+0],n[r+1],n[r+2])}},{key:"addColor",value:function(t,e,r){var n=this.colors,o=this.object.geometry.colors;o.push(n[t+0],n[t+1],n[t+2]),o.push(n[e+0],n[e+1],n[e+2]),o.push(n[r+0],n[r+1],n[r+2])}},{key:"addUV",value:function(t,e,r){var n=this.uvs,o=this.object.geometry.uvs;o.push(n[t+0],n[t+1]),o.push(n[e+0],n[e+1]),o.push(n[r+0],n[r+1])}},{key:"addUVLine",value:function(t){var e=this.uvs;this.object.geometry.uvs.push(e[t+0],e[t+1])}},{key:"addFace",value:function(t,e,r,n,o,i,a,s,u){var c=this.vertices.length,l=this.parseVertexIndex(t,c),f=this.parseVertexIndex(e,c),p=this.parseVertexIndex(r,c);if(this.addVertex(l,f,p),void 0!==n&&""!==n){var h=this.uvs.length;l=this.parseUVIndex(n,h),f=this.parseUVIndex(o,h),p=this.parseUVIndex(i,h),this.addUV(l,f,p)}if(void 0!==a&&""!==a){var d=this.normals.length;l=this.parseNormalIndex(a,d),f=a===s?l:this.parseNormalIndex(s,d),p=a===u?l:this.parseNormalIndex(u,d),this.addNormal(l,f,p)}this.colors.length>0&&this.addColor(l,f,p)}},{key:"addPointGeometry",value:function(t){this.object.geometry.type="Points";var e,r=this.vertices.length,n=k(t);try{for(n.s();!(e=n.n()).done;){var o=e.value;this.addVertexPoint(this.parseVertexIndex(o,r))}}catch(t){n.e(t)}finally{n.f()}}},{key:"addLineGeometry",value:function(t,e){this.object.geometry.type="Line";var r,n=this.vertices.length,o=this.uvs.length,i=k(t);try{for(i.s();!(r=i.n()).done;){var a=r.value;this.addVertexLine(this.parseVertexIndex(a,n))}}catch(t){i.e(t)}finally{i.f()}var s,u=k(e);try{for(u.s();!(s=u.n()).done;){var c=s.value;this.addUVLine(this.parseUVIndex(c,o))}}catch(t){u.e(t)}finally{u.f()}}}]),t}(),P=r(8),D=r.n(P);function N(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return U(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return U(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}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 i,a=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}function U(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var z=function(){function t(e,r){l()(this,t),o()(this,"fields",void 0),o()(this,"metadata",void 0),function(t,e){if(!t)throw new Error(e||"loader assertion failed.")}(Array.isArray(e)),function(t){var e,r={},n=N(t);try{for(n.s();!(e=n.n()).done;){var o=e.value;r[o.name]&&console.warn("Schema: duplicated field name",o.name,o),r[o.name]=!0}}catch(t){n.e(t)}finally{n.f()}}(e),this.fields=e,this.metadata=r||new Map}return p()(t,[{key:"compareTo",value:function(t){if(this.metadata!==t.metadata)return!1;if(this.fields.length!==t.fields.length)return!1;for(var e=0;e<this.fields.length;++e)if(!this.fields[e].compareTo(t.fields[e]))return!1;return!0}},{key:"select",value:function(){for(var e=Object.create(null),r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];for(var i=0,a=n;i<a.length;i++){var s=a[i];e[s]=!0}var u=this.fields.filter((function(t){return e[t.name]}));return new t(u,this.metadata)}},{key:"selectAt",value:function(){for(var e=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];var i=n.map((function(t){return e.fields[t]})).filter(Boolean);return new t(i,this.metadata)}},{key:"assign",value:function(e){var r,n=this.metadata;if(e instanceof t){var o=e;r=o.fields,n=B(B(new Map,this.metadata),o.metadata)}else r=e;var i,a=Object.create(null),s=N(this.fields);try{for(s.s();!(i=s.n()).done;){var u=i.value;a[u.name]=u}}catch(t){s.e(t)}finally{s.f()}var c,l=N(r);try{for(l.s();!(c=l.n()).done;){var f=c.value;a[f.name]=f}}catch(t){l.e(t)}finally{l.f()}return new t(Object.values(a),n)}}]),t}();function B(t,e){return new Map([].concat(D()(t||new Map),D()(e||new Map)))}var C,V,R,G,W=r(4),Y=r.n(W),$=r(1),J=r.n($),X=r(11),q=r.n(X),H=r(9),K=r.n(H);function Q(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=K()(t);if(e){var o=K()(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return q()(this,r)}}!function(t){t[t.NONE=0]="NONE",t[t.Null=1]="Null",t[t.Int=2]="Int",t[t.Float=3]="Float",t[t.Binary=4]="Binary",t[t.Utf8=5]="Utf8",t[t.Bool=6]="Bool",t[t.Decimal=7]="Decimal",t[t.Date=8]="Date",t[t.Time=9]="Time",t[t.Timestamp=10]="Timestamp",t[t.Interval=11]="Interval",t[t.List=12]="List",t[t.Struct=13]="Struct",t[t.Union=14]="Union",t[t.FixedSizeBinary=15]="FixedSizeBinary",t[t.FixedSizeList=16]="FixedSizeList",t[t.Map=17]="Map",t[t.Dictionary=-1]="Dictionary",t[t.Int8=-2]="Int8",t[t.Int16=-3]="Int16",t[t.Int32=-4]="Int32",t[t.Int64=-5]="Int64",t[t.Uint8=-6]="Uint8",t[t.Uint16=-7]="Uint16",t[t.Uint32=-8]="Uint32",t[t.Uint64=-9]="Uint64",t[t.Float16=-10]="Float16",t[t.Float32=-11]="Float32",t[t.Float64=-12]="Float64",t[t.DateDay=-13]="DateDay",t[t.DateMillisecond=-14]="DateMillisecond",t[t.TimestampSecond=-15]="TimestampSecond",t[t.TimestampMillisecond=-16]="TimestampMillisecond",t[t.TimestampMicrosecond=-17]="TimestampMicrosecond",t[t.TimestampNanosecond=-18]="TimestampNanosecond",t[t.TimeSecond=-19]="TimeSecond",t[t.TimeMillisecond=-20]="TimeMillisecond",t[t.TimeMicrosecond=-21]="TimeMicrosecond",t[t.TimeNanosecond=-22]="TimeNanosecond",t[t.DenseUnion=-23]="DenseUnion",t[t.SparseUnion=-24]="SparseUnion",t[t.IntervalDayTime=-25]="IntervalDayTime",t[t.IntervalYearMonth=-26]="IntervalYearMonth"}(C||(C={}));var Z=function(){function t(){l()(this,t)}return p()(t,[{key:"typeId",get:function(){return C.NONE}},{key:"compareTo",value:function(t){return this===t}}],[{key:"isNull",value:function(t){return t&&t.typeId===C.Null}},{key:"isInt",value:function(t){return t&&t.typeId===C.Int}},{key:"isFloat",value:function(t){return t&&t.typeId===C.Float}},{key:"isBinary",value:function(t){return t&&t.typeId===C.Binary}},{key:"isUtf8",value:function(t){return t&&t.typeId===C.Utf8}},{key:"isBool",value:function(t){return t&&t.typeId===C.Bool}},{key:"isDecimal",value:function(t){return t&&t.typeId===C.Decimal}},{key:"isDate",value:function(t){return t&&t.typeId===C.Date}},{key:"isTime",value:function(t){return t&&t.typeId===C.Time}},{key:"isTimestamp",value:function(t){return t&&t.typeId===C.Timestamp}},{key:"isInterval",value:function(t){return t&&t.typeId===C.Interval}},{key:"isList",value:function(t){return t&&t.typeId===C.List}},{key:"isStruct",value:function(t){return t&&t.typeId===C.Struct}},{key:"isUnion",value:function(t){return t&&t.typeId===C.Union}},{key:"isFixedSizeBinary",value:function(t){return t&&t.typeId===C.FixedSizeBinary}},{key:"isFixedSizeList",value:function(t){return t&&t.typeId===C.FixedSizeList}},{key:"isMap",value:function(t){return t&&t.typeId===C.Map}},{key:"isDictionary",value:function(t){return t&&t.typeId===C.Dictionary}}]),t}();V=Symbol.toStringTag;var tt=function(t){J()(r,t);var e=Q(r);function r(t,n){var i;return l()(this,r),i=e.call(this),o()(Y()(i),"isSigned",void 0),o()(Y()(i),"bitWidth",void 0),i.isSigned=t,i.bitWidth=n,i}return p()(r,[{key:"typeId",get:function(){return C.Int}},{key:V,get:function(){return"Int"}},{key:"toString",value:function(){return"".concat(this.isSigned?"I":"Ui","nt").concat(this.bitWidth)}}]),r}(Z),et=function(t){J()(r,t);var e=Q(r);function r(){return l()(this,r),e.call(this,!0,8)}return r}(tt),rt=function(t){J()(r,t);var e=Q(r);function r(){return l()(this,r),e.call(this,!0,16)}return r}(tt),nt=function(t){J()(r,t);var e=Q(r);function r(){return l()(this,r),e.call(this,!0,32)}return r}(tt),ot=function(t){J()(r,t);var e=Q(r);function r(){return l()(this,r),e.call(this,!1,8)}return r}(tt),it=function(t){J()(r,t);var e=Q(r);function r(){return l()(this,r),e.call(this,!1,16)}return r}(tt),at=function(t){J()(r,t);var e=Q(r);function r(){return l()(this,r),e.call(this,!1,32)}return r}(tt),st=32,ut=64;R=Symbol.toStringTag;var ct=function(t){J()(r,t);var e=Q(r);function r(t){var n;return l()(this,r),n=e.call(this),o()(Y()(n),"precision",void 0),n.precision=t,n}return p()(r,[{key:"typeId",get:function(){return C.Float}},{key:R,get:function(){return"Float"}},{key:"toString",value:function(){return"Float".concat(this.precision)}}]),r}(Z),lt=function(t){J()(r,t);var e=Q(r);function r(){return l()(this,r),e.call(this,st)}return r}(ct),ft=function(t){J()(r,t);var e=Q(r);function r(){return l()(this,r),e.call(this,ut)}return r}(ct);Symbol.toStringTag;Symbol.toStringTag;Symbol.toStringTag;Symbol.toStringTag;G=Symbol.toStringTag;var pt=function(t){J()(r,t);var e=Q(r);function r(t,n){var i;return l()(this,r),i=e.call(this),o()(Y()(i),"listSize",void 0),o()(Y()(i),"children",void 0),i.listSize=t,i.children=[n],i}return p()(r,[{key:"typeId",get:function(){return C.FixedSizeList}},{key:"valueType",get:function(){return this.children[0].type}},{key:"valueField",get:function(){return this.children[0]}},{key:G,get:function(){return"FixedSizeList"}},{key:"toString",value:function(){return"FixedSizeList[".concat(this.listSize,"]<").concat(this.valueType,">")}}]),r}(Z);Symbol.toStringTag;var ht=function(){function t(e,r){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:new Map;l()(this,t),o()(this,"name",void 0),o()(this,"type",void 0),o()(this,"nullable",void 0),o()(this,"metadata",void 0),this.name=e,this.type=r,this.nullable=n,this.metadata=i}return p()(t,[{key:"typeId",get:function(){return this.type&&this.type.typeId}},{key:"clone",value:function(){return new t(this.name,this.type,this.nullable,this.metadata)}},{key:"compareTo",value:function(t){return this.name===t.name&&this.type===t.type&&this.nullable===t.nullable&&this.metadata===t.metadata}},{key:"toString",value:function(){return"".concat(this.type).concat(this.nullable?", nullable":"").concat(this.metadata?", metadata: ".concat(this.metadata):"")}}]),t}();function dt(t,e){var r=new Map;for(var n in e)"value"!==n&&r.set(n,JSON.stringify(e[n]));var o=function(t){switch(t.constructor){case Int8Array:return new et;case Uint8Array:return new ot;case Int16Array:return new rt;case Uint16Array:return new it;case Int32Array:return new nt;case Uint32Array:return new at;case Float32Array:return new lt;case Float64Array:return new ft;default:throw new Error("array type not supported")}}(e.value),i=!("size"in e)||1===e.size;return new ht(t,i?o:new pt(e.size,new ht("value",o)),!1,r)}function vt(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return yt(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return yt(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}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 i,a=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}function yt(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function mt(t,e){var r=function(t){var e=new F;-1!==t.indexOf("\r\n")&&(t=t.replace(/\r\n/g,"\n")),-1!==t.indexOf("\\\n")&&(t=t.replace(/\\\n/g,""));for(var r=t.split("\n"),n="",o="",i=[],a="function"==typeof"".trimLeft,s=0,u=r.length;s<u;s++)if(n=r[s],0!==(n=a?n.trimLeft():n.trim()).length&&"#"!==(o=n.charAt(0)))if("v"===o){var c=n.split(/\s+/);switch(c[0]){case"v":e.vertices.push(parseFloat(c[1]),parseFloat(c[2]),parseFloat(c[3])),8===c.length&&e.colors.push(parseFloat(c[4]),parseFloat(c[5]),parseFloat(c[6]));break;case"vn":e.normals.push(parseFloat(c[1]),parseFloat(c[2]),parseFloat(c[3]));break;case"vt":e.uvs.push(parseFloat(c[1]),parseFloat(c[2]))}}else if("f"===o){for(var l=n.substr(1).trim().split(/\s+/),f=[],p=0,h=l.length;p<h;p++){var d=l[p];if(d.length>0){var v=d.split("/");f.push(v)}}for(var y=f[0],m=1,g=f.length-1;m<g;m++){var b=f[m],x=f[m+1];e.addFace(y[0],b[0],x[0],y[1],b[1],x[1],y[2],b[2],x[2])}}else if("l"===o){var w=n.substring(1).trim().split(" "),O=void 0,S=[];if(-1===n.indexOf("/"))O=w;else{O=[];for(var j=0,I=w.length;j<I;j++){var _=w[j].split("/");""!==_[0]&&O.push(_[0]),""!==_[1]&&S.push(_[1])}}e.addLineGeometry(O,S)}else if("p"===o){var A=n.substr(1).trim().split(" ");e.addPointGeometry(A)}else if(null!==(i=M.exec(n))){var E=(" "+i[0].substr(1).trim()).substr(1);e.startObject(E)}else if(L.test(n))e.object.startMaterial(n.substring(7).trim(),e.materialLibraries);else if(T.test(n))e.materialLibraries.push(n.substring(7).trim());else{if("s"!==o){if("\0"===n)continue;throw new Error('Unexpected line: "'.concat(n,'"'))}if((i=n.split(" ")).length>1){var P=i[1].trim().toLowerCase();e.object.smooth="0"!==P&&"off"!==P}else e.object.smooth=!0;var D=e.object.currentMaterial();D&&(D.smooth=e.object.smooth)}e.finalize();var N,U=[],z=[],B=k(e.objects);try{for(B.s();!(N=B.n()).done;){var C=N.value,V=C.geometry;if(0!==V.vertices.length){var R={header:{vertexCount:V.vertices.length/3},attributes:{}};switch(V.type){case"Points":R.mode=0;break;case"Line":R.mode=1;break;default:R.mode=4}R.attributes.POSITION={value:new Float32Array(V.vertices),size:3},V.normals.length>0&&(R.attributes.NORMAL={value:new Float32Array(V.normals),size:3}),V.colors.length>0&&(R.attributes.COLOR_0={value:new Float32Array(V.colors),size:3}),V.uvs.length>0&&(R.attributes.TEXCOORD_0={value:new Float32Array(V.uvs),size:2}),R.materials=[];var G,W=k(C.materials);try{for(W.s();!(G=W.n()).done;){var Y=G.value,$={name:Y.name,flatShading:!Y.smooth};R.materials.push($),z.push($)}}catch(t){W.e(t)}finally{W.f()}R.name=C.name,U.push(R)}}}catch(t){B.e(t)}finally{B.f()}return{meshes:U,materials:z}}(t).meshes,n=r.reduce((function(t,e){return t+e.header.vertexCount}),0),o=function(t,e){var r,n,o,i,a=new Float32Array(3*e),s=0,u=vt(t);try{for(u.s();!(i=u.n()).done;){var c=i.value.attributes,l=c.POSITION,f=c.NORMAL,p=c.COLOR_0,h=c.TEXCOORD_0;a.set(l.value,3*s),f&&(r=r||new Float32Array(3*e)).set(f.value,3*s),p&&(n=n||new Float32Array(3*e)).set(p.value,3*s),h&&(o=o||new Float32Array(2*e)).set(h.value,2*s),s+=l.value.length/3}}catch(t){u.e(t)}finally{u.f()}var d={};d.POSITION={value:a,size:3},r&&(d.NORMAL={value:r,size:3});n&&(d.COLOR_0={value:n,size:3});o&&(d.TEXCOORD_0={value:o,size:2});return d}(r,n),i={vertexCount:n,boundingBox:I(o)};return{loaderData:{header:{}},schema:function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};for(var n in r)e=e||new Map,"value"!==n&&e.set(n,JSON.stringify(r[n]));var o=[];for(var i in t){var a=t[i],s=dt(i,a);o.push(s)}return new z(o,e)}(o,{mode:4,boundingBox:i.boundingBox}),header:i,mode:4,attributes:o}}var gt={name:"OBJ",id:"obj",module:"obj",version:"3.1.0-alpha.3",worker:!0,extensions:["obj"],mimeTypes:["text/plain"],testText:function(t){return"v"===t[0]},options:{obj:{}}};function bt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function xt(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?bt(Object(r),!0).forEach((function(e){o()(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):bt(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var wt,Ot,St=xt(xt({},gt),{},{parse:(wt=a()(u.a.mark((function t(e,r){return u.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",mt((new TextDecoder).decode(e)));case 1:case"end":return t.stop()}}),t)}))),function(t,e){return wt.apply(this,arguments)}),parseTextSync:mt});Ot=St,"undefined"!=typeof self&&(m.onmessage=function(){var t=a()(u.a.mark((function t(e,r){var n,o,i,a,s;return u.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:t.t0=e,t.next="process"===t.t0?3:16;break;case 3:return t.prev=3,n=r.input,o=r.options,i=void 0===o?{}:o,t.next=7,S({loader:Ot,arrayBuffer:n,options:i,context:{parse:O}});case 7:a=t.sent,m.postMessage("done",{result:a}),t.next=15;break;case 11:t.prev=11,t.t1=t.catch(3),s=t.t1 instanceof Error?t.t1.message:"",m.postMessage("error",{error:s});case 15:return t.abrupt("break",16);case 16:case"end":return t.stop()}}),t,null,[[3,11]])})));return function(e,r){return t.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
|
+
// ../schema/src/category/mesh/mesh-utils.ts
|
|
155
|
+
function getMeshBoundingBox(attributes) {
|
|
156
|
+
let minX = Infinity;
|
|
157
|
+
let minY = Infinity;
|
|
158
|
+
let minZ = Infinity;
|
|
159
|
+
let maxX = -Infinity;
|
|
160
|
+
let maxY = -Infinity;
|
|
161
|
+
let maxZ = -Infinity;
|
|
162
|
+
const positions = attributes.POSITION ? attributes.POSITION.value : [];
|
|
163
|
+
const len = positions && positions.length;
|
|
164
|
+
for (let i = 0; i < len; i += 3) {
|
|
165
|
+
const x = positions[i];
|
|
166
|
+
const y = positions[i + 1];
|
|
167
|
+
const z = positions[i + 2];
|
|
168
|
+
minX = x < minX ? x : minX;
|
|
169
|
+
minY = y < minY ? y : minY;
|
|
170
|
+
minZ = z < minZ ? z : minZ;
|
|
171
|
+
maxX = x > maxX ? x : maxX;
|
|
172
|
+
maxY = y > maxY ? y : maxY;
|
|
173
|
+
maxZ = z > maxZ ? z : maxZ;
|
|
174
|
+
}
|
|
175
|
+
return [
|
|
176
|
+
[minX, minY, minZ],
|
|
177
|
+
[maxX, maxY, maxZ]
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ../schema/src/lib/utils/assert.ts
|
|
182
|
+
function assert(condition, message) {
|
|
183
|
+
if (!condition) {
|
|
184
|
+
throw new Error(message || "loader assertion failed.");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// ../schema/src/lib/schema/impl/schema.ts
|
|
189
|
+
var Schema = class {
|
|
190
|
+
constructor(fields, metadata) {
|
|
191
|
+
assert(Array.isArray(fields));
|
|
192
|
+
checkNames(fields);
|
|
193
|
+
this.fields = fields;
|
|
194
|
+
this.metadata = metadata || new Map();
|
|
195
|
+
}
|
|
196
|
+
compareTo(other) {
|
|
197
|
+
if (this.metadata !== other.metadata) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
if (this.fields.length !== other.fields.length) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
for (let i = 0; i < this.fields.length; ++i) {
|
|
204
|
+
if (!this.fields[i].compareTo(other.fields[i])) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
select(...columnNames) {
|
|
211
|
+
const nameMap = Object.create(null);
|
|
212
|
+
for (const name of columnNames) {
|
|
213
|
+
nameMap[name] = true;
|
|
214
|
+
}
|
|
215
|
+
const selectedFields = this.fields.filter((field) => nameMap[field.name]);
|
|
216
|
+
return new Schema(selectedFields, this.metadata);
|
|
217
|
+
}
|
|
218
|
+
selectAt(...columnIndices) {
|
|
219
|
+
const selectedFields = columnIndices.map((index) => this.fields[index]).filter(Boolean);
|
|
220
|
+
return new Schema(selectedFields, this.metadata);
|
|
221
|
+
}
|
|
222
|
+
assign(schemaOrFields) {
|
|
223
|
+
let fields;
|
|
224
|
+
let metadata = this.metadata;
|
|
225
|
+
if (schemaOrFields instanceof Schema) {
|
|
226
|
+
const otherSchema = schemaOrFields;
|
|
227
|
+
fields = otherSchema.fields;
|
|
228
|
+
metadata = mergeMaps(mergeMaps(new Map(), this.metadata), otherSchema.metadata);
|
|
229
|
+
} else {
|
|
230
|
+
fields = schemaOrFields;
|
|
231
|
+
}
|
|
232
|
+
const fieldMap = Object.create(null);
|
|
233
|
+
for (const field of this.fields) {
|
|
234
|
+
fieldMap[field.name] = field;
|
|
235
|
+
}
|
|
236
|
+
for (const field of fields) {
|
|
237
|
+
fieldMap[field.name] = field;
|
|
238
|
+
}
|
|
239
|
+
const mergedFields = Object.values(fieldMap);
|
|
240
|
+
return new Schema(mergedFields, metadata);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
function checkNames(fields) {
|
|
244
|
+
const usedNames = {};
|
|
245
|
+
for (const field of fields) {
|
|
246
|
+
if (usedNames[field.name]) {
|
|
247
|
+
console.warn("Schema: duplicated field name", field.name, field);
|
|
248
|
+
}
|
|
249
|
+
usedNames[field.name] = true;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function mergeMaps(m1, m2) {
|
|
253
|
+
return new Map([...m1 || new Map(), ...m2 || new Map()]);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// ../schema/src/lib/schema/impl/field.ts
|
|
257
|
+
var Field = class {
|
|
258
|
+
constructor(name, type, nullable = false, metadata = new Map()) {
|
|
259
|
+
this.name = name;
|
|
260
|
+
this.type = type;
|
|
261
|
+
this.nullable = nullable;
|
|
262
|
+
this.metadata = metadata;
|
|
263
|
+
}
|
|
264
|
+
get typeId() {
|
|
265
|
+
return this.type && this.type.typeId;
|
|
266
|
+
}
|
|
267
|
+
clone() {
|
|
268
|
+
return new Field(this.name, this.type, this.nullable, this.metadata);
|
|
269
|
+
}
|
|
270
|
+
compareTo(other) {
|
|
271
|
+
return this.name === other.name && this.type === other.type && this.nullable === other.nullable && this.metadata === other.metadata;
|
|
272
|
+
}
|
|
273
|
+
toString() {
|
|
274
|
+
return `${this.type}${this.nullable ? ", nullable" : ""}${this.metadata ? `, metadata: ${this.metadata}` : ""}`;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// ../schema/src/lib/schema/impl/enum.ts
|
|
279
|
+
var Type;
|
|
280
|
+
(function(Type2) {
|
|
281
|
+
Type2[Type2["NONE"] = 0] = "NONE";
|
|
282
|
+
Type2[Type2["Null"] = 1] = "Null";
|
|
283
|
+
Type2[Type2["Int"] = 2] = "Int";
|
|
284
|
+
Type2[Type2["Float"] = 3] = "Float";
|
|
285
|
+
Type2[Type2["Binary"] = 4] = "Binary";
|
|
286
|
+
Type2[Type2["Utf8"] = 5] = "Utf8";
|
|
287
|
+
Type2[Type2["Bool"] = 6] = "Bool";
|
|
288
|
+
Type2[Type2["Decimal"] = 7] = "Decimal";
|
|
289
|
+
Type2[Type2["Date"] = 8] = "Date";
|
|
290
|
+
Type2[Type2["Time"] = 9] = "Time";
|
|
291
|
+
Type2[Type2["Timestamp"] = 10] = "Timestamp";
|
|
292
|
+
Type2[Type2["Interval"] = 11] = "Interval";
|
|
293
|
+
Type2[Type2["List"] = 12] = "List";
|
|
294
|
+
Type2[Type2["Struct"] = 13] = "Struct";
|
|
295
|
+
Type2[Type2["Union"] = 14] = "Union";
|
|
296
|
+
Type2[Type2["FixedSizeBinary"] = 15] = "FixedSizeBinary";
|
|
297
|
+
Type2[Type2["FixedSizeList"] = 16] = "FixedSizeList";
|
|
298
|
+
Type2[Type2["Map"] = 17] = "Map";
|
|
299
|
+
Type2[Type2["Dictionary"] = -1] = "Dictionary";
|
|
300
|
+
Type2[Type2["Int8"] = -2] = "Int8";
|
|
301
|
+
Type2[Type2["Int16"] = -3] = "Int16";
|
|
302
|
+
Type2[Type2["Int32"] = -4] = "Int32";
|
|
303
|
+
Type2[Type2["Int64"] = -5] = "Int64";
|
|
304
|
+
Type2[Type2["Uint8"] = -6] = "Uint8";
|
|
305
|
+
Type2[Type2["Uint16"] = -7] = "Uint16";
|
|
306
|
+
Type2[Type2["Uint32"] = -8] = "Uint32";
|
|
307
|
+
Type2[Type2["Uint64"] = -9] = "Uint64";
|
|
308
|
+
Type2[Type2["Float16"] = -10] = "Float16";
|
|
309
|
+
Type2[Type2["Float32"] = -11] = "Float32";
|
|
310
|
+
Type2[Type2["Float64"] = -12] = "Float64";
|
|
311
|
+
Type2[Type2["DateDay"] = -13] = "DateDay";
|
|
312
|
+
Type2[Type2["DateMillisecond"] = -14] = "DateMillisecond";
|
|
313
|
+
Type2[Type2["TimestampSecond"] = -15] = "TimestampSecond";
|
|
314
|
+
Type2[Type2["TimestampMillisecond"] = -16] = "TimestampMillisecond";
|
|
315
|
+
Type2[Type2["TimestampMicrosecond"] = -17] = "TimestampMicrosecond";
|
|
316
|
+
Type2[Type2["TimestampNanosecond"] = -18] = "TimestampNanosecond";
|
|
317
|
+
Type2[Type2["TimeSecond"] = -19] = "TimeSecond";
|
|
318
|
+
Type2[Type2["TimeMillisecond"] = -20] = "TimeMillisecond";
|
|
319
|
+
Type2[Type2["TimeMicrosecond"] = -21] = "TimeMicrosecond";
|
|
320
|
+
Type2[Type2["TimeNanosecond"] = -22] = "TimeNanosecond";
|
|
321
|
+
Type2[Type2["DenseUnion"] = -23] = "DenseUnion";
|
|
322
|
+
Type2[Type2["SparseUnion"] = -24] = "SparseUnion";
|
|
323
|
+
Type2[Type2["IntervalDayTime"] = -25] = "IntervalDayTime";
|
|
324
|
+
Type2[Type2["IntervalYearMonth"] = -26] = "IntervalYearMonth";
|
|
325
|
+
})(Type || (Type = {}));
|
|
326
|
+
|
|
327
|
+
// ../schema/src/lib/schema/impl/type.ts
|
|
328
|
+
var DataType = class {
|
|
329
|
+
static isNull(x) {
|
|
330
|
+
return x && x.typeId === Type.Null;
|
|
331
|
+
}
|
|
332
|
+
static isInt(x) {
|
|
333
|
+
return x && x.typeId === Type.Int;
|
|
334
|
+
}
|
|
335
|
+
static isFloat(x) {
|
|
336
|
+
return x && x.typeId === Type.Float;
|
|
337
|
+
}
|
|
338
|
+
static isBinary(x) {
|
|
339
|
+
return x && x.typeId === Type.Binary;
|
|
340
|
+
}
|
|
341
|
+
static isUtf8(x) {
|
|
342
|
+
return x && x.typeId === Type.Utf8;
|
|
343
|
+
}
|
|
344
|
+
static isBool(x) {
|
|
345
|
+
return x && x.typeId === Type.Bool;
|
|
346
|
+
}
|
|
347
|
+
static isDecimal(x) {
|
|
348
|
+
return x && x.typeId === Type.Decimal;
|
|
349
|
+
}
|
|
350
|
+
static isDate(x) {
|
|
351
|
+
return x && x.typeId === Type.Date;
|
|
352
|
+
}
|
|
353
|
+
static isTime(x) {
|
|
354
|
+
return x && x.typeId === Type.Time;
|
|
355
|
+
}
|
|
356
|
+
static isTimestamp(x) {
|
|
357
|
+
return x && x.typeId === Type.Timestamp;
|
|
358
|
+
}
|
|
359
|
+
static isInterval(x) {
|
|
360
|
+
return x && x.typeId === Type.Interval;
|
|
361
|
+
}
|
|
362
|
+
static isList(x) {
|
|
363
|
+
return x && x.typeId === Type.List;
|
|
364
|
+
}
|
|
365
|
+
static isStruct(x) {
|
|
366
|
+
return x && x.typeId === Type.Struct;
|
|
367
|
+
}
|
|
368
|
+
static isUnion(x) {
|
|
369
|
+
return x && x.typeId === Type.Union;
|
|
370
|
+
}
|
|
371
|
+
static isFixedSizeBinary(x) {
|
|
372
|
+
return x && x.typeId === Type.FixedSizeBinary;
|
|
373
|
+
}
|
|
374
|
+
static isFixedSizeList(x) {
|
|
375
|
+
return x && x.typeId === Type.FixedSizeList;
|
|
376
|
+
}
|
|
377
|
+
static isMap(x) {
|
|
378
|
+
return x && x.typeId === Type.Map;
|
|
379
|
+
}
|
|
380
|
+
static isDictionary(x) {
|
|
381
|
+
return x && x.typeId === Type.Dictionary;
|
|
382
|
+
}
|
|
383
|
+
get typeId() {
|
|
384
|
+
return Type.NONE;
|
|
385
|
+
}
|
|
386
|
+
compareTo(other) {
|
|
387
|
+
return this === other;
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
var Null = class extends DataType {
|
|
391
|
+
get typeId() {
|
|
392
|
+
return Type.Null;
|
|
393
|
+
}
|
|
394
|
+
get [Symbol.toStringTag]() {
|
|
395
|
+
return "Null";
|
|
396
|
+
}
|
|
397
|
+
toString() {
|
|
398
|
+
return "Null";
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
var Bool = class extends DataType {
|
|
402
|
+
get typeId() {
|
|
403
|
+
return Type.Bool;
|
|
404
|
+
}
|
|
405
|
+
get [Symbol.toStringTag]() {
|
|
406
|
+
return "Bool";
|
|
407
|
+
}
|
|
408
|
+
toString() {
|
|
409
|
+
return "Bool";
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
var Int = class extends DataType {
|
|
413
|
+
constructor(isSigned, bitWidth) {
|
|
414
|
+
super();
|
|
415
|
+
this.isSigned = isSigned;
|
|
416
|
+
this.bitWidth = bitWidth;
|
|
417
|
+
}
|
|
418
|
+
get typeId() {
|
|
419
|
+
return Type.Int;
|
|
420
|
+
}
|
|
421
|
+
get [Symbol.toStringTag]() {
|
|
422
|
+
return "Int";
|
|
423
|
+
}
|
|
424
|
+
toString() {
|
|
425
|
+
return `${this.isSigned ? "I" : "Ui"}nt${this.bitWidth}`;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
var Int8 = class extends Int {
|
|
429
|
+
constructor() {
|
|
430
|
+
super(true, 8);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
var Int16 = class extends Int {
|
|
434
|
+
constructor() {
|
|
435
|
+
super(true, 16);
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
var Int32 = class extends Int {
|
|
439
|
+
constructor() {
|
|
440
|
+
super(true, 32);
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
var Uint8 = class extends Int {
|
|
444
|
+
constructor() {
|
|
445
|
+
super(false, 8);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
var Uint16 = class extends Int {
|
|
449
|
+
constructor() {
|
|
450
|
+
super(false, 16);
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
var Uint32 = class extends Int {
|
|
454
|
+
constructor() {
|
|
455
|
+
super(false, 32);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
var Precision = {
|
|
459
|
+
HALF: 16,
|
|
460
|
+
SINGLE: 32,
|
|
461
|
+
DOUBLE: 64
|
|
462
|
+
};
|
|
463
|
+
var Float = class extends DataType {
|
|
464
|
+
constructor(precision) {
|
|
465
|
+
super();
|
|
466
|
+
this.precision = precision;
|
|
467
|
+
}
|
|
468
|
+
get typeId() {
|
|
469
|
+
return Type.Float;
|
|
470
|
+
}
|
|
471
|
+
get [Symbol.toStringTag]() {
|
|
472
|
+
return "Float";
|
|
473
|
+
}
|
|
474
|
+
toString() {
|
|
475
|
+
return `Float${this.precision}`;
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
var Float32 = class extends Float {
|
|
479
|
+
constructor() {
|
|
480
|
+
super(Precision.SINGLE);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
var Float64 = class extends Float {
|
|
484
|
+
constructor() {
|
|
485
|
+
super(Precision.DOUBLE);
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
var Binary = class extends DataType {
|
|
489
|
+
constructor() {
|
|
490
|
+
super();
|
|
491
|
+
}
|
|
492
|
+
get typeId() {
|
|
493
|
+
return Type.Binary;
|
|
494
|
+
}
|
|
495
|
+
toString() {
|
|
496
|
+
return "Binary";
|
|
497
|
+
}
|
|
498
|
+
get [Symbol.toStringTag]() {
|
|
499
|
+
return "Binary";
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
var Utf8 = class extends DataType {
|
|
503
|
+
get typeId() {
|
|
504
|
+
return Type.Utf8;
|
|
505
|
+
}
|
|
506
|
+
get [Symbol.toStringTag]() {
|
|
507
|
+
return "Utf8";
|
|
508
|
+
}
|
|
509
|
+
toString() {
|
|
510
|
+
return "Utf8";
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
var DateUnit = {
|
|
514
|
+
DAY: 0,
|
|
515
|
+
MILLISECOND: 1
|
|
516
|
+
};
|
|
517
|
+
var Date = class extends DataType {
|
|
518
|
+
constructor(unit) {
|
|
519
|
+
super();
|
|
520
|
+
this.unit = unit;
|
|
521
|
+
}
|
|
522
|
+
get typeId() {
|
|
523
|
+
return Type.Date;
|
|
524
|
+
}
|
|
525
|
+
get [Symbol.toStringTag]() {
|
|
526
|
+
return "Date";
|
|
527
|
+
}
|
|
528
|
+
toString() {
|
|
529
|
+
return `Date${(this.unit + 1) * 32}<${DateUnit[this.unit]}>`;
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
var TimeUnit = {
|
|
533
|
+
SECOND: 1,
|
|
534
|
+
MILLISECOND: 1e3,
|
|
535
|
+
MICROSECOND: 1e6,
|
|
536
|
+
NANOSECOND: 1e9
|
|
537
|
+
};
|
|
538
|
+
var Time = class extends DataType {
|
|
539
|
+
constructor(unit, bitWidth) {
|
|
540
|
+
super();
|
|
541
|
+
this.unit = unit;
|
|
542
|
+
this.bitWidth = bitWidth;
|
|
543
|
+
}
|
|
544
|
+
get typeId() {
|
|
545
|
+
return Type.Time;
|
|
546
|
+
}
|
|
547
|
+
toString() {
|
|
548
|
+
return `Time${this.bitWidth}<${TimeUnit[this.unit]}>`;
|
|
549
|
+
}
|
|
550
|
+
get [Symbol.toStringTag]() {
|
|
551
|
+
return "Time";
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
var Timestamp = class extends DataType {
|
|
555
|
+
constructor(unit, timezone = null) {
|
|
556
|
+
super();
|
|
557
|
+
this.unit = unit;
|
|
558
|
+
this.timezone = timezone;
|
|
559
|
+
}
|
|
560
|
+
get typeId() {
|
|
561
|
+
return Type.Timestamp;
|
|
562
|
+
}
|
|
563
|
+
get [Symbol.toStringTag]() {
|
|
564
|
+
return "Timestamp";
|
|
565
|
+
}
|
|
566
|
+
toString() {
|
|
567
|
+
return `Timestamp<${TimeUnit[this.unit]}${this.timezone ? `, ${this.timezone}` : ""}>`;
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
var IntervalUnit = {
|
|
571
|
+
DAY_TIME: 0,
|
|
572
|
+
YEAR_MONTH: 1
|
|
573
|
+
};
|
|
574
|
+
var Interval = class extends DataType {
|
|
575
|
+
constructor(unit) {
|
|
576
|
+
super();
|
|
577
|
+
this.unit = unit;
|
|
578
|
+
}
|
|
579
|
+
get typeId() {
|
|
580
|
+
return Type.Interval;
|
|
581
|
+
}
|
|
582
|
+
get [Symbol.toStringTag]() {
|
|
583
|
+
return "Interval";
|
|
584
|
+
}
|
|
585
|
+
toString() {
|
|
586
|
+
return `Interval<${IntervalUnit[this.unit]}>`;
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
var FixedSizeList = class extends DataType {
|
|
590
|
+
constructor(listSize, child) {
|
|
591
|
+
super();
|
|
592
|
+
this.listSize = listSize;
|
|
593
|
+
this.children = [child];
|
|
594
|
+
}
|
|
595
|
+
get typeId() {
|
|
596
|
+
return Type.FixedSizeList;
|
|
597
|
+
}
|
|
598
|
+
get valueType() {
|
|
599
|
+
return this.children[0].type;
|
|
600
|
+
}
|
|
601
|
+
get valueField() {
|
|
602
|
+
return this.children[0];
|
|
603
|
+
}
|
|
604
|
+
get [Symbol.toStringTag]() {
|
|
605
|
+
return "FixedSizeList";
|
|
606
|
+
}
|
|
607
|
+
toString() {
|
|
608
|
+
return `FixedSizeList[${this.listSize}]<${this.valueType}>`;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
var Struct = class extends DataType {
|
|
612
|
+
constructor(children) {
|
|
613
|
+
super();
|
|
614
|
+
this.children = children;
|
|
615
|
+
}
|
|
616
|
+
get typeId() {
|
|
617
|
+
return Type.Struct;
|
|
618
|
+
}
|
|
619
|
+
toString() {
|
|
620
|
+
return `Struct<{${this.children.map((f) => `${f.name}:${f.type}`).join(", ")}}>`;
|
|
621
|
+
}
|
|
622
|
+
get [Symbol.toStringTag]() {
|
|
623
|
+
return "Struct";
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
// ../schema/src/lib/arrow/arrow-like-type-utils.ts
|
|
628
|
+
function getArrowTypeFromTypedArray(array) {
|
|
629
|
+
switch (array.constructor) {
|
|
630
|
+
case Int8Array:
|
|
631
|
+
return new Int8();
|
|
632
|
+
case Uint8Array:
|
|
633
|
+
return new Uint8();
|
|
634
|
+
case Int16Array:
|
|
635
|
+
return new Int16();
|
|
636
|
+
case Uint16Array:
|
|
637
|
+
return new Uint16();
|
|
638
|
+
case Int32Array:
|
|
639
|
+
return new Int32();
|
|
640
|
+
case Uint32Array:
|
|
641
|
+
return new Uint32();
|
|
642
|
+
case Float32Array:
|
|
643
|
+
return new Float32();
|
|
644
|
+
case Float64Array:
|
|
645
|
+
return new Float64();
|
|
646
|
+
default:
|
|
647
|
+
throw new Error("array type not supported");
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// src/lib/parse-obj.ts
|
|
652
|
+
var OBJECT_RE = /^[og]\s*(.+)?/;
|
|
653
|
+
var MATERIAL_RE = /^mtllib /;
|
|
654
|
+
var MATERIAL_USE_RE = /^usemtl /;
|
|
655
|
+
var MeshMaterial = class {
|
|
656
|
+
constructor({ index, name = "", mtllib, smooth, groupStart }) {
|
|
657
|
+
this.index = index;
|
|
658
|
+
this.name = name;
|
|
659
|
+
this.mtllib = mtllib;
|
|
660
|
+
this.smooth = smooth;
|
|
661
|
+
this.groupStart = groupStart;
|
|
662
|
+
this.groupEnd = -1;
|
|
663
|
+
this.groupCount = -1;
|
|
664
|
+
this.inherited = false;
|
|
665
|
+
}
|
|
666
|
+
clone(index = this.index) {
|
|
667
|
+
return new MeshMaterial({
|
|
668
|
+
index,
|
|
669
|
+
name: this.name,
|
|
670
|
+
mtllib: this.mtllib,
|
|
671
|
+
smooth: this.smooth,
|
|
672
|
+
groupStart: 0
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
var MeshObject = class {
|
|
677
|
+
constructor(name = "") {
|
|
678
|
+
this.name = name;
|
|
679
|
+
this.geometry = {
|
|
680
|
+
vertices: [],
|
|
681
|
+
normals: [],
|
|
682
|
+
colors: [],
|
|
683
|
+
uvs: []
|
|
684
|
+
};
|
|
685
|
+
this.materials = [];
|
|
686
|
+
this.smooth = true;
|
|
687
|
+
this.fromDeclaration = null;
|
|
688
|
+
}
|
|
689
|
+
startMaterial(name, libraries) {
|
|
690
|
+
const previous = this._finalize(false);
|
|
691
|
+
if (previous && (previous.inherited || previous.groupCount <= 0)) {
|
|
692
|
+
this.materials.splice(previous.index, 1);
|
|
693
|
+
}
|
|
694
|
+
const material = new MeshMaterial({
|
|
695
|
+
index: this.materials.length,
|
|
696
|
+
name,
|
|
697
|
+
mtllib: Array.isArray(libraries) && libraries.length > 0 ? libraries[libraries.length - 1] : "",
|
|
698
|
+
smooth: previous !== void 0 ? previous.smooth : this.smooth,
|
|
699
|
+
groupStart: previous !== void 0 ? previous.groupEnd : 0
|
|
700
|
+
});
|
|
701
|
+
this.materials.push(material);
|
|
702
|
+
return material;
|
|
703
|
+
}
|
|
704
|
+
currentMaterial() {
|
|
705
|
+
if (this.materials.length > 0) {
|
|
706
|
+
return this.materials[this.materials.length - 1];
|
|
707
|
+
}
|
|
708
|
+
return void 0;
|
|
709
|
+
}
|
|
710
|
+
_finalize(end) {
|
|
711
|
+
const lastMultiMaterial = this.currentMaterial();
|
|
712
|
+
if (lastMultiMaterial && lastMultiMaterial.groupEnd === -1) {
|
|
713
|
+
lastMultiMaterial.groupEnd = this.geometry.vertices.length / 3;
|
|
714
|
+
lastMultiMaterial.groupCount = lastMultiMaterial.groupEnd - lastMultiMaterial.groupStart;
|
|
715
|
+
lastMultiMaterial.inherited = false;
|
|
716
|
+
}
|
|
717
|
+
if (end && this.materials.length > 1) {
|
|
718
|
+
for (let mi = this.materials.length - 1; mi >= 0; mi--) {
|
|
719
|
+
if (this.materials[mi].groupCount <= 0) {
|
|
720
|
+
this.materials.splice(mi, 1);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
if (end && this.materials.length === 0) {
|
|
725
|
+
this.materials.push({
|
|
726
|
+
name: "",
|
|
727
|
+
smooth: this.smooth
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
return lastMultiMaterial;
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
var ParserState = class {
|
|
734
|
+
constructor() {
|
|
735
|
+
this.objects = [];
|
|
736
|
+
this.object = null;
|
|
737
|
+
this.vertices = [];
|
|
738
|
+
this.normals = [];
|
|
739
|
+
this.colors = [];
|
|
740
|
+
this.uvs = [];
|
|
741
|
+
this.materialLibraries = [];
|
|
742
|
+
this.startObject("", false);
|
|
743
|
+
}
|
|
744
|
+
startObject(name, fromDeclaration = true) {
|
|
745
|
+
if (this.object && !this.object.fromDeclaration) {
|
|
746
|
+
this.object.name = name;
|
|
747
|
+
this.object.fromDeclaration = fromDeclaration;
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
const previousMaterial = this.object && typeof this.object.currentMaterial === "function" ? this.object.currentMaterial() : void 0;
|
|
751
|
+
if (this.object && typeof this.object._finalize === "function") {
|
|
752
|
+
this.object._finalize(true);
|
|
753
|
+
}
|
|
754
|
+
this.object = new MeshObject(name);
|
|
755
|
+
this.object.fromDeclaration = fromDeclaration;
|
|
756
|
+
if (previousMaterial && previousMaterial.name && typeof previousMaterial.clone === "function") {
|
|
757
|
+
const declared = previousMaterial.clone(0);
|
|
758
|
+
declared.inherited = true;
|
|
759
|
+
this.object.materials.push(declared);
|
|
760
|
+
}
|
|
761
|
+
this.objects.push(this.object);
|
|
762
|
+
}
|
|
763
|
+
finalize() {
|
|
764
|
+
if (this.object && typeof this.object._finalize === "function") {
|
|
765
|
+
this.object._finalize(true);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
parseVertexIndex(value, len) {
|
|
769
|
+
const index = parseInt(value);
|
|
770
|
+
return (index >= 0 ? index - 1 : index + len / 3) * 3;
|
|
771
|
+
}
|
|
772
|
+
parseNormalIndex(value, len) {
|
|
773
|
+
const index = parseInt(value);
|
|
774
|
+
return (index >= 0 ? index - 1 : index + len / 3) * 3;
|
|
775
|
+
}
|
|
776
|
+
parseUVIndex(value, len) {
|
|
777
|
+
const index = parseInt(value);
|
|
778
|
+
return (index >= 0 ? index - 1 : index + len / 2) * 2;
|
|
779
|
+
}
|
|
780
|
+
addVertex(a, b, c) {
|
|
781
|
+
const src = this.vertices;
|
|
782
|
+
const dst = this.object.geometry.vertices;
|
|
783
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
784
|
+
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
785
|
+
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
786
|
+
}
|
|
787
|
+
addVertexPoint(a) {
|
|
788
|
+
const src = this.vertices;
|
|
789
|
+
const dst = this.object.geometry.vertices;
|
|
790
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
791
|
+
}
|
|
792
|
+
addVertexLine(a) {
|
|
793
|
+
const src = this.vertices;
|
|
794
|
+
const dst = this.object.geometry.vertices;
|
|
795
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
796
|
+
}
|
|
797
|
+
addNormal(a, b, c) {
|
|
798
|
+
const src = this.normals;
|
|
799
|
+
const dst = this.object.geometry.normals;
|
|
800
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
801
|
+
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
802
|
+
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
803
|
+
}
|
|
804
|
+
addColor(a, b, c) {
|
|
805
|
+
const src = this.colors;
|
|
806
|
+
const dst = this.object.geometry.colors;
|
|
807
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
808
|
+
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
809
|
+
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
810
|
+
}
|
|
811
|
+
addUV(a, b, c) {
|
|
812
|
+
const src = this.uvs;
|
|
813
|
+
const dst = this.object.geometry.uvs;
|
|
814
|
+
dst.push(src[a + 0], src[a + 1]);
|
|
815
|
+
dst.push(src[b + 0], src[b + 1]);
|
|
816
|
+
dst.push(src[c + 0], src[c + 1]);
|
|
817
|
+
}
|
|
818
|
+
addUVLine(a) {
|
|
819
|
+
const src = this.uvs;
|
|
820
|
+
const dst = this.object.geometry.uvs;
|
|
821
|
+
dst.push(src[a + 0], src[a + 1]);
|
|
822
|
+
}
|
|
823
|
+
addFace(a, b, c, ua, ub, uc, na, nb, nc) {
|
|
824
|
+
const vLen = this.vertices.length;
|
|
825
|
+
let ia = this.parseVertexIndex(a, vLen);
|
|
826
|
+
let ib = this.parseVertexIndex(b, vLen);
|
|
827
|
+
let ic = this.parseVertexIndex(c, vLen);
|
|
828
|
+
this.addVertex(ia, ib, ic);
|
|
829
|
+
if (ua !== void 0 && ua !== "") {
|
|
830
|
+
const uvLen = this.uvs.length;
|
|
831
|
+
ia = this.parseUVIndex(ua, uvLen);
|
|
832
|
+
ib = this.parseUVIndex(ub, uvLen);
|
|
833
|
+
ic = this.parseUVIndex(uc, uvLen);
|
|
834
|
+
this.addUV(ia, ib, ic);
|
|
835
|
+
}
|
|
836
|
+
if (na !== void 0 && na !== "") {
|
|
837
|
+
const nLen = this.normals.length;
|
|
838
|
+
ia = this.parseNormalIndex(na, nLen);
|
|
839
|
+
ib = na === nb ? ia : this.parseNormalIndex(nb, nLen);
|
|
840
|
+
ic = na === nc ? ia : this.parseNormalIndex(nc, nLen);
|
|
841
|
+
this.addNormal(ia, ib, ic);
|
|
842
|
+
}
|
|
843
|
+
if (this.colors.length > 0) {
|
|
844
|
+
this.addColor(ia, ib, ic);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
addPointGeometry(vertices) {
|
|
848
|
+
this.object.geometry.type = "Points";
|
|
849
|
+
const vLen = this.vertices.length;
|
|
850
|
+
for (const vertex of vertices) {
|
|
851
|
+
this.addVertexPoint(this.parseVertexIndex(vertex, vLen));
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
addLineGeometry(vertices, uvs) {
|
|
855
|
+
this.object.geometry.type = "Line";
|
|
856
|
+
const vLen = this.vertices.length;
|
|
857
|
+
const uvLen = this.uvs.length;
|
|
858
|
+
for (const vertex of vertices) {
|
|
859
|
+
this.addVertexLine(this.parseVertexIndex(vertex, vLen));
|
|
860
|
+
}
|
|
861
|
+
for (const uv of uvs) {
|
|
862
|
+
this.addUVLine(this.parseUVIndex(uv, uvLen));
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
var parse_obj_default = (text) => {
|
|
867
|
+
const state = new ParserState();
|
|
868
|
+
if (text.indexOf("\r\n") !== -1) {
|
|
869
|
+
text = text.replace(/\r\n/g, "\n");
|
|
870
|
+
}
|
|
871
|
+
if (text.indexOf("\\\n") !== -1) {
|
|
872
|
+
text = text.replace(/\\\n/g, "");
|
|
873
|
+
}
|
|
874
|
+
const lines = text.split("\n");
|
|
875
|
+
let line = "";
|
|
876
|
+
let lineFirstChar = "";
|
|
877
|
+
let lineLength = 0;
|
|
878
|
+
let result = [];
|
|
879
|
+
const trimLeft = typeof "".trimLeft === "function";
|
|
880
|
+
for (let i = 0, l = lines.length; i < l; i++) {
|
|
881
|
+
line = lines[i];
|
|
882
|
+
line = trimLeft ? line.trimLeft() : line.trim();
|
|
883
|
+
lineLength = line.length;
|
|
884
|
+
if (lineLength === 0)
|
|
885
|
+
continue;
|
|
886
|
+
lineFirstChar = line.charAt(0);
|
|
887
|
+
if (lineFirstChar === "#")
|
|
888
|
+
continue;
|
|
889
|
+
if (lineFirstChar === "v") {
|
|
890
|
+
const data = line.split(/\s+/);
|
|
891
|
+
switch (data[0]) {
|
|
892
|
+
case "v":
|
|
893
|
+
state.vertices.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
|
|
894
|
+
if (data.length === 8) {
|
|
895
|
+
state.colors.push(parseFloat(data[4]), parseFloat(data[5]), parseFloat(data[6]));
|
|
896
|
+
}
|
|
897
|
+
break;
|
|
898
|
+
case "vn":
|
|
899
|
+
state.normals.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
|
|
900
|
+
break;
|
|
901
|
+
case "vt":
|
|
902
|
+
state.uvs.push(parseFloat(data[1]), parseFloat(data[2]));
|
|
903
|
+
break;
|
|
904
|
+
default:
|
|
905
|
+
}
|
|
906
|
+
} else if (lineFirstChar === "f") {
|
|
907
|
+
const lineData = line.substr(1).trim();
|
|
908
|
+
const vertexData = lineData.split(/\s+/);
|
|
909
|
+
const faceVertices = [];
|
|
910
|
+
for (let j = 0, jl = vertexData.length; j < jl; j++) {
|
|
911
|
+
const vertex = vertexData[j];
|
|
912
|
+
if (vertex.length > 0) {
|
|
913
|
+
const vertexParts = vertex.split("/");
|
|
914
|
+
faceVertices.push(vertexParts);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
const v1 = faceVertices[0];
|
|
918
|
+
for (let j = 1, jl = faceVertices.length - 1; j < jl; j++) {
|
|
919
|
+
const v2 = faceVertices[j];
|
|
920
|
+
const v3 = faceVertices[j + 1];
|
|
921
|
+
state.addFace(v1[0], v2[0], v3[0], v1[1], v2[1], v3[1], v1[2], v2[2], v3[2]);
|
|
922
|
+
}
|
|
923
|
+
} else if (lineFirstChar === "l") {
|
|
924
|
+
const lineParts = line.substring(1).trim().split(" ");
|
|
925
|
+
let lineVertices;
|
|
926
|
+
const lineUVs = [];
|
|
927
|
+
if (line.indexOf("/") === -1) {
|
|
928
|
+
lineVertices = lineParts;
|
|
929
|
+
} else {
|
|
930
|
+
lineVertices = [];
|
|
931
|
+
for (let li = 0, llen = lineParts.length; li < llen; li++) {
|
|
932
|
+
const parts = lineParts[li].split("/");
|
|
933
|
+
if (parts[0] !== "")
|
|
934
|
+
lineVertices.push(parts[0]);
|
|
935
|
+
if (parts[1] !== "")
|
|
936
|
+
lineUVs.push(parts[1]);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
state.addLineGeometry(lineVertices, lineUVs);
|
|
940
|
+
} else if (lineFirstChar === "p") {
|
|
941
|
+
const lineData = line.substr(1).trim();
|
|
942
|
+
const pointData = lineData.split(" ");
|
|
943
|
+
state.addPointGeometry(pointData);
|
|
944
|
+
} else if ((result = OBJECT_RE.exec(line)) !== null) {
|
|
945
|
+
const name = (" " + result[0].substr(1).trim()).substr(1);
|
|
946
|
+
state.startObject(name);
|
|
947
|
+
} else if (MATERIAL_USE_RE.test(line)) {
|
|
948
|
+
state.object.startMaterial(line.substring(7).trim(), state.materialLibraries);
|
|
949
|
+
} else if (MATERIAL_RE.test(line)) {
|
|
950
|
+
state.materialLibraries.push(line.substring(7).trim());
|
|
951
|
+
} else if (lineFirstChar === "s") {
|
|
952
|
+
result = line.split(" ");
|
|
953
|
+
if (result.length > 1) {
|
|
954
|
+
const value = result[1].trim().toLowerCase();
|
|
955
|
+
state.object.smooth = value !== "0" && value !== "off";
|
|
956
|
+
} else {
|
|
957
|
+
state.object.smooth = true;
|
|
958
|
+
}
|
|
959
|
+
const material = state.object.currentMaterial();
|
|
960
|
+
if (material)
|
|
961
|
+
material.smooth = state.object.smooth;
|
|
962
|
+
} else {
|
|
963
|
+
if (line === "\0")
|
|
964
|
+
continue;
|
|
965
|
+
throw new Error(`Unexpected line: "${line}"`);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
state.finalize();
|
|
969
|
+
const meshes = [];
|
|
970
|
+
const materials = [];
|
|
971
|
+
for (const object of state.objects) {
|
|
972
|
+
const { geometry } = object;
|
|
973
|
+
if (geometry.vertices.length === 0)
|
|
974
|
+
continue;
|
|
975
|
+
const mesh = {
|
|
976
|
+
header: {
|
|
977
|
+
vertexCount: geometry.vertices.length / 3
|
|
978
|
+
},
|
|
979
|
+
attributes: {}
|
|
980
|
+
};
|
|
981
|
+
switch (geometry.type) {
|
|
982
|
+
case "Points":
|
|
983
|
+
mesh.mode = 0;
|
|
984
|
+
break;
|
|
985
|
+
case "Line":
|
|
986
|
+
mesh.mode = 1;
|
|
987
|
+
break;
|
|
988
|
+
default:
|
|
989
|
+
mesh.mode = 4;
|
|
990
|
+
break;
|
|
991
|
+
}
|
|
992
|
+
mesh.attributes.POSITION = { value: new Float32Array(geometry.vertices), size: 3 };
|
|
993
|
+
if (geometry.normals.length > 0) {
|
|
994
|
+
mesh.attributes.NORMAL = { value: new Float32Array(geometry.normals), size: 3 };
|
|
995
|
+
}
|
|
996
|
+
if (geometry.colors.length > 0) {
|
|
997
|
+
mesh.attributes.COLOR_0 = { value: new Float32Array(geometry.colors), size: 3 };
|
|
998
|
+
}
|
|
999
|
+
if (geometry.uvs.length > 0) {
|
|
1000
|
+
mesh.attributes.TEXCOORD_0 = { value: new Float32Array(geometry.uvs), size: 2 };
|
|
1001
|
+
}
|
|
1002
|
+
mesh.materials = [];
|
|
1003
|
+
for (const sourceMaterial of object.materials) {
|
|
1004
|
+
const _material = {
|
|
1005
|
+
name: sourceMaterial.name,
|
|
1006
|
+
flatShading: !sourceMaterial.smooth
|
|
1007
|
+
};
|
|
1008
|
+
mesh.materials.push(_material);
|
|
1009
|
+
materials.push(_material);
|
|
1010
|
+
}
|
|
1011
|
+
mesh.name = object.name;
|
|
1012
|
+
meshes.push(mesh);
|
|
1013
|
+
}
|
|
1014
|
+
return { meshes, materials };
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
// src/lib/get-obj-schema.ts
|
|
1018
|
+
function getOBJSchema(attributes, metadata = {}) {
|
|
1019
|
+
let metadataMap;
|
|
1020
|
+
for (const key in metadata) {
|
|
1021
|
+
metadataMap = metadataMap || new Map();
|
|
1022
|
+
if (key !== "value") {
|
|
1023
|
+
metadataMap.set(key, JSON.stringify(metadata[key]));
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
const fields = [];
|
|
1027
|
+
for (const attributeName in attributes) {
|
|
1028
|
+
const attribute = attributes[attributeName];
|
|
1029
|
+
const field = getArrowFieldFromAttribute(attributeName, attribute);
|
|
1030
|
+
fields.push(field);
|
|
1031
|
+
}
|
|
1032
|
+
return new Schema(fields, metadataMap);
|
|
1033
|
+
}
|
|
1034
|
+
function getArrowFieldFromAttribute(attributeName, attribute) {
|
|
1035
|
+
const metadataMap = new Map();
|
|
1036
|
+
for (const key in attribute) {
|
|
1037
|
+
if (key !== "value") {
|
|
1038
|
+
metadataMap.set(key, JSON.stringify(attribute[key]));
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
const type = getArrowTypeFromTypedArray(attribute.value);
|
|
1042
|
+
const isSingleValue = !("size" in attribute) || attribute.size === 1;
|
|
1043
|
+
return isSingleValue ? new Field(attributeName, type, false, metadataMap) : new Field(attributeName, new FixedSizeList(attribute.size, new Field("value", type)), false, metadataMap);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
// src/lib/load-obj.ts
|
|
1047
|
+
function loadOBJ(text, options) {
|
|
1048
|
+
const { meshes } = parse_obj_default(text);
|
|
1049
|
+
const vertexCount = meshes.reduce((s, mesh) => s + mesh.header.vertexCount, 0);
|
|
1050
|
+
const attributes = mergeAttributes(meshes, vertexCount);
|
|
1051
|
+
const header = {
|
|
1052
|
+
vertexCount,
|
|
1053
|
+
boundingBox: getMeshBoundingBox(attributes)
|
|
1054
|
+
};
|
|
1055
|
+
const schema = getOBJSchema(attributes, {
|
|
1056
|
+
mode: 4,
|
|
1057
|
+
boundingBox: header.boundingBox
|
|
1058
|
+
});
|
|
1059
|
+
return {
|
|
1060
|
+
loaderData: {
|
|
1061
|
+
header: {}
|
|
1062
|
+
},
|
|
1063
|
+
schema,
|
|
1064
|
+
header,
|
|
1065
|
+
mode: 4,
|
|
1066
|
+
attributes
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
function mergeAttributes(meshes, vertexCount) {
|
|
1070
|
+
const positions = new Float32Array(vertexCount * 3);
|
|
1071
|
+
let normals;
|
|
1072
|
+
let colors;
|
|
1073
|
+
let uvs;
|
|
1074
|
+
let i = 0;
|
|
1075
|
+
for (const mesh of meshes) {
|
|
1076
|
+
const { POSITION, NORMAL, COLOR_0, TEXCOORD_0 } = mesh.attributes;
|
|
1077
|
+
positions.set(POSITION.value, i * 3);
|
|
1078
|
+
if (NORMAL) {
|
|
1079
|
+
normals = normals || new Float32Array(vertexCount * 3);
|
|
1080
|
+
normals.set(NORMAL.value, i * 3);
|
|
1081
|
+
}
|
|
1082
|
+
if (COLOR_0) {
|
|
1083
|
+
colors = colors || new Float32Array(vertexCount * 3);
|
|
1084
|
+
colors.set(COLOR_0.value, i * 3);
|
|
1085
|
+
}
|
|
1086
|
+
if (TEXCOORD_0) {
|
|
1087
|
+
uvs = uvs || new Float32Array(vertexCount * 2);
|
|
1088
|
+
uvs.set(TEXCOORD_0.value, i * 2);
|
|
1089
|
+
}
|
|
1090
|
+
i += POSITION.value.length / 3;
|
|
1091
|
+
}
|
|
1092
|
+
const attributes = {};
|
|
1093
|
+
attributes.POSITION = { value: positions, size: 3 };
|
|
1094
|
+
if (normals) {
|
|
1095
|
+
attributes.NORMAL = { value: normals, size: 3 };
|
|
1096
|
+
}
|
|
1097
|
+
if (colors) {
|
|
1098
|
+
attributes.COLOR_0 = { value: colors, size: 3 };
|
|
1099
|
+
}
|
|
1100
|
+
if (uvs) {
|
|
1101
|
+
attributes.TEXCOORD_0 = { value: uvs, size: 2 };
|
|
1102
|
+
}
|
|
1103
|
+
return attributes;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
// src/obj-loader.ts
|
|
1107
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1108
|
+
var OBJLoader = {
|
|
1109
|
+
name: "OBJ",
|
|
1110
|
+
id: "obj",
|
|
1111
|
+
module: "obj",
|
|
1112
|
+
version: VERSION,
|
|
1113
|
+
worker: true,
|
|
1114
|
+
extensions: ["obj"],
|
|
1115
|
+
mimeTypes: ["text/plain"],
|
|
1116
|
+
testText: testOBJFile,
|
|
1117
|
+
options: {
|
|
1118
|
+
obj: {}
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1121
|
+
function testOBJFile(text) {
|
|
1122
|
+
return text[0] === "v";
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
// src/index.ts
|
|
1126
|
+
var OBJLoader2 = {
|
|
1127
|
+
...OBJLoader,
|
|
1128
|
+
parse: async (arrayBuffer, options) => loadOBJ(new TextDecoder().decode(arrayBuffer), options),
|
|
1129
|
+
parseTextSync: loadOBJ
|
|
1130
|
+
};
|
|
1131
|
+
|
|
1132
|
+
// src/workers/obj-worker.js
|
|
1133
|
+
createLoaderWorker(OBJLoader2);
|
|
1134
|
+
})();
|