@loaders.gl/ply 3.1.0-alpha.4 → 3.1.0-beta.3
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/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +1249 -0
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +5 -37
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/get-ply-schema.js +3 -3
- package/dist/es5/lib/get-ply-schema.js.map +1 -1
- package/dist/es5/lib/normalize-ply.js +15 -15
- package/dist/es5/lib/normalize-ply.js.map +1 -1
- package/dist/es5/lib/parse-ply-in-batches.js +107 -247
- package/dist/es5/lib/parse-ply-in-batches.js.map +1 -1
- package/dist/es5/lib/parse-ply.js +52 -55
- package/dist/es5/lib/parse-ply.js.map +1 -1
- package/dist/es5/ply-loader.js +3 -3
- package/dist/es5/ply-loader.js.map +1 -1
- package/dist/esm/ply-loader.js +1 -1
- package/dist/esm/ply-loader.js.map +1 -1
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/lib/get-ply-schema.d.ts +10 -0
- package/dist/lib/get-ply-schema.d.ts.map +1 -0
- package/dist/lib/get-ply-schema.js +36 -0
- package/dist/lib/normalize-ply.d.ts +8 -0
- package/dist/lib/normalize-ply.d.ts.map +1 -0
- package/dist/lib/normalize-ply.js +58 -0
- package/dist/lib/parse-ply-in-batches.d.ts +8 -0
- package/dist/lib/parse-ply-in-batches.d.ts.map +1 -0
- package/dist/lib/parse-ply-in-batches.js +253 -0
- package/dist/lib/parse-ply.d.ts +8 -0
- package/dist/lib/parse-ply.d.ts.map +1 -0
- package/dist/lib/parse-ply.js +350 -0
- package/dist/lib/ply-types.d.ts +29 -0
- package/dist/lib/ply-types.d.ts.map +1 -0
- package/dist/lib/ply-types.js +2 -0
- package/dist/ply-loader.d.ts +24 -0
- package/dist/ply-loader.d.ts.map +1 -0
- package/dist/ply-loader.js +28 -0
- package/dist/ply-worker.js +1257 -2
- package/dist/workers/ply-worker.d.ts +2 -0
- package/dist/workers/ply-worker.d.ts.map +1 -0
- package/dist/workers/ply-worker.js +5 -0
- package/package.json +10 -8
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/ply-worker.js.map +0 -1
package/dist/es5/bundle.js
CHANGED
package/dist/es5/bundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":";;AACA,
|
|
1
|
+
{"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":";;AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
package/dist/es5/index.js
CHANGED
|
@@ -7,57 +7,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
Object.defineProperty(exports, "PLYWorkerLoader", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function
|
|
10
|
+
get: function () {
|
|
11
11
|
return _plyLoader.PLYLoader;
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
exports._typecheckPLYLoader = exports.PLYLoader = void 0;
|
|
15
15
|
|
|
16
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
17
|
-
|
|
18
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
19
|
-
|
|
20
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
21
|
-
|
|
22
16
|
var _plyLoader = require("./ply-loader");
|
|
23
17
|
|
|
24
18
|
var _parsePly = _interopRequireDefault(require("./lib/parse-ply"));
|
|
25
19
|
|
|
26
20
|
var _parsePlyInBatches = _interopRequireDefault(require("./lib/parse-ply-in-batches"));
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
31
|
-
|
|
32
|
-
var PLYLoader = _objectSpread(_objectSpread({}, _plyLoader.PLYLoader), {}, {
|
|
33
|
-
parse: function () {
|
|
34
|
-
var _parse = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(arrayBuffer, options) {
|
|
35
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
36
|
-
while (1) {
|
|
37
|
-
switch (_context.prev = _context.next) {
|
|
38
|
-
case 0:
|
|
39
|
-
return _context.abrupt("return", (0, _parsePly.default)(arrayBuffer, options));
|
|
40
|
-
|
|
41
|
-
case 1:
|
|
42
|
-
case "end":
|
|
43
|
-
return _context.stop();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}, _callee);
|
|
47
|
-
}));
|
|
48
|
-
|
|
49
|
-
function parse(_x, _x2) {
|
|
50
|
-
return _parse.apply(this, arguments);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return parse;
|
|
54
|
-
}(),
|
|
22
|
+
const PLYLoader = { ..._plyLoader.PLYLoader,
|
|
23
|
+
parse: async (arrayBuffer, options) => (0, _parsePly.default)(arrayBuffer, options),
|
|
55
24
|
parseTextSync: _parsePly.default,
|
|
56
25
|
parseSync: _parsePly.default,
|
|
57
26
|
parseInBatches: _parsePlyInBatches.default
|
|
58
|
-
}
|
|
59
|
-
|
|
27
|
+
};
|
|
60
28
|
exports.PLYLoader = PLYLoader;
|
|
61
|
-
|
|
29
|
+
const _typecheckPLYLoader = PLYLoader;
|
|
62
30
|
exports._typecheckPLYLoader = _typecheckPLYLoader;
|
|
63
31
|
//# sourceMappingURL=index.js.map
|
package/dist/es5/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":["PLYLoader","PLYWorkerLoader","parse","arrayBuffer","options","parseTextSync","parsePLY","parseSync","parseInBatches","parsePLYInBatches","_typecheckPLYLoader"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["PLYLoader","PLYWorkerLoader","parse","arrayBuffer","options","parseTextSync","parsePLY","parseSync","parseInBatches","parsePLYInBatches","_typecheckPLYLoader"],"mappings":";;;;;;;;;;;;;;;AACA;;AACA;;AACA;;AASO,MAAMA,SAAS,GAAG,EACvB,GAAGC,oBADoB;AAGvBC,EAAAA,KAAK,EAAE,OAAOC,WAAP,EAAoBC,OAApB,KAAgC,uBAASD,WAAT,EAAsBC,OAAtB,CAHhB;AAIvBC,EAAAA,aAAa,EAAEC,iBAJQ;AAKvBC,EAAAA,SAAS,EAAED,iBALY;AAMvBE,EAAAA,cAAc,EAAEC;AANO,CAAlB;;AASA,MAAMC,mBAAqC,GAAGV,SAA9C","sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {PLYLoader as PLYWorkerLoader} from './ply-loader';\nimport parsePLY from './lib/parse-ply';\nimport parsePLYInBatches from './lib/parse-ply-in-batches';\n\n// PLYLoader\n\nexport {PLYWorkerLoader};\n\n/**\n * Loader for PLY - Polygon File Format\n */\nexport const PLYLoader = {\n ...PLYWorkerLoader,\n // Note: parsePLY supports both text and binary\n parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options), // TODO - this may not detect text correctly?\n parseTextSync: parsePLY,\n parseSync: parsePLY,\n parseInBatches: parsePLYInBatches\n};\n\nexport const _typecheckPLYLoader: LoaderWithParser = PLYLoader;\n"],"file":"index.js"}
|
|
@@ -8,13 +8,13 @@ exports.getPLYSchema = getPLYSchema;
|
|
|
8
8
|
var _schema = require("@loaders.gl/schema");
|
|
9
9
|
|
|
10
10
|
function getPLYSchema(plyHeader, attributes) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const metadataMap = makeMetadataFromPlyHeader(plyHeader);
|
|
12
|
+
const schema = (0, _schema.deduceMeshSchema)(attributes, metadataMap);
|
|
13
13
|
return schema;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
function makeMetadataFromPlyHeader(plyHeader) {
|
|
17
|
-
|
|
17
|
+
const metadataMap = new Map();
|
|
18
18
|
metadataMap.set('ply_comments', JSON.stringify(plyHeader.comments));
|
|
19
19
|
metadataMap.set('ply_elements', JSON.stringify(plyHeader.elements));
|
|
20
20
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/get-ply-schema.ts"],"names":["getPLYSchema","plyHeader","attributes","metadataMap","makeMetadataFromPlyHeader","schema","Map","set","JSON","stringify","comments","elements","format","undefined","version","headerLength","toString"],"mappings":";;;;;;;AAAA;;AASO,SAASA,YAAT,CAAsBC,SAAtB,EAA4CC,UAA5C,EAAgF;AACrF,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/get-ply-schema.ts"],"names":["getPLYSchema","plyHeader","attributes","metadataMap","makeMetadataFromPlyHeader","schema","Map","set","JSON","stringify","comments","elements","format","undefined","version","headerLength","toString"],"mappings":";;;;;;;AAAA;;AASO,SAASA,YAAT,CAAsBC,SAAtB,EAA4CC,UAA5C,EAAgF;AACrF,QAAMC,WAAW,GAAGC,yBAAyB,CAACH,SAAD,CAA7C;AACA,QAAMI,MAAM,GAAG,8BAAiBH,UAAjB,EAA6BC,WAA7B,CAAf;AACA,SAAOE,MAAP;AACD;;AAOD,SAASD,yBAAT,CAAmCH,SAAnC,EAA8E;AAC5E,QAAME,WAAW,GAAG,IAAIG,GAAJ,EAApB;AACAH,EAAAA,WAAW,CAACI,GAAZ,CAAgB,cAAhB,EAAgCC,IAAI,CAACC,SAAL,CAAeR,SAAS,CAACS,QAAzB,CAAhC;AACAP,EAAAA,WAAW,CAACI,GAAZ,CAAgB,cAAhB,EAAgCC,IAAI,CAACC,SAAL,CAAeR,SAAS,CAACU,QAAzB,CAAhC;;AACA,MAAIV,SAAS,CAACW,MAAV,KAAqBC,SAAzB,EAAoC;AAClCV,IAAAA,WAAW,CAACI,GAAZ,CAAgB,YAAhB,EAA8BN,SAAS,CAACW,MAAxC;AACD;;AACD,MAAIX,SAAS,CAACa,OAAV,KAAsBD,SAA1B,EAAqC;AACnCV,IAAAA,WAAW,CAACI,GAAZ,CAAgB,aAAhB,EAA+BN,SAAS,CAACa,OAAzC;AACD;;AACD,MAAIb,SAAS,CAACc,YAAV,KAA2BF,SAA/B,EAA0C;AACxCV,IAAAA,WAAW,CAACI,GAAZ,CAAgB,kBAAhB,EAAoCN,SAAS,CAACc,YAAV,CAAuBC,QAAvB,CAAgC,EAAhC,CAApC;AACD;;AACD,SAAOb,WAAP;AACD","sourcesContent":["import {Schema, MeshAttributes, deduceMeshSchema} from '@loaders.gl/schema';\nimport type {PLYHeader} from './ply-types';\n\n/**\n * Gets schema from PLY header\n * @param plyHeader\n * @param metadata\n * @returns Schema\n */\nexport function getPLYSchema(plyHeader: PLYHeader, attributes: MeshAttributes): Schema {\n const metadataMap = makeMetadataFromPlyHeader(plyHeader);\n const schema = deduceMeshSchema(attributes, metadataMap);\n return schema;\n}\n\n/**\n * Make arrow like schema metadata by PlyHeader properties\n * @param plyHeader\n * @returns\n */\nfunction makeMetadataFromPlyHeader(plyHeader: PLYHeader): Map<string, string> {\n const metadataMap = new Map();\n metadataMap.set('ply_comments', JSON.stringify(plyHeader.comments));\n metadataMap.set('ply_elements', JSON.stringify(plyHeader.elements));\n if (plyHeader.format !== undefined) {\n metadataMap.set('ply_format', plyHeader.format);\n }\n if (plyHeader.version !== undefined) {\n metadataMap.set('ply_version', plyHeader.version);\n }\n if (plyHeader.headerLength !== undefined) {\n metadataMap.set('ply_headerLength', plyHeader.headerLength.toString(10));\n }\n return metadataMap;\n}\n"],"file":"get-ply-schema.js"}
|
|
@@ -10,28 +10,28 @@ var _schema = require("@loaders.gl/schema");
|
|
|
10
10
|
var _getPlySchema = require("./get-ply-schema");
|
|
11
11
|
|
|
12
12
|
function normalizePLY(plyHeader, plyAttributes, options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
const attributes = getMeshAttributes(plyAttributes);
|
|
14
|
+
const boundingBox = (0, _schema.getMeshBoundingBox)(attributes);
|
|
15
|
+
const vertexCount = plyAttributes.indices.length || plyAttributes.vertices.length / 3;
|
|
16
|
+
const isTriangles = plyAttributes.indices && plyAttributes.indices.length > 0;
|
|
17
|
+
const mode = isTriangles ? 4 : 0;
|
|
18
|
+
const topology = isTriangles ? 'triangle-list' : 'point-list';
|
|
19
|
+
const schema = (0, _getPlySchema.getPLYSchema)(plyHeader, attributes);
|
|
20
|
+
const plyMesh = {
|
|
21
21
|
loader: 'ply',
|
|
22
22
|
loaderData: plyHeader,
|
|
23
23
|
header: {
|
|
24
|
-
vertexCount
|
|
25
|
-
boundingBox
|
|
24
|
+
vertexCount,
|
|
25
|
+
boundingBox
|
|
26
26
|
},
|
|
27
|
-
schema
|
|
28
|
-
attributes
|
|
27
|
+
schema,
|
|
28
|
+
attributes,
|
|
29
29
|
indices: {
|
|
30
30
|
value: new Uint32Array(0),
|
|
31
31
|
size: 0
|
|
32
32
|
},
|
|
33
|
-
mode
|
|
34
|
-
topology
|
|
33
|
+
mode,
|
|
34
|
+
topology
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
if (plyAttributes.indices.length > 0) {
|
|
@@ -45,7 +45,7 @@ function normalizePLY(plyHeader, plyAttributes, options) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
function getMeshAttributes(attributes) {
|
|
48
|
-
|
|
48
|
+
const accessors = {};
|
|
49
49
|
accessors.POSITION = {
|
|
50
50
|
value: new Float32Array(attributes.vertices),
|
|
51
51
|
size: 3
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/normalize-ply.ts"],"names":["normalizePLY","plyHeader","plyAttributes","options","attributes","getMeshAttributes","boundingBox","vertexCount","indices","length","vertices","isTriangles","mode","topology","schema","plyMesh","loader","loaderData","header","value","Uint32Array","size","accessors","POSITION","Float32Array","normals","NORMAL","uvs","TEXCOORD_0","colors","COLOR_0","Uint8Array","normalized"],"mappings":";;;;;;;AACA;;AAEA;;AAOe,SAASA,YAAT,CACbC,SADa,EAEbC,aAFa,EAGbC,OAHa,EAIJ;AACT,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/normalize-ply.ts"],"names":["normalizePLY","plyHeader","plyAttributes","options","attributes","getMeshAttributes","boundingBox","vertexCount","indices","length","vertices","isTriangles","mode","topology","schema","plyMesh","loader","loaderData","header","value","Uint32Array","size","accessors","POSITION","Float32Array","normals","NORMAL","uvs","TEXCOORD_0","colors","COLOR_0","Uint8Array","normalized"],"mappings":";;;;;;;AACA;;AAEA;;AAOe,SAASA,YAAT,CACbC,SADa,EAEbC,aAFa,EAGbC,OAHa,EAIJ;AACT,QAAMC,UAAU,GAAGC,iBAAiB,CAACH,aAAD,CAApC;AACA,QAAMI,WAAW,GAAG,gCAAmBF,UAAnB,CAApB;AACA,QAAMG,WAAW,GAAGL,aAAa,CAACM,OAAd,CAAsBC,MAAtB,IAAgCP,aAAa,CAACQ,QAAd,CAAuBD,MAAvB,GAAgC,CAApF;AAIA,QAAME,WAAW,GAAGT,aAAa,CAACM,OAAd,IAAyBN,aAAa,CAACM,OAAd,CAAsBC,MAAtB,GAA+B,CAA5E;AACA,QAAMG,IAAI,GAAGD,WAAW,GAAG,CAAH,GAAO,CAA/B;AACA,QAAME,QAAQ,GAAGF,WAAW,GAAG,eAAH,GAAqB,YAAjD;AAEA,QAAMG,MAAM,GAAG,gCAAab,SAAb,EAAwBG,UAAxB,CAAf;AAEA,QAAMW,OAAgB,GAAG;AACvBC,IAAAA,MAAM,EAAE,KADe;AAEvBC,IAAAA,UAAU,EAAEhB,SAFW;AAGvBiB,IAAAA,MAAM,EAAE;AACNX,MAAAA,WADM;AAEND,MAAAA;AAFM,KAHe;AAOvBQ,IAAAA,MAPuB;AAQvBV,IAAAA,UARuB;AASvBI,IAAAA,OAAO,EAAE;AAACW,MAAAA,KAAK,EAAE,IAAIC,WAAJ,CAAgB,CAAhB,CAAR;AAA4BC,MAAAA,IAAI,EAAE;AAAlC,KATc;AAUvBT,IAAAA,IAVuB;AAWvBC,IAAAA;AAXuB,GAAzB;;AAcA,MAAIX,aAAa,CAACM,OAAd,CAAsBC,MAAtB,GAA+B,CAAnC,EAAsC;AACpCM,IAAAA,OAAO,CAACP,OAAR,GAAkB;AAACW,MAAAA,KAAK,EAAE,IAAIC,WAAJ,CAAgBlB,aAAa,CAACM,OAA9B,CAAR;AAAgDa,MAAAA,IAAI,EAAE;AAAtD,KAAlB;AACD;;AAED,SAAON,OAAP;AACD;;AAMD,SAASV,iBAAT,CAA2BD,UAA3B,EAAsE;AACpE,QAAMkB,SAAyB,GAAG,EAAlC;AAEAA,EAAAA,SAAS,CAACC,QAAV,GAAqB;AAACJ,IAAAA,KAAK,EAAE,IAAIK,YAAJ,CAAiBpB,UAAU,CAACM,QAA5B,CAAR;AAA+CW,IAAAA,IAAI,EAAE;AAArD,GAArB;;AAIA,MAAIjB,UAAU,CAACqB,OAAX,CAAmBhB,MAAnB,GAA4B,CAAhC,EAAmC;AACjCa,IAAAA,SAAS,CAACI,MAAV,GAAmB;AAACP,MAAAA,KAAK,EAAE,IAAIK,YAAJ,CAAiBpB,UAAU,CAACqB,OAA5B,CAAR;AAA8CJ,MAAAA,IAAI,EAAE;AAApD,KAAnB;AACD;;AAED,MAAIjB,UAAU,CAACuB,GAAX,CAAelB,MAAf,GAAwB,CAA5B,EAA+B;AAC7Ba,IAAAA,SAAS,CAACM,UAAV,GAAuB;AAACT,MAAAA,KAAK,EAAE,IAAIK,YAAJ,CAAiBpB,UAAU,CAACuB,GAA5B,CAAR;AAA0CN,MAAAA,IAAI,EAAE;AAAhD,KAAvB;AACD;;AAED,MAAIjB,UAAU,CAACyB,MAAX,CAAkBpB,MAAlB,GAA2B,CAA/B,EAAkC;AAEhCa,IAAAA,SAAS,CAACQ,OAAV,GAAoB;AAACX,MAAAA,KAAK,EAAE,IAAIY,UAAJ,CAAe3B,UAAU,CAACyB,MAA1B,CAAR;AAA2CR,MAAAA,IAAI,EAAE,CAAjD;AAAoDW,MAAAA,UAAU,EAAE;AAAhE,KAApB;AACD;;AAED,SAAOV,SAAP;AACD","sourcesContent":["import type {MeshAttributes} from '@loaders.gl/schema';\nimport {getMeshBoundingBox} from '@loaders.gl/schema';\nimport type {PLYMesh, PLYHeader, PLYAttributes, MeshHeader} from './ply-types';\nimport {getPLYSchema} from './get-ply-schema';\n\n/**\n * @param header\n * @param attributes\n * @returns data and header\n */\nexport default function normalizePLY(\n plyHeader: MeshHeader & PLYHeader,\n plyAttributes: PLYAttributes,\n options?: {}\n): PLYMesh {\n const attributes = getMeshAttributes(plyAttributes);\n const boundingBox = getMeshBoundingBox(attributes);\n const vertexCount = plyAttributes.indices.length || plyAttributes.vertices.length / 3;\n\n // TODO - how to detect POINT CLOUDS vs MESHES?\n // TODO - For Meshes, PLY quadrangles must be split?\n const isTriangles = plyAttributes.indices && plyAttributes.indices.length > 0;\n const mode = isTriangles ? 4 : 0; // TRIANGLES vs POINTS\n const topology = isTriangles ? 'triangle-list' : 'point-list';\n\n const schema = getPLYSchema(plyHeader, attributes);\n\n const plyMesh: PLYMesh = {\n loader: 'ply',\n loaderData: plyHeader,\n header: {\n vertexCount,\n boundingBox\n },\n schema,\n attributes,\n indices: {value: new Uint32Array(0), size: 0},\n mode,\n topology\n };\n\n if (plyAttributes.indices.length > 0) {\n plyMesh.indices = {value: new Uint32Array(plyAttributes.indices), size: 1};\n }\n\n return plyMesh;\n}\n\n/**\n * @param attributes\n * @returns accessors []\n */\nfunction getMeshAttributes(attributes: PLYAttributes): MeshAttributes {\n const accessors: MeshAttributes = {};\n\n accessors.POSITION = {value: new Float32Array(attributes.vertices), size: 3};\n\n // optional attributes data\n\n if (attributes.normals.length > 0) {\n accessors.NORMAL = {value: new Float32Array(attributes.normals), size: 3};\n }\n\n if (attributes.uvs.length > 0) {\n accessors.TEXCOORD_0 = {value: new Float32Array(attributes.uvs), size: 2};\n }\n\n if (attributes.colors.length > 0) {\n // TODO - normalized shoud be based on `uchar` flag in source data?\n accessors.COLOR_0 = {value: new Uint8Array(attributes.colors), size: 3, normalized: true};\n }\n\n return accessors;\n}\n"],"file":"normalize-ply.js"}
|
|
@@ -7,155 +7,95 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = parsePLYInBatches;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _core = require("@loaders.gl/core");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _normalizePly = _interopRequireDefault(require("./normalize-ply"));
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
let currentElement;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
async function* parsePLYInBatches(iterator, options) {
|
|
17
|
+
const lineIterator = (0, _core.makeLineIterator)((0, _core.makeTextDecoderIterator)(iterator));
|
|
18
|
+
const header = await parsePLYHeader(lineIterator, options);
|
|
19
|
+
let attributes;
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
switch (header.format) {
|
|
22
|
+
case 'ascii':
|
|
23
|
+
attributes = await parseASCII(lineIterator, header);
|
|
24
|
+
break;
|
|
19
25
|
|
|
20
|
-
|
|
26
|
+
default:
|
|
27
|
+
throw new Error('Binary PLY can not yet be parsed in streaming mode');
|
|
28
|
+
}
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
yield (0, _normalizePly.default)(header, attributes, options);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function parsePLYHeader(lineIterator, options) {
|
|
34
|
+
const header = {
|
|
35
|
+
comments: [],
|
|
36
|
+
elements: []
|
|
37
|
+
};
|
|
38
|
+
await (0, _core.forEach)(lineIterator, line => {
|
|
39
|
+
line = line.trim();
|
|
23
40
|
|
|
24
|
-
|
|
41
|
+
if (line === 'end_header') {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
25
44
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
45
|
+
if (line === '') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
29
48
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return _regenerator.default.wrap(function _callee$(_context2) {
|
|
34
|
-
while (1) {
|
|
35
|
-
switch (_context2.prev = _context2.next) {
|
|
36
|
-
case 0:
|
|
37
|
-
lineIterator = (0, _core.makeLineIterator)((0, _core.makeTextDecoderIterator)(iterator));
|
|
38
|
-
_context2.next = 3;
|
|
39
|
-
return (0, _awaitAsyncGenerator2.default)(parsePLYHeader(lineIterator, options));
|
|
40
|
-
|
|
41
|
-
case 3:
|
|
42
|
-
header = _context2.sent;
|
|
43
|
-
_context2.t0 = header.format;
|
|
44
|
-
_context2.next = _context2.t0 === 'ascii' ? 7 : 11;
|
|
45
|
-
break;
|
|
46
|
-
|
|
47
|
-
case 7:
|
|
48
|
-
_context2.next = 9;
|
|
49
|
-
return (0, _awaitAsyncGenerator2.default)(parseASCII(lineIterator, header));
|
|
50
|
-
|
|
51
|
-
case 9:
|
|
52
|
-
attributes = _context2.sent;
|
|
53
|
-
return _context2.abrupt("break", 12);
|
|
54
|
-
|
|
55
|
-
case 11:
|
|
56
|
-
throw new Error('Binary PLY can not yet be parsed in streaming mode');
|
|
57
|
-
|
|
58
|
-
case 12:
|
|
59
|
-
_context2.next = 14;
|
|
60
|
-
return (0, _normalizePly.default)(header, attributes, options);
|
|
61
|
-
|
|
62
|
-
case 14:
|
|
63
|
-
case "end":
|
|
64
|
-
return _context2.stop();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}, _callee);
|
|
68
|
-
}));
|
|
69
|
-
return _parsePLYInBatches.apply(this, arguments);
|
|
70
|
-
}
|
|
49
|
+
const lineValues = line.split(/\s+/);
|
|
50
|
+
const lineType = lineValues.shift();
|
|
51
|
+
line = lineValues.join(' ');
|
|
71
52
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
53
|
+
switch (lineType) {
|
|
54
|
+
case 'ply':
|
|
55
|
+
break;
|
|
56
|
+
|
|
57
|
+
case 'format':
|
|
58
|
+
header.format = lineValues[0];
|
|
59
|
+
header.version = lineValues[1];
|
|
60
|
+
break;
|
|
75
61
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
header = {
|
|
84
|
-
comments: [],
|
|
85
|
-
elements: []
|
|
86
|
-
};
|
|
87
|
-
_context3.next = 3;
|
|
88
|
-
return (0, _core.forEach)(lineIterator, function (line) {
|
|
89
|
-
line = line.trim();
|
|
90
|
-
|
|
91
|
-
if (line === 'end_header') {
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (line === '') {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
var lineValues = line.split(/\s+/);
|
|
100
|
-
var lineType = lineValues.shift();
|
|
101
|
-
line = lineValues.join(' ');
|
|
102
|
-
|
|
103
|
-
switch (lineType) {
|
|
104
|
-
case 'ply':
|
|
105
|
-
break;
|
|
106
|
-
|
|
107
|
-
case 'format':
|
|
108
|
-
header.format = lineValues[0];
|
|
109
|
-
header.version = lineValues[1];
|
|
110
|
-
break;
|
|
111
|
-
|
|
112
|
-
case 'comment':
|
|
113
|
-
header.comments.push(line);
|
|
114
|
-
break;
|
|
115
|
-
|
|
116
|
-
case 'element':
|
|
117
|
-
if (currentElement) {
|
|
118
|
-
header.elements.push(currentElement);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
currentElement = {
|
|
122
|
-
name: lineValues[0],
|
|
123
|
-
count: parseInt(lineValues[1], 10),
|
|
124
|
-
properties: []
|
|
125
|
-
};
|
|
126
|
-
break;
|
|
127
|
-
|
|
128
|
-
case 'property':
|
|
129
|
-
var property = makePLYElementProperty(lineValues, options.propertyNameMapping);
|
|
130
|
-
currentElement.properties.push(property);
|
|
131
|
-
break;
|
|
132
|
-
|
|
133
|
-
default:
|
|
134
|
-
console.log('unhandled', lineType, lineValues);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return false;
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
case 3:
|
|
141
|
-
if (currentElement) {
|
|
142
|
-
header.elements.push(currentElement);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return _context3.abrupt("return", header);
|
|
146
|
-
|
|
147
|
-
case 5:
|
|
148
|
-
case "end":
|
|
149
|
-
return _context3.stop();
|
|
62
|
+
case 'comment':
|
|
63
|
+
header.comments.push(line);
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
case 'element':
|
|
67
|
+
if (currentElement) {
|
|
68
|
+
header.elements.push(currentElement);
|
|
150
69
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
70
|
+
|
|
71
|
+
currentElement = {
|
|
72
|
+
name: lineValues[0],
|
|
73
|
+
count: parseInt(lineValues[1], 10),
|
|
74
|
+
properties: []
|
|
75
|
+
};
|
|
76
|
+
break;
|
|
77
|
+
|
|
78
|
+
case 'property':
|
|
79
|
+
const property = makePLYElementProperty(lineValues, options.propertyNameMapping);
|
|
80
|
+
currentElement.properties.push(property);
|
|
81
|
+
break;
|
|
82
|
+
|
|
83
|
+
default:
|
|
84
|
+
console.log('unhandled', lineType, lineValues);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return false;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (currentElement) {
|
|
91
|
+
header.elements.push(currentElement);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return header;
|
|
155
95
|
}
|
|
156
96
|
|
|
157
97
|
function makePLYElementProperty(propertValues, propertyNameMapping) {
|
|
158
|
-
|
|
98
|
+
const property = {
|
|
159
99
|
type: propertValues[0]
|
|
160
100
|
};
|
|
161
101
|
|
|
@@ -174,111 +114,33 @@ function makePLYElementProperty(propertValues, propertyNameMapping) {
|
|
|
174
114
|
return property;
|
|
175
115
|
}
|
|
176
116
|
|
|
177
|
-
function parseASCII(lineIterator, header) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
_context.prev = 5;
|
|
196
|
-
_iterator = (0, _asyncIterator2.default)(lineIterator);
|
|
197
|
-
|
|
198
|
-
case 7:
|
|
199
|
-
_context.next = 9;
|
|
200
|
-
return _regenerator.default.awrap(_iterator.next());
|
|
201
|
-
|
|
202
|
-
case 9:
|
|
203
|
-
_step = _context.sent;
|
|
204
|
-
_iteratorNormalCompletion = _step.done;
|
|
205
|
-
_context.next = 13;
|
|
206
|
-
return _regenerator.default.awrap(_step.value);
|
|
207
|
-
|
|
208
|
-
case 13:
|
|
209
|
-
_value = _context.sent;
|
|
210
|
-
|
|
211
|
-
if (_iteratorNormalCompletion) {
|
|
212
|
-
_context.next = 21;
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
line = _value;
|
|
217
|
-
line = line.trim();
|
|
218
|
-
|
|
219
|
-
if (line !== '') {
|
|
220
|
-
if (currentElementCount >= header.elements[currentElement].count) {
|
|
221
|
-
currentElement++;
|
|
222
|
-
currentElementCount = 0;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
element = parseASCIIElement(header.elements[currentElement].properties, line);
|
|
226
|
-
handleElement(attributes, header.elements[currentElement].name, element);
|
|
227
|
-
currentElementCount++;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
case 18:
|
|
231
|
-
_iteratorNormalCompletion = true;
|
|
232
|
-
_context.next = 7;
|
|
233
|
-
break;
|
|
234
|
-
|
|
235
|
-
case 21:
|
|
236
|
-
_context.next = 27;
|
|
237
|
-
break;
|
|
238
|
-
|
|
239
|
-
case 23:
|
|
240
|
-
_context.prev = 23;
|
|
241
|
-
_context.t0 = _context["catch"](5);
|
|
242
|
-
_didIteratorError = true;
|
|
243
|
-
_iteratorError = _context.t0;
|
|
244
|
-
|
|
245
|
-
case 27:
|
|
246
|
-
_context.prev = 27;
|
|
247
|
-
_context.prev = 28;
|
|
248
|
-
|
|
249
|
-
if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
|
|
250
|
-
_context.next = 32;
|
|
251
|
-
break;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
_context.next = 32;
|
|
255
|
-
return _regenerator.default.awrap(_iterator.return());
|
|
256
|
-
|
|
257
|
-
case 32:
|
|
258
|
-
_context.prev = 32;
|
|
259
|
-
|
|
260
|
-
if (!_didIteratorError) {
|
|
261
|
-
_context.next = 35;
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
throw _iteratorError;
|
|
266
|
-
|
|
267
|
-
case 35:
|
|
268
|
-
return _context.finish(32);
|
|
269
|
-
|
|
270
|
-
case 36:
|
|
271
|
-
return _context.finish(27);
|
|
272
|
-
|
|
273
|
-
case 37:
|
|
274
|
-
return _context.abrupt("return", attributes);
|
|
275
|
-
|
|
276
|
-
case 38:
|
|
277
|
-
case "end":
|
|
278
|
-
return _context.stop();
|
|
117
|
+
async function parseASCII(lineIterator, header) {
|
|
118
|
+
const attributes = {
|
|
119
|
+
indices: [],
|
|
120
|
+
vertices: [],
|
|
121
|
+
normals: [],
|
|
122
|
+
uvs: [],
|
|
123
|
+
colors: []
|
|
124
|
+
};
|
|
125
|
+
let currentElement = 0;
|
|
126
|
+
let currentElementCount = 0;
|
|
127
|
+
|
|
128
|
+
for await (let line of lineIterator) {
|
|
129
|
+
line = line.trim();
|
|
130
|
+
|
|
131
|
+
if (line !== '') {
|
|
132
|
+
if (currentElementCount >= header.elements[currentElement].count) {
|
|
133
|
+
currentElement++;
|
|
134
|
+
currentElementCount = 0;
|
|
279
135
|
}
|
|
136
|
+
|
|
137
|
+
const element = parseASCIIElement(header.elements[currentElement].properties, line);
|
|
138
|
+
handleElement(attributes, header.elements[currentElement].name, element);
|
|
139
|
+
currentElementCount++;
|
|
280
140
|
}
|
|
281
|
-
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return attributes;
|
|
282
144
|
}
|
|
283
145
|
|
|
284
146
|
function parseASCIINumber(n, type) {
|
|
@@ -309,15 +171,15 @@ function parseASCIINumber(n, type) {
|
|
|
309
171
|
}
|
|
310
172
|
|
|
311
173
|
function parseASCIIElement(properties, line) {
|
|
312
|
-
|
|
313
|
-
|
|
174
|
+
const values = line.split(/\s+/);
|
|
175
|
+
const element = {};
|
|
314
176
|
|
|
315
|
-
for (
|
|
177
|
+
for (let i = 0; i < properties.length; i++) {
|
|
316
178
|
if (properties[i].type === 'list') {
|
|
317
|
-
|
|
318
|
-
|
|
179
|
+
const list = [];
|
|
180
|
+
const n = parseASCIINumber(values.shift(), properties[i].countType);
|
|
319
181
|
|
|
320
|
-
for (
|
|
182
|
+
for (let j = 0; j < n; j++) {
|
|
321
183
|
list.push(parseASCIINumber(values.shift(), properties[i].itemType));
|
|
322
184
|
}
|
|
323
185
|
|
|
@@ -330,9 +192,7 @@ function parseASCIIElement(properties, line) {
|
|
|
330
192
|
return element;
|
|
331
193
|
}
|
|
332
194
|
|
|
333
|
-
function handleElement(buffer, elementName) {
|
|
334
|
-
var element = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
335
|
-
|
|
195
|
+
function handleElement(buffer, elementName, element = {}) {
|
|
336
196
|
switch (elementName) {
|
|
337
197
|
case 'vertex':
|
|
338
198
|
buffer.vertices.push(element.x, element.y, element.z);
|
|
@@ -352,7 +212,7 @@ function handleElement(buffer, elementName) {
|
|
|
352
212
|
break;
|
|
353
213
|
|
|
354
214
|
case 'face':
|
|
355
|
-
|
|
215
|
+
const vertexIndices = element.vertex_indices || element.vertex_index;
|
|
356
216
|
|
|
357
217
|
if (vertexIndices.length === 3) {
|
|
358
218
|
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);
|