@loaders.gl/ply 4.0.0-alpha.8 → 4.0.0-beta.1
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/es5/ply-loader.js +2 -4
- package/dist/es5/ply-loader.js.map +1 -1
- package/dist/esm/ply-loader.js +1 -2
- package/dist/esm/ply-loader.js.map +1 -1
- package/dist/ply-loader.d.ts +0 -1
- package/dist/ply-loader.d.ts.map +1 -1
- package/dist/ply-worker.js +9 -4
- package/package.json +4 -4
- package/src/ply-loader.ts +0 -2
- package/dist/bundle.js +0 -5
- package/dist/index.js +0 -19
- package/dist/lib/get-ply-schema.js +0 -37
- package/dist/lib/normalize-ply.js +0 -80
- package/dist/lib/parse-ply-in-batches.js +0 -253
- package/dist/lib/parse-ply.js +0 -406
- package/dist/lib/ply-types.js +0 -2
- package/dist/ply-loader.js +0 -28
- package/dist/workers/ply-worker.js +0 -5
package/dist/es5/ply-loader.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var VERSION = typeof "4.0.0-
|
|
6
|
+
exports.PLYLoader = void 0;
|
|
7
|
+
var VERSION = typeof "4.0.0-beta.1" !== 'undefined' ? "4.0.0-beta.1" : 'latest';
|
|
8
8
|
var PLYLoader = {
|
|
9
9
|
name: 'PLY',
|
|
10
10
|
id: 'ply',
|
|
@@ -21,6 +21,4 @@ var PLYLoader = {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
exports.PLYLoader = PLYLoader;
|
|
24
|
-
var _typecheckPLYLoader = PLYLoader;
|
|
25
|
-
exports._typecheckPLYLoader = _typecheckPLYLoader;
|
|
26
24
|
//# sourceMappingURL=ply-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ply-loader.js","names":["VERSION","PLYLoader","name","id","module","version","worker","extensions","mimeTypes","text","binary","tests","options","ply","exports"
|
|
1
|
+
{"version":3,"file":"ply-loader.js","names":["VERSION","PLYLoader","name","id","module","version","worker","extensions","mimeTypes","text","binary","tests","options","ply","exports"],"sources":["../../src/ply-loader.ts"],"sourcesContent":["// PLY Loader\nimport type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\nimport {PLYMesh} from './lib/ply-types';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Worker loader for PLY - Polygon File Format (aka Stanford Triangle Format)'\n * links: ['http://paulbourke.net/dataformats/ply/',\n * 'https://en.wikipedia.org/wiki/PLY_(file_format)']\n */\nexport const PLYLoader: Loader<PLYMesh, never, LoaderOptions> = {\n name: 'PLY',\n id: 'ply',\n module: 'ply',\n // shapes: ['mesh', 'gltf', 'columnar-table'],\n version: VERSION,\n worker: true,\n extensions: ['ply'],\n mimeTypes: ['text/plain', 'application/octet-stream'],\n text: true,\n binary: true,\n tests: ['ply'],\n options: {\n ply: {}\n }\n};\n"],"mappings":";;;;;;AAMA,IAAMA,OAAO,GAAG,qBAAkB,KAAK,WAAW,oBAAiB,QAAQ;AAOpE,IAAMC,SAAgD,GAAG;EAC9DC,IAAI,EAAE,KAAK;EACXC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,KAAK;EAEbC,OAAO,EAAEL,OAAO;EAChBM,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBC,SAAS,EAAE,CAAC,YAAY,EAAE,0BAA0B,CAAC;EACrDC,IAAI,EAAE,IAAI;EACVC,MAAM,EAAE,IAAI;EACZC,KAAK,EAAE,CAAC,KAAK,CAAC;EACdC,OAAO,EAAE;IACPC,GAAG,EAAE,CAAC;EACR;AACF,CAAC;AAACC,OAAA,CAAAb,SAAA,GAAAA,SAAA"}
|
package/dist/esm/ply-loader.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const VERSION = typeof "4.0.0-
|
|
1
|
+
const VERSION = typeof "4.0.0-beta.1" !== 'undefined' ? "4.0.0-beta.1" : 'latest';
|
|
2
2
|
export const PLYLoader = {
|
|
3
3
|
name: 'PLY',
|
|
4
4
|
id: 'ply',
|
|
@@ -14,5 +14,4 @@ export const PLYLoader = {
|
|
|
14
14
|
ply: {}
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
-
export const _typecheckPLYLoader = PLYLoader;
|
|
18
17
|
//# sourceMappingURL=ply-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ply-loader.js","names":["VERSION","PLYLoader","name","id","module","version","worker","extensions","mimeTypes","text","binary","tests","options","ply"
|
|
1
|
+
{"version":3,"file":"ply-loader.js","names":["VERSION","PLYLoader","name","id","module","version","worker","extensions","mimeTypes","text","binary","tests","options","ply"],"sources":["../../src/ply-loader.ts"],"sourcesContent":["// PLY Loader\nimport type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\nimport {PLYMesh} from './lib/ply-types';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Worker loader for PLY - Polygon File Format (aka Stanford Triangle Format)'\n * links: ['http://paulbourke.net/dataformats/ply/',\n * 'https://en.wikipedia.org/wiki/PLY_(file_format)']\n */\nexport const PLYLoader: Loader<PLYMesh, never, LoaderOptions> = {\n name: 'PLY',\n id: 'ply',\n module: 'ply',\n // shapes: ['mesh', 'gltf', 'columnar-table'],\n version: VERSION,\n worker: true,\n extensions: ['ply'],\n mimeTypes: ['text/plain', 'application/octet-stream'],\n text: true,\n binary: true,\n tests: ['ply'],\n options: {\n ply: {}\n }\n};\n"],"mappings":"AAMA,MAAMA,OAAO,GAAG,qBAAkB,KAAK,WAAW,oBAAiB,QAAQ;AAO3E,OAAO,MAAMC,SAAgD,GAAG;EAC9DC,IAAI,EAAE,KAAK;EACXC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,KAAK;EAEbC,OAAO,EAAEL,OAAO;EAChBM,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBC,SAAS,EAAE,CAAC,YAAY,EAAE,0BAA0B,CAAC;EACrDC,IAAI,EAAE,IAAI;EACVC,MAAM,EAAE,IAAI;EACZC,KAAK,EAAE,CAAC,KAAK,CAAC;EACdC,OAAO,EAAE;IACPC,GAAG,EAAE,CAAC;EACR;AACF,CAAC"}
|
package/dist/ply-loader.d.ts
CHANGED
package/dist/ply-loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ply-loader.d.ts","sourceRoot":"","sources":["../src/ply-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAC;AAMxC;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAe3D,CAAC
|
|
1
|
+
{"version":3,"file":"ply-loader.d.ts","sourceRoot":"","sources":["../src/ply-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAC;AAMxC;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAe3D,CAAC"}
|
package/dist/ply-worker.js
CHANGED
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
options,
|
|
126
126
|
context: {
|
|
127
127
|
...context,
|
|
128
|
-
|
|
128
|
+
_parse: parseOnMainThread
|
|
129
129
|
}
|
|
130
130
|
});
|
|
131
131
|
WorkerBody.postMessage("done", { result });
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
|
-
function parseOnMainThread(arrayBuffer, options) {
|
|
141
|
+
function parseOnMainThread(arrayBuffer, loader, options, context) {
|
|
142
142
|
return new Promise((resolve, reject) => {
|
|
143
143
|
const id = requestId++;
|
|
144
144
|
const onMessage = (type, payload2) => {
|
|
@@ -162,7 +162,12 @@
|
|
|
162
162
|
WorkerBody.postMessage("process", payload);
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
|
-
async function parseData({
|
|
165
|
+
async function parseData({
|
|
166
|
+
loader,
|
|
167
|
+
arrayBuffer,
|
|
168
|
+
options,
|
|
169
|
+
context
|
|
170
|
+
}) {
|
|
166
171
|
let data;
|
|
167
172
|
let parser;
|
|
168
173
|
if (loader.parseSync || loader.parse) {
|
|
@@ -222,7 +227,7 @@
|
|
|
222
227
|
}
|
|
223
228
|
|
|
224
229
|
// src/ply-loader.ts
|
|
225
|
-
var VERSION = true ? "4.0.0-
|
|
230
|
+
var VERSION = true ? "4.0.0-beta.1" : "latest";
|
|
226
231
|
var PLYLoader = {
|
|
227
232
|
name: "PLY",
|
|
228
233
|
id: "ply",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/ply",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.1",
|
|
4
4
|
"description": "Framework-independent loader for the PLY format",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/runtime": "^7.3.1",
|
|
37
|
-
"@loaders.gl/loader-utils": "4.0.0-
|
|
38
|
-
"@loaders.gl/schema": "4.0.0-
|
|
37
|
+
"@loaders.gl/loader-utils": "4.0.0-beta.1",
|
|
38
|
+
"@loaders.gl/schema": "4.0.0-beta.1"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "35c625e67132b0784e597d9ddabae8aefea29ff2"
|
|
41
41
|
}
|
package/src/ply-loader.ts
CHANGED
package/dist/bundle.js
DELETED
package/dist/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.PLYLoader = exports.PLYWorkerLoader = void 0;
|
|
5
|
-
const ply_loader_1 = require("./ply-loader");
|
|
6
|
-
Object.defineProperty(exports, "PLYWorkerLoader", { enumerable: true, get: function () { return ply_loader_1.PLYLoader; } });
|
|
7
|
-
const parse_ply_1 = require("./lib/parse-ply");
|
|
8
|
-
const parse_ply_in_batches_1 = require("./lib/parse-ply-in-batches");
|
|
9
|
-
/**
|
|
10
|
-
* Loader for PLY - Polygon File Format
|
|
11
|
-
*/
|
|
12
|
-
exports.PLYLoader = {
|
|
13
|
-
...ply_loader_1.PLYLoader,
|
|
14
|
-
// Note: parsePLY supports both text and binary
|
|
15
|
-
parse: async (arrayBuffer, options) => (0, parse_ply_1.parsePLY)(arrayBuffer, options?.ply),
|
|
16
|
-
parseTextSync: (arrayBuffer, options) => (0, parse_ply_1.parsePLY)(arrayBuffer, options?.ply),
|
|
17
|
-
parseSync: (arrayBuffer, options) => (0, parse_ply_1.parsePLY)(arrayBuffer, options?.ply),
|
|
18
|
-
parseInBatches: (arrayBuffer, options) => (0, parse_ply_in_batches_1.parsePLYInBatches)(arrayBuffer, options?.ply)
|
|
19
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPLYSchema = void 0;
|
|
4
|
-
const schema_1 = require("@loaders.gl/schema");
|
|
5
|
-
/**
|
|
6
|
-
* Gets schema from PLY header
|
|
7
|
-
* @param plyHeader
|
|
8
|
-
* @param metadata
|
|
9
|
-
* @returns Schema
|
|
10
|
-
*/
|
|
11
|
-
function getPLYSchema(plyHeader, attributes) {
|
|
12
|
-
const metadata = makeMetadataFromPlyHeader(plyHeader);
|
|
13
|
-
const schema = (0, schema_1.deduceMeshSchema)(attributes, metadata);
|
|
14
|
-
return schema;
|
|
15
|
-
}
|
|
16
|
-
exports.getPLYSchema = getPLYSchema;
|
|
17
|
-
/**
|
|
18
|
-
* Make arrow like schema metadata by PlyHeader properties
|
|
19
|
-
* @param plyHeader
|
|
20
|
-
* @returns
|
|
21
|
-
*/
|
|
22
|
-
function makeMetadataFromPlyHeader(plyHeader) {
|
|
23
|
-
/* eslint-disable camelcase */
|
|
24
|
-
const metadata = {};
|
|
25
|
-
metadata.ply_comments = JSON.stringify(plyHeader.comments);
|
|
26
|
-
metadata.ply_elements = JSON.stringify(plyHeader.elements);
|
|
27
|
-
if (plyHeader.format !== undefined) {
|
|
28
|
-
metadata.ply_format = plyHeader.format;
|
|
29
|
-
}
|
|
30
|
-
if (plyHeader.version !== undefined) {
|
|
31
|
-
metadata.ply_version = plyHeader.version;
|
|
32
|
-
}
|
|
33
|
-
if (plyHeader.headerLength !== undefined) {
|
|
34
|
-
metadata.ply_headerLength = plyHeader.headerLength.toString(10);
|
|
35
|
-
}
|
|
36
|
-
return metadata;
|
|
37
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const schema_1 = require("@loaders.gl/schema");
|
|
4
|
-
const get_ply_schema_1 = require("./get-ply-schema");
|
|
5
|
-
/**
|
|
6
|
-
* @param header
|
|
7
|
-
* @param attributes
|
|
8
|
-
* @returns data and header
|
|
9
|
-
*/
|
|
10
|
-
function normalizePLY(plyHeader, plyAttributes, options) {
|
|
11
|
-
const attributes = getMeshAttributes(plyAttributes);
|
|
12
|
-
const boundingBox = (0, schema_1.getMeshBoundingBox)(attributes);
|
|
13
|
-
const vertexCount = plyAttributes.indices.length || plyAttributes.vertices.length / 3;
|
|
14
|
-
// TODO - how to detect POINT CLOUDS vs MESHES?
|
|
15
|
-
// TODO - For Meshes, PLY quadrangles must be split?
|
|
16
|
-
const isTriangles = plyAttributes.indices && plyAttributes.indices.length > 0;
|
|
17
|
-
const mode = isTriangles ? 4 : 0; // TRIANGLES vs POINTS
|
|
18
|
-
const topology = isTriangles ? 'triangle-list' : 'point-list';
|
|
19
|
-
const schema = (0, get_ply_schema_1.getPLYSchema)(plyHeader, attributes);
|
|
20
|
-
const plyMesh = {
|
|
21
|
-
loader: 'ply',
|
|
22
|
-
loaderData: plyHeader,
|
|
23
|
-
header: {
|
|
24
|
-
vertexCount,
|
|
25
|
-
boundingBox
|
|
26
|
-
},
|
|
27
|
-
schema,
|
|
28
|
-
attributes,
|
|
29
|
-
indices: { value: new Uint32Array(0), size: 0 },
|
|
30
|
-
mode,
|
|
31
|
-
topology
|
|
32
|
-
};
|
|
33
|
-
if (plyAttributes.indices.length > 0) {
|
|
34
|
-
plyMesh.indices = { value: new Uint32Array(plyAttributes.indices), size: 1 };
|
|
35
|
-
}
|
|
36
|
-
return plyMesh;
|
|
37
|
-
}
|
|
38
|
-
exports.default = normalizePLY;
|
|
39
|
-
/**
|
|
40
|
-
* @param attributes
|
|
41
|
-
* @returns accessors []
|
|
42
|
-
*/
|
|
43
|
-
// eslint-disable-next-line complexity
|
|
44
|
-
function getMeshAttributes(attributes) {
|
|
45
|
-
const accessors = {};
|
|
46
|
-
for (const attributeName of Object.keys(attributes)) {
|
|
47
|
-
switch (attributeName) {
|
|
48
|
-
case 'vertices':
|
|
49
|
-
if (attributes.vertices.length > 0) {
|
|
50
|
-
accessors.POSITION = { value: new Float32Array(attributes.vertices), size: 3 };
|
|
51
|
-
}
|
|
52
|
-
break;
|
|
53
|
-
// optional attributes data
|
|
54
|
-
case 'normals':
|
|
55
|
-
if (attributes.normals.length > 0) {
|
|
56
|
-
accessors.NORMAL = { value: new Float32Array(attributes.normals), size: 3 };
|
|
57
|
-
}
|
|
58
|
-
break;
|
|
59
|
-
case 'uvs':
|
|
60
|
-
if (attributes.uvs.length > 0) {
|
|
61
|
-
accessors.TEXCOORD_0 = { value: new Float32Array(attributes.uvs), size: 2 };
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
|
-
case 'colors':
|
|
65
|
-
if (attributes.colors.length > 0) {
|
|
66
|
-
// TODO - normalized shoud be based on `uchar` flag in source data?
|
|
67
|
-
accessors.COLOR_0 = { value: new Uint8Array(attributes.colors), size: 3, normalized: true };
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
case 'indices':
|
|
71
|
-
break;
|
|
72
|
-
default:
|
|
73
|
-
if (attributes[attributeName].length > 0) {
|
|
74
|
-
accessors[attributeName] = { value: new Float32Array(attributes[attributeName]), size: 1 };
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return accessors;
|
|
80
|
-
}
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// PLY Loader, adapted from THREE.js (MIT license)
|
|
3
|
-
//
|
|
4
|
-
// Attributions per original THREE.js source file:
|
|
5
|
-
//
|
|
6
|
-
// @author Wei Meng / http://about.me/menway
|
|
7
|
-
//
|
|
8
|
-
// Description: A loader for PLY ASCII files (known as the Polygon File Format
|
|
9
|
-
// or the Stanford Triangle Format).
|
|
10
|
-
//
|
|
11
|
-
// Limitations: ASCII decoding assumes file is UTF-8.
|
|
12
|
-
//
|
|
13
|
-
// If the PLY file uses non standard property names, they can be mapped while
|
|
14
|
-
// loading. For example, the following maps the properties
|
|
15
|
-
// “diffuse_(red|green|blue)” in the file to standard color names.
|
|
16
|
-
//
|
|
17
|
-
// parsePLY(data, {
|
|
18
|
-
// propertyNameMapping: {
|
|
19
|
-
// diffuse_red: 'red',
|
|
20
|
-
// diffuse_green: 'green',
|
|
21
|
-
// diffuse_blue: 'blue'
|
|
22
|
-
// }
|
|
23
|
-
// });
|
|
24
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.parsePLYInBatches = void 0;
|
|
29
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
30
|
-
const normalize_ply_1 = __importDefault(require("./normalize-ply"));
|
|
31
|
-
let currentElement;
|
|
32
|
-
/**
|
|
33
|
-
* PARSER
|
|
34
|
-
* @param iterator
|
|
35
|
-
* @param options
|
|
36
|
-
*/
|
|
37
|
-
async function* parsePLYInBatches(iterator, options) {
|
|
38
|
-
const lineIterator = (0, loader_utils_1.makeLineIterator)((0, loader_utils_1.makeTextDecoderIterator)(iterator));
|
|
39
|
-
const header = await parsePLYHeader(lineIterator, options);
|
|
40
|
-
let attributes;
|
|
41
|
-
switch (header.format) {
|
|
42
|
-
case 'ascii':
|
|
43
|
-
attributes = await parseASCII(lineIterator, header);
|
|
44
|
-
break;
|
|
45
|
-
default:
|
|
46
|
-
throw new Error('Binary PLY can not yet be parsed in streaming mode');
|
|
47
|
-
// attributes = await parseBinary(lineIterator, header);
|
|
48
|
-
}
|
|
49
|
-
yield (0, normalize_ply_1.default)(header, attributes, options);
|
|
50
|
-
}
|
|
51
|
-
exports.parsePLYInBatches = parsePLYInBatches;
|
|
52
|
-
/**
|
|
53
|
-
* Parses header
|
|
54
|
-
* @param lineIterator
|
|
55
|
-
* @param options
|
|
56
|
-
* @returns
|
|
57
|
-
*/
|
|
58
|
-
async function parsePLYHeader(lineIterator, options) {
|
|
59
|
-
const header = {
|
|
60
|
-
comments: [],
|
|
61
|
-
elements: []
|
|
62
|
-
// headerLength
|
|
63
|
-
};
|
|
64
|
-
// Note: forEach does not reset iterator if exiting loop prematurely
|
|
65
|
-
// so that iteration can continue in a second loop
|
|
66
|
-
await (0, loader_utils_1.forEach)(lineIterator, (line) => {
|
|
67
|
-
line = line.trim();
|
|
68
|
-
// End of header
|
|
69
|
-
if (line === 'end_header') {
|
|
70
|
-
return true; // Returning true cancels `forEach`
|
|
71
|
-
}
|
|
72
|
-
// Ignore empty lines
|
|
73
|
-
if (line === '') {
|
|
74
|
-
// eslint-disable-next-line
|
|
75
|
-
return false; // Returning false does not cancel `forEach`
|
|
76
|
-
}
|
|
77
|
-
const lineValues = line.split(/\s+/);
|
|
78
|
-
const lineType = lineValues.shift();
|
|
79
|
-
line = lineValues.join(' ');
|
|
80
|
-
switch (lineType) {
|
|
81
|
-
case 'ply':
|
|
82
|
-
// First line magic characters, ignore
|
|
83
|
-
break;
|
|
84
|
-
case 'format':
|
|
85
|
-
header.format = lineValues[0];
|
|
86
|
-
header.version = lineValues[1];
|
|
87
|
-
break;
|
|
88
|
-
case 'comment':
|
|
89
|
-
header.comments.push(line);
|
|
90
|
-
break;
|
|
91
|
-
case 'element':
|
|
92
|
-
if (currentElement) {
|
|
93
|
-
header.elements.push(currentElement);
|
|
94
|
-
}
|
|
95
|
-
currentElement = {
|
|
96
|
-
name: lineValues[0],
|
|
97
|
-
count: parseInt(lineValues[1], 10),
|
|
98
|
-
properties: []
|
|
99
|
-
};
|
|
100
|
-
break;
|
|
101
|
-
case 'property':
|
|
102
|
-
const property = makePLYElementProperty(lineValues, options.propertyNameMapping);
|
|
103
|
-
currentElement.properties.push(property);
|
|
104
|
-
break;
|
|
105
|
-
default:
|
|
106
|
-
// eslint-disable-next-line
|
|
107
|
-
console.log('unhandled', lineType, lineValues);
|
|
108
|
-
}
|
|
109
|
-
return false;
|
|
110
|
-
});
|
|
111
|
-
if (currentElement) {
|
|
112
|
-
header.elements.push(currentElement);
|
|
113
|
-
}
|
|
114
|
-
return header;
|
|
115
|
-
}
|
|
116
|
-
function makePLYElementProperty(propertyValues, propertyNameMapping) {
|
|
117
|
-
const type = propertyValues[0];
|
|
118
|
-
switch (type) {
|
|
119
|
-
case 'list':
|
|
120
|
-
return {
|
|
121
|
-
type,
|
|
122
|
-
name: propertyValues[3],
|
|
123
|
-
countType: propertyValues[1],
|
|
124
|
-
itemType: propertyValues[2]
|
|
125
|
-
};
|
|
126
|
-
default:
|
|
127
|
-
return {
|
|
128
|
-
type,
|
|
129
|
-
name: propertyValues[1]
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
// ASCII PARSING
|
|
134
|
-
/**
|
|
135
|
-
* @param lineIterator
|
|
136
|
-
* @param header
|
|
137
|
-
* @returns
|
|
138
|
-
*/
|
|
139
|
-
async function parseASCII(lineIterator, header) {
|
|
140
|
-
// PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)
|
|
141
|
-
const attributes = {
|
|
142
|
-
indices: [],
|
|
143
|
-
vertices: [],
|
|
144
|
-
normals: [],
|
|
145
|
-
uvs: [],
|
|
146
|
-
colors: []
|
|
147
|
-
};
|
|
148
|
-
let currentElement = 0;
|
|
149
|
-
let currentElementCount = 0;
|
|
150
|
-
for await (let line of lineIterator) {
|
|
151
|
-
line = line.trim();
|
|
152
|
-
if (line !== '') {
|
|
153
|
-
if (currentElementCount >= header.elements[currentElement].count) {
|
|
154
|
-
currentElement++;
|
|
155
|
-
currentElementCount = 0;
|
|
156
|
-
}
|
|
157
|
-
const element = parsePLYElement(header.elements[currentElement].properties, line);
|
|
158
|
-
handleElement(attributes, header.elements[currentElement].name, element);
|
|
159
|
-
currentElementCount++;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return attributes;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Parses ASCII number
|
|
166
|
-
* @param n
|
|
167
|
-
* @param type
|
|
168
|
-
* @returns ASCII number
|
|
169
|
-
*/
|
|
170
|
-
// eslint-disable-next-line complexity
|
|
171
|
-
function parseASCIINumber(n, type) {
|
|
172
|
-
switch (type) {
|
|
173
|
-
case 'char':
|
|
174
|
-
case 'uchar':
|
|
175
|
-
case 'short':
|
|
176
|
-
case 'ushort':
|
|
177
|
-
case 'int':
|
|
178
|
-
case 'uint':
|
|
179
|
-
case 'int8':
|
|
180
|
-
case 'uint8':
|
|
181
|
-
case 'int16':
|
|
182
|
-
case 'uint16':
|
|
183
|
-
case 'int32':
|
|
184
|
-
case 'uint32':
|
|
185
|
-
return parseInt(n, 10);
|
|
186
|
-
case 'float':
|
|
187
|
-
case 'double':
|
|
188
|
-
case 'float32':
|
|
189
|
-
case 'float64':
|
|
190
|
-
return parseFloat(n);
|
|
191
|
-
default:
|
|
192
|
-
throw new Error(type);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Parses ASCII element
|
|
197
|
-
* @param properties
|
|
198
|
-
* @param line
|
|
199
|
-
* @returns element
|
|
200
|
-
*/
|
|
201
|
-
function parsePLYElement(properties, line) {
|
|
202
|
-
const values = line.split(/\s+/);
|
|
203
|
-
const element = {};
|
|
204
|
-
for (let i = 0; i < properties.length; i++) {
|
|
205
|
-
if (properties[i].type === 'list') {
|
|
206
|
-
const list = [];
|
|
207
|
-
const n = parseASCIINumber(values.shift(), properties[i].countType);
|
|
208
|
-
for (let j = 0; j < n; j++) {
|
|
209
|
-
list.push(parseASCIINumber(values.shift(), properties[i].itemType));
|
|
210
|
-
}
|
|
211
|
-
element[properties[i].name] = list;
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
element[properties[i].name] = parseASCIINumber(values.shift(), properties[i].type);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return element;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* @param buffer
|
|
221
|
-
* @param elementName
|
|
222
|
-
* @param element
|
|
223
|
-
*/
|
|
224
|
-
// HELPER FUNCTIONS
|
|
225
|
-
// eslint-disable-next-line complexity
|
|
226
|
-
function handleElement(buffer, elementName, element = {}) {
|
|
227
|
-
switch (elementName) {
|
|
228
|
-
case 'vertex':
|
|
229
|
-
buffer.vertices.push(element.x, element.y, element.z);
|
|
230
|
-
if ('nx' in element && 'ny' in element && 'nz' in element) {
|
|
231
|
-
buffer.normals.push(element.nx, element.ny, element.nz);
|
|
232
|
-
}
|
|
233
|
-
if ('s' in element && 't' in element) {
|
|
234
|
-
buffer.uvs.push(element.s, element.t);
|
|
235
|
-
}
|
|
236
|
-
if ('red' in element && 'green' in element && 'blue' in element) {
|
|
237
|
-
buffer.colors.push(element.red / 255.0, element.green / 255.0, element.blue / 255.0);
|
|
238
|
-
}
|
|
239
|
-
break;
|
|
240
|
-
case 'face':
|
|
241
|
-
const vertexIndices = element.vertex_indices || element.vertex_index; // issue #9338
|
|
242
|
-
if (vertexIndices.length === 3) {
|
|
243
|
-
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);
|
|
244
|
-
}
|
|
245
|
-
else if (vertexIndices.length === 4) {
|
|
246
|
-
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);
|
|
247
|
-
buffer.indices.push(vertexIndices[1], vertexIndices[2], vertexIndices[3]);
|
|
248
|
-
}
|
|
249
|
-
break;
|
|
250
|
-
default:
|
|
251
|
-
break;
|
|
252
|
-
}
|
|
253
|
-
}
|
package/dist/lib/parse-ply.js
DELETED
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parsePLY = void 0;
|
|
7
|
-
const normalize_ply_1 = __importDefault(require("./normalize-ply"));
|
|
8
|
-
/**
|
|
9
|
-
* @param data
|
|
10
|
-
* @param options
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
function parsePLY(data, options = {}) {
|
|
14
|
-
let header;
|
|
15
|
-
let attributes;
|
|
16
|
-
if (data instanceof ArrayBuffer) {
|
|
17
|
-
const text = new TextDecoder().decode(data);
|
|
18
|
-
header = parseHeader(text, options);
|
|
19
|
-
attributes = header.format === 'ascii' ? parseASCII(text, header) : parseBinary(data, header);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
header = parseHeader(data, options);
|
|
23
|
-
attributes = parseASCII(data, header);
|
|
24
|
-
}
|
|
25
|
-
return (0, normalize_ply_1.default)(header, attributes);
|
|
26
|
-
}
|
|
27
|
-
exports.parsePLY = parsePLY;
|
|
28
|
-
/**
|
|
29
|
-
* @param data
|
|
30
|
-
* @param options
|
|
31
|
-
* @returns header
|
|
32
|
-
*/
|
|
33
|
-
function parseHeader(data, options) {
|
|
34
|
-
const PLY_HEADER_PATTERN = /ply([\s\S]*)end_header\s/;
|
|
35
|
-
let headerText = '';
|
|
36
|
-
let headerLength = 0;
|
|
37
|
-
const result = PLY_HEADER_PATTERN.exec(data);
|
|
38
|
-
if (result !== null) {
|
|
39
|
-
headerText = result[1];
|
|
40
|
-
headerLength = result[0].length;
|
|
41
|
-
}
|
|
42
|
-
const lines = headerText.split('\n');
|
|
43
|
-
const header = parseHeaderLines(lines, headerLength, options);
|
|
44
|
-
return header;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* @param lines
|
|
48
|
-
* @param headerLength
|
|
49
|
-
* @param options
|
|
50
|
-
* @returns header
|
|
51
|
-
*/
|
|
52
|
-
// eslint-disable-next-line complexity
|
|
53
|
-
function parseHeaderLines(lines, headerLength, options) {
|
|
54
|
-
const header = {
|
|
55
|
-
comments: [],
|
|
56
|
-
elements: [],
|
|
57
|
-
headerLength
|
|
58
|
-
};
|
|
59
|
-
let lineType;
|
|
60
|
-
let lineValues;
|
|
61
|
-
let currentElement = null;
|
|
62
|
-
for (let i = 0; i < lines.length; i++) {
|
|
63
|
-
let line = lines[i];
|
|
64
|
-
line = line.trim();
|
|
65
|
-
if (line === '') {
|
|
66
|
-
// eslint-disable-next-line
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
lineValues = line.split(/\s+/);
|
|
70
|
-
lineType = lineValues.shift();
|
|
71
|
-
line = lineValues.join(' ');
|
|
72
|
-
switch (lineType) {
|
|
73
|
-
case 'format':
|
|
74
|
-
header.format = lineValues[0];
|
|
75
|
-
header.version = lineValues[1];
|
|
76
|
-
break;
|
|
77
|
-
case 'comment':
|
|
78
|
-
header.comments.push(line);
|
|
79
|
-
break;
|
|
80
|
-
case 'element':
|
|
81
|
-
// Start new element, store previous element
|
|
82
|
-
if (currentElement) {
|
|
83
|
-
header.elements.push(currentElement);
|
|
84
|
-
}
|
|
85
|
-
currentElement = {
|
|
86
|
-
name: lineValues[0],
|
|
87
|
-
count: parseInt(lineValues[1], 10),
|
|
88
|
-
properties: []
|
|
89
|
-
};
|
|
90
|
-
break;
|
|
91
|
-
case 'property':
|
|
92
|
-
if (currentElement) {
|
|
93
|
-
const property = makePLYElementProperty(lineValues);
|
|
94
|
-
if (options?.propertyNameMapping && property.name in options?.propertyNameMapping) {
|
|
95
|
-
property.name = options?.propertyNameMapping[property.name];
|
|
96
|
-
}
|
|
97
|
-
currentElement.properties.push(property);
|
|
98
|
-
}
|
|
99
|
-
break;
|
|
100
|
-
default:
|
|
101
|
-
// eslint-disable-next-line
|
|
102
|
-
console.log('unhandled', lineType, lineValues);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// Store in-progress element
|
|
106
|
-
if (currentElement) {
|
|
107
|
-
header.elements.push(currentElement);
|
|
108
|
-
}
|
|
109
|
-
return header;
|
|
110
|
-
}
|
|
111
|
-
/** Generate attributes arrays from the header */
|
|
112
|
-
// eslint-disable-next-line complexity
|
|
113
|
-
function getPLYAttributes(header) {
|
|
114
|
-
// TODO Generate only the attribute arrays actually in the header
|
|
115
|
-
const attributes = {
|
|
116
|
-
indices: [],
|
|
117
|
-
vertices: [],
|
|
118
|
-
normals: [],
|
|
119
|
-
uvs: [],
|
|
120
|
-
colors: []
|
|
121
|
-
};
|
|
122
|
-
for (const element of header.elements) {
|
|
123
|
-
if (element.name === 'vertex') {
|
|
124
|
-
for (const property of element.properties) {
|
|
125
|
-
switch (property.name) {
|
|
126
|
-
case 'x':
|
|
127
|
-
case 'y':
|
|
128
|
-
case 'z':
|
|
129
|
-
case 'nx':
|
|
130
|
-
case 'ny':
|
|
131
|
-
case 'nz':
|
|
132
|
-
case 's':
|
|
133
|
-
case 't':
|
|
134
|
-
case 'red':
|
|
135
|
-
case 'green':
|
|
136
|
-
case 'blue':
|
|
137
|
-
break;
|
|
138
|
-
default:
|
|
139
|
-
// Add any non-geometry attributes
|
|
140
|
-
attributes[property.name] = [];
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return attributes;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* @param propertyValues
|
|
150
|
-
* @returns property of ply element
|
|
151
|
-
*/
|
|
152
|
-
function makePLYElementProperty(propertyValues) {
|
|
153
|
-
const type = propertyValues[0];
|
|
154
|
-
switch (type) {
|
|
155
|
-
case 'list':
|
|
156
|
-
return {
|
|
157
|
-
type,
|
|
158
|
-
name: propertyValues[3],
|
|
159
|
-
countType: propertyValues[1],
|
|
160
|
-
itemType: propertyValues[2]
|
|
161
|
-
};
|
|
162
|
-
default:
|
|
163
|
-
return {
|
|
164
|
-
type,
|
|
165
|
-
name: propertyValues[1]
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Parses ASCII number
|
|
171
|
-
* @param n
|
|
172
|
-
* @param type
|
|
173
|
-
* @returns
|
|
174
|
-
*/
|
|
175
|
-
// eslint-disable-next-line complexity
|
|
176
|
-
function parseASCIINumber(n, type) {
|
|
177
|
-
switch (type) {
|
|
178
|
-
case 'char':
|
|
179
|
-
case 'uchar':
|
|
180
|
-
case 'short':
|
|
181
|
-
case 'ushort':
|
|
182
|
-
case 'int':
|
|
183
|
-
case 'uint':
|
|
184
|
-
case 'int8':
|
|
185
|
-
case 'uint8':
|
|
186
|
-
case 'int16':
|
|
187
|
-
case 'uint16':
|
|
188
|
-
case 'int32':
|
|
189
|
-
case 'uint32':
|
|
190
|
-
return parseInt(n, 10);
|
|
191
|
-
case 'float':
|
|
192
|
-
case 'double':
|
|
193
|
-
case 'float32':
|
|
194
|
-
case 'float64':
|
|
195
|
-
return parseFloat(n);
|
|
196
|
-
default:
|
|
197
|
-
throw new Error(type);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* @param properties
|
|
202
|
-
* @param line
|
|
203
|
-
* @returns ASCII element
|
|
204
|
-
*/
|
|
205
|
-
function parsePLYElement(properties, line) {
|
|
206
|
-
const values = line.split(/\s+/);
|
|
207
|
-
const element = {};
|
|
208
|
-
for (let i = 0; i < properties.length; i++) {
|
|
209
|
-
if (properties[i].type === 'list') {
|
|
210
|
-
const list = [];
|
|
211
|
-
const n = parseASCIINumber(values.shift(), properties[i].countType);
|
|
212
|
-
for (let j = 0; j < n; j++) {
|
|
213
|
-
list.push(parseASCIINumber(values.shift(), properties[i].itemType));
|
|
214
|
-
}
|
|
215
|
-
element[properties[i].name] = list;
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
element[properties[i].name] = parseASCIINumber(values.shift(), properties[i].type);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return element;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* @param data
|
|
225
|
-
* @param header
|
|
226
|
-
* @returns [attributes]
|
|
227
|
-
*/
|
|
228
|
-
function parseASCII(data, header) {
|
|
229
|
-
// PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)
|
|
230
|
-
const attributes = getPLYAttributes(header);
|
|
231
|
-
let result;
|
|
232
|
-
const patternBody = /end_header\s([\s\S]*)$/;
|
|
233
|
-
let body = '';
|
|
234
|
-
if ((result = patternBody.exec(data)) !== null) {
|
|
235
|
-
body = result[1];
|
|
236
|
-
}
|
|
237
|
-
const lines = body.split('\n');
|
|
238
|
-
let currentElement = 0;
|
|
239
|
-
let currentElementCount = 0;
|
|
240
|
-
for (let i = 0; i < lines.length; i++) {
|
|
241
|
-
let line = lines[i];
|
|
242
|
-
line = line.trim();
|
|
243
|
-
if (line !== '') {
|
|
244
|
-
if (currentElementCount >= header.elements[currentElement].count) {
|
|
245
|
-
currentElement++;
|
|
246
|
-
currentElementCount = 0;
|
|
247
|
-
}
|
|
248
|
-
const element = parsePLYElement(header.elements[currentElement].properties, line);
|
|
249
|
-
handleElement(attributes, header.elements[currentElement].name, element);
|
|
250
|
-
currentElementCount++;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return attributes;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* @param buffer
|
|
257
|
-
* @param elementName
|
|
258
|
-
* @param element
|
|
259
|
-
*/
|
|
260
|
-
// eslint-disable-next-line complexity
|
|
261
|
-
function handleElement(buffer, elementName, element = {}) {
|
|
262
|
-
if (elementName === 'vertex') {
|
|
263
|
-
for (const propertyName of Object.keys(element)) {
|
|
264
|
-
switch (propertyName) {
|
|
265
|
-
case 'x':
|
|
266
|
-
buffer.vertices.push(element.x, element.y, element.z);
|
|
267
|
-
break;
|
|
268
|
-
case 'y':
|
|
269
|
-
case 'z':
|
|
270
|
-
break;
|
|
271
|
-
case 'nx':
|
|
272
|
-
if ('nx' in element && 'ny' in element && 'nz' in element) {
|
|
273
|
-
buffer.normals.push(element.nx, element.ny, element.nz);
|
|
274
|
-
}
|
|
275
|
-
break;
|
|
276
|
-
case 'ny':
|
|
277
|
-
case 'nz':
|
|
278
|
-
break;
|
|
279
|
-
case 's':
|
|
280
|
-
if ('s' in element && 't' in element) {
|
|
281
|
-
buffer.uvs.push(element.s, element.t);
|
|
282
|
-
}
|
|
283
|
-
break;
|
|
284
|
-
case 't':
|
|
285
|
-
break;
|
|
286
|
-
case 'red':
|
|
287
|
-
if ('red' in element && 'green' in element && 'blue' in element) {
|
|
288
|
-
buffer.colors.push(element.red, element.green, element.blue);
|
|
289
|
-
}
|
|
290
|
-
break;
|
|
291
|
-
case 'green':
|
|
292
|
-
case 'blue':
|
|
293
|
-
break;
|
|
294
|
-
default:
|
|
295
|
-
buffer[propertyName].push(element[propertyName]);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
else if (elementName === 'face') {
|
|
300
|
-
const vertexIndices = element.vertex_indices || element.vertex_index; // issue #9338
|
|
301
|
-
if (vertexIndices.length === 3) {
|
|
302
|
-
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);
|
|
303
|
-
}
|
|
304
|
-
else if (vertexIndices.length === 4) {
|
|
305
|
-
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);
|
|
306
|
-
buffer.indices.push(vertexIndices[1], vertexIndices[2], vertexIndices[3]);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Reads binary data
|
|
312
|
-
* @param dataview
|
|
313
|
-
* @param at
|
|
314
|
-
* @param type
|
|
315
|
-
* @param littleEndian
|
|
316
|
-
* @returns [number, number]
|
|
317
|
-
*/
|
|
318
|
-
// eslint-disable-next-line complexity
|
|
319
|
-
function binaryRead(dataview, at, type, littleEndian) {
|
|
320
|
-
switch (type) {
|
|
321
|
-
// corespondences for non-specific length types here match rply:
|
|
322
|
-
case 'int8':
|
|
323
|
-
case 'char':
|
|
324
|
-
return [dataview.getInt8(at), 1];
|
|
325
|
-
case 'uint8':
|
|
326
|
-
case 'uchar':
|
|
327
|
-
return [dataview.getUint8(at), 1];
|
|
328
|
-
case 'int16':
|
|
329
|
-
case 'short':
|
|
330
|
-
return [dataview.getInt16(at, littleEndian), 2];
|
|
331
|
-
case 'uint16':
|
|
332
|
-
case 'ushort':
|
|
333
|
-
return [dataview.getUint16(at, littleEndian), 2];
|
|
334
|
-
case 'int32':
|
|
335
|
-
case 'int':
|
|
336
|
-
return [dataview.getInt32(at, littleEndian), 4];
|
|
337
|
-
case 'uint32':
|
|
338
|
-
case 'uint':
|
|
339
|
-
return [dataview.getUint32(at, littleEndian), 4];
|
|
340
|
-
case 'float32':
|
|
341
|
-
case 'float':
|
|
342
|
-
return [dataview.getFloat32(at, littleEndian), 4];
|
|
343
|
-
case 'float64':
|
|
344
|
-
case 'double':
|
|
345
|
-
return [dataview.getFloat64(at, littleEndian), 8];
|
|
346
|
-
default:
|
|
347
|
-
throw new Error(type);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Reads binary data
|
|
352
|
-
* @param dataview
|
|
353
|
-
* @param at
|
|
354
|
-
* @param properties
|
|
355
|
-
* @param littleEndian
|
|
356
|
-
* @returns [object, number]
|
|
357
|
-
*/
|
|
358
|
-
function binaryReadElement(dataview, at, properties, littleEndian) {
|
|
359
|
-
const element = {};
|
|
360
|
-
let result;
|
|
361
|
-
let read = 0;
|
|
362
|
-
for (let i = 0; i < properties.length; i++) {
|
|
363
|
-
if (properties[i].type === 'list') {
|
|
364
|
-
const list = [];
|
|
365
|
-
result = binaryRead(dataview, at + read, properties[i].countType, littleEndian);
|
|
366
|
-
const n = result[0];
|
|
367
|
-
read += result[1];
|
|
368
|
-
for (let j = 0; j < n; j++) {
|
|
369
|
-
result = binaryRead(dataview, at + read, properties[i].itemType, littleEndian);
|
|
370
|
-
// @ts-ignore
|
|
371
|
-
list.push(result[0]);
|
|
372
|
-
read += result[1];
|
|
373
|
-
}
|
|
374
|
-
element[properties[i].name] = list;
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
result = binaryRead(dataview, at + read, properties[i].type, littleEndian);
|
|
378
|
-
element[properties[i].name] = result[0];
|
|
379
|
-
read += result[1];
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
return [element, read];
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Parses binary data
|
|
386
|
-
* @param data
|
|
387
|
-
* @param header
|
|
388
|
-
* @returns [attributes] of data
|
|
389
|
-
*/
|
|
390
|
-
function parseBinary(data, header) {
|
|
391
|
-
const attributes = getPLYAttributes(header);
|
|
392
|
-
const littleEndian = header.format === 'binary_little_endian';
|
|
393
|
-
const body = new DataView(data, header.headerLength);
|
|
394
|
-
let result;
|
|
395
|
-
let loc = 0;
|
|
396
|
-
for (let currentElement = 0; currentElement < header.elements.length; currentElement++) {
|
|
397
|
-
const count = header.elements[currentElement].count;
|
|
398
|
-
for (let currentElementCount = 0; currentElementCount < count; currentElementCount++) {
|
|
399
|
-
result = binaryReadElement(body, loc, header.elements[currentElement].properties, littleEndian);
|
|
400
|
-
loc += result[1];
|
|
401
|
-
const element = result[0];
|
|
402
|
-
handleElement(attributes, header.elements[currentElement].name, element);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
return attributes;
|
|
406
|
-
}
|
package/dist/lib/ply-types.js
DELETED
package/dist/ply-loader.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._typecheckPLYLoader = exports.PLYLoader = void 0;
|
|
4
|
-
// __VERSION__ is injected by babel-plugin-version-inline
|
|
5
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
6
|
-
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
7
|
-
/**
|
|
8
|
-
* Worker loader for PLY - Polygon File Format (aka Stanford Triangle Format)'
|
|
9
|
-
* links: ['http://paulbourke.net/dataformats/ply/',
|
|
10
|
-
* 'https://en.wikipedia.org/wiki/PLY_(file_format)']
|
|
11
|
-
*/
|
|
12
|
-
exports.PLYLoader = {
|
|
13
|
-
name: 'PLY',
|
|
14
|
-
id: 'ply',
|
|
15
|
-
module: 'ply',
|
|
16
|
-
// shapes: ['mesh', 'gltf', 'columnar-table'],
|
|
17
|
-
version: VERSION,
|
|
18
|
-
worker: true,
|
|
19
|
-
extensions: ['ply'],
|
|
20
|
-
mimeTypes: ['text/plain', 'application/octet-stream'],
|
|
21
|
-
text: true,
|
|
22
|
-
binary: true,
|
|
23
|
-
tests: ['ply'],
|
|
24
|
-
options: {
|
|
25
|
-
ply: {}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
exports._typecheckPLYLoader = exports.PLYLoader;
|