@loaders.gl/ply 4.2.0-alpha.4 → 4.2.0-alpha.6
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/dist.dev.js +54 -57
- package/dist/dist.min.js +12 -0
- package/dist/index.cjs +14 -18
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -6
- package/dist/lib/get-ply-schema.d.ts +1 -1
- package/dist/lib/get-ply-schema.d.ts.map +1 -1
- package/dist/lib/get-ply-schema.js +28 -17
- package/dist/lib/normalize-ply.d.ts +1 -1
- package/dist/lib/normalize-ply.d.ts.map +1 -1
- package/dist/lib/normalize-ply.js +68 -77
- package/dist/lib/parse-ply-in-batches.d.ts +1 -1
- package/dist/lib/parse-ply-in-batches.d.ts.map +1 -1
- package/dist/lib/parse-ply-in-batches.js +226 -157
- package/dist/lib/parse-ply.d.ts +1 -1
- package/dist/lib/parse-ply.d.ts.map +1 -1
- package/dist/lib/parse-ply.js +365 -285
- package/dist/lib/ply-types.js +0 -1
- package/dist/ply-loader.d.ts +1 -1
- package/dist/ply-loader.d.ts.map +1 -1
- package/dist/ply-loader.js +22 -15
- package/dist/ply-worker.js +4 -2
- package/dist/workers/ply-worker.js +0 -1
- package/package.json +10 -7
- package/dist/index.js.map +0 -1
- package/dist/lib/get-ply-schema.js.map +0 -1
- package/dist/lib/normalize-ply.js.map +0 -1
- package/dist/lib/parse-ply-in-batches.js.map +0 -1
- package/dist/lib/parse-ply.js.map +0 -1
- package/dist/lib/ply-types.js.map +0 -1
- package/dist/ply-loader.js.map +0 -1
- package/dist/workers/ply-worker.js.map +0 -1
package/dist/dist.dev.js
CHANGED
|
@@ -2,14 +2,19 @@
|
|
|
2
2
|
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
3
|
module.exports = factory();
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
-
else if (typeof exports === 'object') exports['
|
|
6
|
-
else root['
|
|
5
|
+
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
|
+
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
7
|
"use strict";
|
|
8
8
|
var __exports__ = (() => {
|
|
9
|
+
var __create = Object.create;
|
|
9
10
|
var __defProp = Object.defineProperty;
|
|
10
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
14
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
16
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
17
|
+
};
|
|
13
18
|
var __export = (target, all) => {
|
|
14
19
|
for (var name in all)
|
|
15
20
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -22,21 +27,39 @@ var __exports__ = (() => {
|
|
|
22
27
|
}
|
|
23
28
|
return to;
|
|
24
29
|
};
|
|
30
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
31
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
34
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
35
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
36
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
+
mod
|
|
38
|
+
));
|
|
25
39
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
40
|
|
|
27
|
-
//
|
|
28
|
-
var
|
|
29
|
-
|
|
41
|
+
// external-global-plugin:@loaders.gl/core
|
|
42
|
+
var require_core = __commonJS({
|
|
43
|
+
"external-global-plugin:@loaders.gl/core"(exports, module) {
|
|
44
|
+
module.exports = globalThis.loaders;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// bundle.ts
|
|
49
|
+
var bundle_exports = {};
|
|
50
|
+
__export(bundle_exports, {
|
|
30
51
|
PLYLoader: () => PLYLoader2,
|
|
31
52
|
PLYWorkerLoader: () => PLYLoader
|
|
32
53
|
});
|
|
54
|
+
__reExport(bundle_exports, __toESM(require_core(), 1));
|
|
33
55
|
|
|
34
56
|
// src/ply-loader.ts
|
|
35
|
-
var VERSION =
|
|
57
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
36
58
|
var PLYLoader = {
|
|
37
59
|
name: "PLY",
|
|
38
60
|
id: "ply",
|
|
39
61
|
module: "ply",
|
|
62
|
+
// shapes: ['mesh', 'gltf', 'columnar-table'],
|
|
40
63
|
version: VERSION,
|
|
41
64
|
worker: true,
|
|
42
65
|
extensions: ["ply"],
|
|
@@ -95,30 +118,23 @@ var __exports__ = (() => {
|
|
|
95
118
|
maxY = y > maxY ? y : maxY;
|
|
96
119
|
maxZ = z > maxZ ? z : maxZ;
|
|
97
120
|
}
|
|
98
|
-
return [
|
|
121
|
+
return [
|
|
122
|
+
[minX, minY, minZ],
|
|
123
|
+
[maxX, maxY, maxZ]
|
|
124
|
+
];
|
|
99
125
|
}
|
|
100
126
|
|
|
101
127
|
// ../schema/src/lib/mesh/deduce-mesh-schema.ts
|
|
102
128
|
function deduceMeshSchema(attributes, metadata = {}) {
|
|
103
129
|
const fields = deduceMeshFields(attributes);
|
|
104
|
-
return {
|
|
105
|
-
fields,
|
|
106
|
-
metadata
|
|
107
|
-
};
|
|
130
|
+
return { fields, metadata };
|
|
108
131
|
}
|
|
109
132
|
function deduceMeshField(name, attribute, optionalMetadata) {
|
|
110
133
|
const type = getDataTypeFromTypedArray(attribute.value);
|
|
111
134
|
const metadata = optionalMetadata ? optionalMetadata : makeMeshAttributeMetadata(attribute);
|
|
112
135
|
return {
|
|
113
136
|
name,
|
|
114
|
-
type: {
|
|
115
|
-
type: "fixed-size-list",
|
|
116
|
-
listSize: attribute.size,
|
|
117
|
-
children: [{
|
|
118
|
-
name: "value",
|
|
119
|
-
type
|
|
120
|
-
}]
|
|
121
|
-
},
|
|
137
|
+
type: { type: "fixed-size-list", listSize: attribute.size, children: [{ name: "value", type }] },
|
|
122
138
|
nullable: false,
|
|
123
139
|
metadata
|
|
124
140
|
};
|
|
@@ -185,18 +201,12 @@ var __exports__ = (() => {
|
|
|
185
201
|
},
|
|
186
202
|
schema,
|
|
187
203
|
attributes,
|
|
188
|
-
indices: {
|
|
189
|
-
value: new Uint32Array(0),
|
|
190
|
-
size: 0
|
|
191
|
-
},
|
|
204
|
+
indices: { value: new Uint32Array(0), size: 0 },
|
|
192
205
|
mode,
|
|
193
206
|
topology
|
|
194
207
|
};
|
|
195
208
|
if (plyAttributes.indices.length > 0) {
|
|
196
|
-
plyMesh.indices = {
|
|
197
|
-
value: new Uint32Array(plyAttributes.indices),
|
|
198
|
-
size: 1
|
|
199
|
-
};
|
|
209
|
+
plyMesh.indices = { value: new Uint32Array(plyAttributes.indices), size: 1 };
|
|
200
210
|
}
|
|
201
211
|
return plyMesh;
|
|
202
212
|
}
|
|
@@ -206,45 +216,29 @@ var __exports__ = (() => {
|
|
|
206
216
|
switch (attributeName) {
|
|
207
217
|
case "vertices":
|
|
208
218
|
if (attributes.vertices.length > 0) {
|
|
209
|
-
accessors.POSITION = {
|
|
210
|
-
value: new Float32Array(attributes.vertices),
|
|
211
|
-
size: 3
|
|
212
|
-
};
|
|
219
|
+
accessors.POSITION = { value: new Float32Array(attributes.vertices), size: 3 };
|
|
213
220
|
}
|
|
214
221
|
break;
|
|
215
222
|
case "normals":
|
|
216
223
|
if (attributes.normals.length > 0) {
|
|
217
|
-
accessors.NORMAL = {
|
|
218
|
-
value: new Float32Array(attributes.normals),
|
|
219
|
-
size: 3
|
|
220
|
-
};
|
|
224
|
+
accessors.NORMAL = { value: new Float32Array(attributes.normals), size: 3 };
|
|
221
225
|
}
|
|
222
226
|
break;
|
|
223
227
|
case "uvs":
|
|
224
228
|
if (attributes.uvs.length > 0) {
|
|
225
|
-
accessors.TEXCOORD_0 = {
|
|
226
|
-
value: new Float32Array(attributes.uvs),
|
|
227
|
-
size: 2
|
|
228
|
-
};
|
|
229
|
+
accessors.TEXCOORD_0 = { value: new Float32Array(attributes.uvs), size: 2 };
|
|
229
230
|
}
|
|
230
231
|
break;
|
|
231
232
|
case "colors":
|
|
232
233
|
if (attributes.colors.length > 0) {
|
|
233
|
-
accessors.COLOR_0 = {
|
|
234
|
-
value: new Uint8Array(attributes.colors),
|
|
235
|
-
size: 3,
|
|
236
|
-
normalized: true
|
|
237
|
-
};
|
|
234
|
+
accessors.COLOR_0 = { value: new Uint8Array(attributes.colors), size: 3, normalized: true };
|
|
238
235
|
}
|
|
239
236
|
break;
|
|
240
237
|
case "indices":
|
|
241
238
|
break;
|
|
242
239
|
default:
|
|
243
240
|
if (attributes[attributeName].length > 0) {
|
|
244
|
-
accessors[attributeName] = {
|
|
245
|
-
value: new Float32Array(attributes[attributeName]),
|
|
246
|
-
size: 1
|
|
247
|
-
};
|
|
241
|
+
accessors[attributeName] = { value: new Float32Array(attributes[attributeName]), size: 1 };
|
|
248
242
|
}
|
|
249
243
|
break;
|
|
250
244
|
}
|
|
@@ -560,7 +554,12 @@ var __exports__ = (() => {
|
|
|
560
554
|
for (let currentElement2 = 0; currentElement2 < header.elements.length; currentElement2++) {
|
|
561
555
|
const count = header.elements[currentElement2].count;
|
|
562
556
|
for (let currentElementCount = 0; currentElementCount < count; currentElementCount++) {
|
|
563
|
-
result = binaryReadElement(
|
|
557
|
+
result = binaryReadElement(
|
|
558
|
+
body,
|
|
559
|
+
loc,
|
|
560
|
+
header.elements[currentElement2].properties,
|
|
561
|
+
littleEndian
|
|
562
|
+
);
|
|
564
563
|
loc += result[1];
|
|
565
564
|
const element = result[0];
|
|
566
565
|
handleElement(attributes, header.elements[currentElement2].name, element);
|
|
@@ -573,9 +572,7 @@ var __exports__ = (() => {
|
|
|
573
572
|
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
574
573
|
const textDecoder = new TextDecoder(void 0, options);
|
|
575
574
|
for await (const arrayBuffer of arrayBufferIterator) {
|
|
576
|
-
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, {
|
|
577
|
-
stream: true
|
|
578
|
-
});
|
|
575
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
579
576
|
}
|
|
580
577
|
}
|
|
581
578
|
async function* makeLineIterator(textIterator) {
|
|
@@ -597,10 +594,7 @@ var __exports__ = (() => {
|
|
|
597
594
|
// ../loader-utils/src/lib/iterators/async-iteration.ts
|
|
598
595
|
async function forEach(iterator, visitor) {
|
|
599
596
|
while (true) {
|
|
600
|
-
const {
|
|
601
|
-
done,
|
|
602
|
-
value
|
|
603
|
-
} = await iterator.next();
|
|
597
|
+
const { done, value } = await iterator.next();
|
|
604
598
|
if (done) {
|
|
605
599
|
iterator.return();
|
|
606
600
|
return;
|
|
@@ -631,6 +625,7 @@ var __exports__ = (() => {
|
|
|
631
625
|
const header = {
|
|
632
626
|
comments: [],
|
|
633
627
|
elements: []
|
|
628
|
+
// headerLength
|
|
634
629
|
};
|
|
635
630
|
await forEach(lineIterator, (line) => {
|
|
636
631
|
line = line.trim();
|
|
@@ -790,12 +785,14 @@ var __exports__ = (() => {
|
|
|
790
785
|
// src/index.ts
|
|
791
786
|
var PLYLoader2 = {
|
|
792
787
|
...PLYLoader,
|
|
788
|
+
// Note: parsePLY supports both text and binary
|
|
793
789
|
parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
|
|
790
|
+
// TODO - this may not detect text correctly?
|
|
794
791
|
parseTextSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
|
|
795
792
|
parseSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
|
|
796
793
|
parseInBatches: (arrayBuffer, options) => parsePLYInBatches(arrayBuffer, options?.ply)
|
|
797
794
|
};
|
|
798
|
-
return __toCommonJS(
|
|
795
|
+
return __toCommonJS(bundle_exports);
|
|
799
796
|
})();
|
|
800
797
|
return __exports__;
|
|
801
798
|
});
|
package/dist/dist.min.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
+
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
|
+
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
|
+
"use strict";var __exports__=(()=>{var R=Object.create;var x=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var V=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),X=(e,t)=>{for(var r in t)x(e,r,{get:t[r],enumerable:!0})},h=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of j(t))!J.call(e,o)&&o!==r&&x(e,o,{get:()=>t[o],enumerable:!(n=U(t,o))||n.enumerable});return e},g=(e,t,r)=>(h(e,t,"default"),r&&h(r,t,"default")),Z=(e,t,r)=>(r=e!=null?R(W(e)):{},h(t||!e||!e.__esModule?x(r,"default",{value:e,enumerable:!0}):r,e)),q=e=>h(x({},"__esModule",{value:!0}),e);var P=V((ue,v)=>{v.exports=globalThis.loaders});var d={};X(d,{PLYLoader:()=>le,PLYWorkerLoader:()=>A});g(d,Z(P(),1));var Q="4.2.0-alpha.5",A={name:"PLY",id:"ply",module:"ply",version:Q,worker:!0,extensions:["ply"],mimeTypes:["text/plain","application/octet-stream"],text:!0,binary:!0,tests:["ply"],options:{ply:{}}};function N(e){switch(e.constructor){case Int8Array:return"int8";case Uint8Array:case Uint8ClampedArray:return"uint8";case Int16Array:return"int16";case Uint16Array:return"uint16";case Int32Array:return"int32";case Uint32Array:return"uint32";case Float32Array:return"float32";case Float64Array:return"float64";default:return"null"}}function k(e){let t=1/0,r=1/0,n=1/0,o=-1/0,a=-1/0,s=-1/0,i=e.POSITION?e.POSITION.value:[],l=i&&i.length;for(let c=0;c<l;c+=3){let f=i[c],u=i[c+1],y=i[c+2];t=f<t?f:t,r=u<r?u:r,n=y<n?y:n,o=f>o?f:o,a=u>a?u:a,s=y>s?y:s}return[[t,r,n],[o,a,s]]}function b(e,t={}){return{fields:$(e),metadata:t}}function z(e,t,r){let n=N(t.value),o=r||D(t);return{name:e,type:{type:"fixed-size-list",listSize:t.size,children:[{name:"value",type:n}]},nullable:!1,metadata:o}}function $(e){let t=[];for(let r in e){let n=e[r];t.push(z(r,n))}return t}function D(e){let t={};return"byteOffset"in e&&(t.byteOffset=e.byteOffset.toString(10)),"byteStride"in e&&(t.byteStride=e.byteStride.toString(10)),"normalized"in e&&(t.normalized=e.normalized.toString()),t}function E(e,t){let r=G(e);return b(t,r)}function G(e){let t={};return t.ply_comments=JSON.stringify(e.comments),t.ply_elements=JSON.stringify(e.elements),e.format!==void 0&&(t.ply_format=e.format),e.version!==void 0&&(t.ply_version=e.version),e.headerLength!==void 0&&(t.ply_headerLength=e.headerLength.toString(10)),t}function p(e,t,r){let n=K(t),o=k(n),a=t.indices.length||t.vertices.length/3,s=t.indices&&t.indices.length>0,i=s?4:0,l=s?"triangle-list":"point-list",c=E(e,n),f={loader:"ply",loaderData:e,header:{vertexCount:a,boundingBox:o},schema:c,attributes:n,indices:{value:new Uint32Array(0),size:0},mode:i,topology:l};return t.indices.length>0&&(f.indices={value:new Uint32Array(t.indices),size:1}),f}function K(e){let t={};for(let r of Object.keys(e))switch(r){case"vertices":e.vertices.length>0&&(t.POSITION={value:new Float32Array(e.vertices),size:3});break;case"normals":e.normals.length>0&&(t.NORMAL={value:new Float32Array(e.normals),size:3});break;case"uvs":e.uvs.length>0&&(t.TEXCOORD_0={value:new Float32Array(e.uvs),size:2});break;case"colors":e.colors.length>0&&(t.COLOR_0={value:new Uint8Array(e.colors),size:3,normalized:!0});break;case"indices":break;default:e[r].length>0&&(t[r]={value:new Float32Array(e[r]),size:1});break}return t}function T(e,t={}){let r,n;if(e instanceof ArrayBuffer){let o=new TextDecoder().decode(e);r=M(o,t),n=r.format==="ascii"?O(o,r):ne(e,r)}else r=M(e,t),n=O(e,r);return p(r,n)}function M(e,t){let r=/ply([\s\S]*)end_header\s/,n="",o=0,a=r.exec(e);a!==null&&(n=a[1],o=a[0].length);let s=n.split(`
|
|
8
|
+
`);return H(s,o,t)}function H(e,t,r){let n={comments:[],elements:[],headerLength:t},o,a,s=null;for(let i=0;i<e.length;i++){let l=e[i];if(l=l.trim(),l!=="")switch(a=l.split(/\s+/),o=a.shift(),l=a.join(" "),o){case"format":n.format=a[0],n.version=a[1];break;case"comment":n.comments.push(l);break;case"element":s&&n.elements.push(s),s={name:a[0],count:parseInt(a[1],10),properties:[]};break;case"property":if(s){let c=ee(a);r?.propertyNameMapping&&c.name in r?.propertyNameMapping&&(c.name=r?.propertyNameMapping[c.name]),s.properties.push(c)}break;default:console.log("unhandled",o,a)}}return s&&n.elements.push(s),n}function Y(e){let t={indices:[],vertices:[],normals:[],uvs:[],colors:[]};for(let r of e.elements)if(r.name==="vertex")for(let n of r.properties)switch(n.name){case"x":case"y":case"z":case"nx":case"ny":case"nz":case"s":case"t":case"red":case"green":case"blue":break;default:t[n.name]=[];break}return t}function ee(e){let t=e[0];switch(t){case"list":return{type:t,name:e[3],countType:e[1],itemType:e[2]};default:return{type:t,name:e[1]}}}function I(e,t){switch(t){case"char":case"uchar":case"short":case"ushort":case"int":case"uint":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":return parseInt(e,10);case"float":case"double":case"float32":case"float64":return parseFloat(e);default:throw new Error(t)}}function te(e,t){let r=t.split(/\s+/),n={};for(let o=0;o<e.length;o++)if(e[o].type==="list"){let a=[],s=I(r.shift(),e[o].countType);for(let i=0;i<s;i++)a.push(I(r.shift(),e[o].itemType));n[e[o].name]=a}else n[e[o].name]=I(r.shift(),e[o].type);return n}function O(e,t){let r=Y(t),n,o=/end_header\s([\s\S]*)$/,a="";(n=o.exec(e))!==null&&(a=n[1]);let s=a.split(`
|
|
9
|
+
`),i=0,l=0;for(let c=0;c<s.length;c++){let f=s[c];if(f=f.trim(),f!==""){l>=t.elements[i].count&&(i++,l=0);let u=te(t.elements[i].properties,f);C(r,t.elements[i].name,u),l++}}return r}function C(e,t,r={}){if(t==="vertex")for(let n of Object.keys(r))switch(n){case"x":e.vertices.push(r.x,r.y,r.z);break;case"y":case"z":break;case"nx":"nx"in r&&"ny"in r&&"nz"in r&&e.normals.push(r.nx,r.ny,r.nz);break;case"ny":case"nz":break;case"s":"s"in r&&"t"in r&&e.uvs.push(r.s,r.t);break;case"t":break;case"red":"red"in r&&"green"in r&&"blue"in r&&e.colors.push(r.red,r.green,r.blue);break;case"green":case"blue":break;default:e[n].push(r[n])}else if(t==="face"){let n=r.vertex_indices||r.vertex_index;n.length===3?e.indices.push(n[0],n[1],n[2]):n.length===4&&(e.indices.push(n[0],n[1],n[3]),e.indices.push(n[1],n[2],n[3]))}}function w(e,t,r,n){switch(r){case"int8":case"char":return[e.getInt8(t),1];case"uint8":case"uchar":return[e.getUint8(t),1];case"int16":case"short":return[e.getInt16(t,n),2];case"uint16":case"ushort":return[e.getUint16(t,n),2];case"int32":case"int":return[e.getInt32(t,n),4];case"uint32":case"uint":return[e.getUint32(t,n),4];case"float32":case"float":return[e.getFloat32(t,n),4];case"float64":case"double":return[e.getFloat64(t,n),8];default:throw new Error(r)}}function re(e,t,r,n){let o={},a,s=0;for(let i=0;i<r.length;i++)if(r[i].type==="list"){let l=[];a=w(e,t+s,r[i].countType,n);let c=a[0];s+=a[1];for(let f=0;f<c;f++)a=w(e,t+s,r[i].itemType,n),l.push(a[0]),s+=a[1];o[r[i].name]=l}else a=w(e,t+s,r[i].type,n),o[r[i].name]=a[0],s+=a[1];return[o,s]}function ne(e,t){let r=Y(t),n=t.format==="binary_little_endian",o=new DataView(e,t.headerLength),a,s=0;for(let i=0;i<t.elements.length;i++){let l=t.elements[i].count;for(let c=0;c<l;c++){a=re(o,s,t.elements[i].properties,n),s+=a[1];let f=a[0];C(r,t.elements[i].name,f)}}return r}async function*L(e,t={}){let r=new TextDecoder(void 0,t);for await(let n of e)yield typeof n=="string"?n:r.decode(n,{stream:!0})}async function*S(e){let t="";for await(let r of e){t+=r;let n;for(;(n=t.indexOf(`
|
|
10
|
+
`))>=0;){let o=t.slice(0,n+1);t=t.slice(n+1),yield o}}t.length>0&&(yield t)}async function F(e,t){for(;;){let{done:r,value:n}=await e.next();if(r){e.return();return}if(t(n))return}}var m;async function*_(e,t){let r=S(L(e)),n=await oe(r,t),o;switch(n.format){case"ascii":o=await se(r,n);break;default:throw new Error("Binary PLY can not yet be parsed in streaming mode")}yield p(n,o,t)}async function oe(e,t){let r={comments:[],elements:[]};return await F(e,n=>{if(n=n.trim(),n==="end_header")return!0;if(n==="")return!1;let o=n.split(/\s+/),a=o.shift();switch(n=o.join(" "),a){case"ply":break;case"format":r.format=o[0],r.version=o[1];break;case"comment":r.comments.push(n);break;case"element":m&&r.elements.push(m),m={name:o[0],count:parseInt(o[1],10),properties:[]};break;case"property":let s=ae(o,t.propertyNameMapping);m.properties.push(s);break;default:console.log("unhandled",a,o)}return!1}),m&&r.elements.push(m),r}function ae(e,t){let r=e[0];switch(r){case"list":return{type:r,name:e[3],countType:e[1],itemType:e[2]};default:return{type:r,name:e[1]}}}async function se(e,t){let r={indices:[],vertices:[],normals:[],uvs:[],colors:[]},n=0,o=0;for await(let a of e)if(a=a.trim(),a!==""){o>=t.elements[n].count&&(n++,o=0);let s=ie(t.elements[n].properties,a);ce(r,t.elements[n].name,s),o++}return r}function B(e,t){switch(t){case"char":case"uchar":case"short":case"ushort":case"int":case"uint":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":return parseInt(e,10);case"float":case"double":case"float32":case"float64":return parseFloat(e);default:throw new Error(t)}}function ie(e,t){let r=t.split(/\s+/),n={};for(let o=0;o<e.length;o++)if(e[o].type==="list"){let a=[],s=B(r.shift(),e[o].countType);for(let i=0;i<s;i++)a.push(B(r.shift(),e[o].itemType));n[e[o].name]=a}else n[e[o].name]=B(r.shift(),e[o].type);return n}function ce(e,t,r={}){switch(t){case"vertex":e.vertices.push(r.x,r.y,r.z),"nx"in r&&"ny"in r&&"nz"in r&&e.normals.push(r.nx,r.ny,r.nz),"s"in r&&"t"in r&&e.uvs.push(r.s,r.t),"red"in r&&"green"in r&&"blue"in r&&e.colors.push(r.red/255,r.green/255,r.blue/255);break;case"face":let n=r.vertex_indices||r.vertex_index;n.length===3?e.indices.push(n[0],n[1],n[2]):n.length===4&&(e.indices.push(n[0],n[1],n[3]),e.indices.push(n[1],n[2],n[3]));break;default:break}}var le={...A,parse:async(e,t)=>T(e,t?.ply),parseTextSync:(e,t)=>T(e,t?.ply),parseSync:(e,t)=>T(e,t?.ply),parseInBatches:(e,t)=>_(e,t?.ply)};return q(d);})();
|
|
11
|
+
return __exports__;
|
|
12
|
+
});
|
package/dist/index.cjs
CHANGED
|
@@ -17,16 +17,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
//
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
20
|
+
// dist/index.js
|
|
21
|
+
var dist_exports = {};
|
|
22
|
+
__export(dist_exports, {
|
|
23
23
|
PLYLoader: () => PLYLoader2,
|
|
24
24
|
PLYWorkerLoader: () => PLYLoader
|
|
25
25
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
26
|
+
module.exports = __toCommonJS(dist_exports);
|
|
27
27
|
|
|
28
|
-
//
|
|
29
|
-
var VERSION =
|
|
28
|
+
// dist/ply-loader.js
|
|
29
|
+
var VERSION = true ? "4.2.0-alpha.5" : "latest";
|
|
30
30
|
var PLYLoader = {
|
|
31
31
|
name: "PLY",
|
|
32
32
|
id: "ply",
|
|
@@ -44,10 +44,10 @@ var PLYLoader = {
|
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
//
|
|
47
|
+
// dist/lib/normalize-ply.js
|
|
48
48
|
var import_schema2 = require("@loaders.gl/schema");
|
|
49
49
|
|
|
50
|
-
//
|
|
50
|
+
// dist/lib/get-ply-schema.js
|
|
51
51
|
var import_schema = require("@loaders.gl/schema");
|
|
52
52
|
function getPLYSchema(plyHeader, attributes) {
|
|
53
53
|
const metadata = makeMetadataFromPlyHeader(plyHeader);
|
|
@@ -70,7 +70,7 @@ function makeMetadataFromPlyHeader(plyHeader) {
|
|
|
70
70
|
return metadata;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
//
|
|
73
|
+
// dist/lib/normalize-ply.js
|
|
74
74
|
function normalizePLY(plyHeader, plyAttributes, options) {
|
|
75
75
|
const attributes = getMeshAttributes(plyAttributes);
|
|
76
76
|
const boundingBox = (0, import_schema2.getMeshBoundingBox)(attributes);
|
|
@@ -133,7 +133,7 @@ function getMeshAttributes(attributes) {
|
|
|
133
133
|
return accessors;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
//
|
|
136
|
+
// dist/lib/parse-ply.js
|
|
137
137
|
function parsePLY(data, options = {}) {
|
|
138
138
|
let header;
|
|
139
139
|
let attributes;
|
|
@@ -441,12 +441,7 @@ function parseBinary(data, header) {
|
|
|
441
441
|
for (let currentElement2 = 0; currentElement2 < header.elements.length; currentElement2++) {
|
|
442
442
|
const count = header.elements[currentElement2].count;
|
|
443
443
|
for (let currentElementCount = 0; currentElementCount < count; currentElementCount++) {
|
|
444
|
-
result = binaryReadElement(
|
|
445
|
-
body,
|
|
446
|
-
loc,
|
|
447
|
-
header.elements[currentElement2].properties,
|
|
448
|
-
littleEndian
|
|
449
|
-
);
|
|
444
|
+
result = binaryReadElement(body, loc, header.elements[currentElement2].properties, littleEndian);
|
|
450
445
|
loc += result[1];
|
|
451
446
|
const element = result[0];
|
|
452
447
|
handleElement(attributes, header.elements[currentElement2].name, element);
|
|
@@ -455,7 +450,7 @@ function parseBinary(data, header) {
|
|
|
455
450
|
return attributes;
|
|
456
451
|
}
|
|
457
452
|
|
|
458
|
-
//
|
|
453
|
+
// dist/lib/parse-ply-in-batches.js
|
|
459
454
|
var import_loader_utils = require("@loaders.gl/loader-utils");
|
|
460
455
|
var currentElement;
|
|
461
456
|
async function* parsePLYInBatches(iterator, options) {
|
|
@@ -632,7 +627,7 @@ function handleElement2(buffer, elementName, element = {}) {
|
|
|
632
627
|
}
|
|
633
628
|
}
|
|
634
629
|
|
|
635
|
-
//
|
|
630
|
+
// dist/index.js
|
|
636
631
|
var PLYLoader2 = {
|
|
637
632
|
...PLYLoader,
|
|
638
633
|
// Note: parsePLY supports both text and binary
|
|
@@ -642,3 +637,4 @@ var PLYLoader2 = {
|
|
|
642
637
|
parseSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options == null ? void 0 : options.ply),
|
|
643
638
|
parseInBatches: (arrayBuffer, options) => parsePLYInBatches(arrayBuffer, options == null ? void 0 : options.ply)
|
|
644
639
|
};
|
|
640
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["index.js", "ply-loader.js", "lib/normalize-ply.js", "lib/get-ply-schema.js", "lib/parse-ply.js", "lib/parse-ply-in-batches.js"],
|
|
4
|
+
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport { PLYLoader as PLYWorkerLoader } from \"./ply-loader.js\";\nimport { parsePLY } from \"./lib/parse-ply.js\";\nimport { parsePLYInBatches } from \"./lib/parse-ply-in-batches.js\";\n// PLYLoader\nexport { PLYWorkerLoader };\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?.ply), // TODO - this may not detect text correctly?\n parseTextSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),\n parseSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),\n parseInBatches: (arrayBuffer, options) => parsePLYInBatches(arrayBuffer, options?.ply)\n};\n", "// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof \"4.2.0-alpha.5\" !== 'undefined' ? \"4.2.0-alpha.5\" : 'latest';\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 = {\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", "import { getMeshBoundingBox } from '@loaders.gl/schema';\nimport { getPLYSchema } from \"./get-ply-schema.js\";\n/**\n * @param header\n * @param attributes\n * @returns data and header\n */\nexport default function normalizePLY(plyHeader, plyAttributes, options) {\n const attributes = getMeshAttributes(plyAttributes);\n const boundingBox = getMeshBoundingBox(attributes);\n const vertexCount = plyAttributes.indices.length || plyAttributes.vertices.length / 3;\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 const schema = getPLYSchema(plyHeader, attributes);\n const 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 if (plyAttributes.indices.length > 0) {\n plyMesh.indices = { value: new Uint32Array(plyAttributes.indices), size: 1 };\n }\n return plyMesh;\n}\n/**\n * @param attributes\n * @returns accessors []\n */\n// eslint-disable-next-line complexity\nfunction getMeshAttributes(attributes) {\n const accessors = {};\n for (const attributeName of Object.keys(attributes)) {\n switch (attributeName) {\n case 'vertices':\n if (attributes.vertices.length > 0) {\n accessors.POSITION = { value: new Float32Array(attributes.vertices), size: 3 };\n }\n break;\n // optional attributes data\n case 'normals':\n if (attributes.normals.length > 0) {\n accessors.NORMAL = { value: new Float32Array(attributes.normals), size: 3 };\n }\n break;\n case 'uvs':\n if (attributes.uvs.length > 0) {\n accessors.TEXCOORD_0 = { value: new Float32Array(attributes.uvs), size: 2 };\n }\n break;\n case 'colors':\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 break;\n case 'indices':\n break;\n default:\n if (attributes[attributeName].length > 0) {\n accessors[attributeName] = { value: new Float32Array(attributes[attributeName]), size: 1 };\n }\n break;\n }\n }\n return accessors;\n}\n", "import { deduceMeshSchema } from '@loaders.gl/schema';\n/**\n * Gets schema from PLY header\n * @param plyHeader\n * @param metadata\n * @returns Schema\n */\nexport function getPLYSchema(plyHeader, attributes) {\n const metadata = makeMetadataFromPlyHeader(plyHeader);\n const schema = deduceMeshSchema(attributes, metadata);\n return schema;\n}\n/**\n * Make arrow like schema metadata by PlyHeader properties\n * @param plyHeader\n * @returns\n */\nfunction makeMetadataFromPlyHeader(plyHeader) {\n /* eslint-disable camelcase */\n const metadata = {};\n metadata.ply_comments = JSON.stringify(plyHeader.comments);\n metadata.ply_elements = JSON.stringify(plyHeader.elements);\n if (plyHeader.format !== undefined) {\n metadata.ply_format = plyHeader.format;\n }\n if (plyHeader.version !== undefined) {\n metadata.ply_version = plyHeader.version;\n }\n if (plyHeader.headerLength !== undefined) {\n metadata.ply_headerLength = plyHeader.headerLength.toString(10);\n }\n return metadata;\n}\n", "import normalizePLY from \"./normalize-ply.js\";\n/**\n * @param data\n * @param options\n * @returns\n */\nexport function parsePLY(data, options = {}) {\n let header;\n let attributes;\n if (data instanceof ArrayBuffer) {\n const text = new TextDecoder().decode(data);\n header = parseHeader(text, options);\n attributes = header.format === 'ascii' ? parseASCII(text, header) : parseBinary(data, header);\n }\n else {\n header = parseHeader(data, options);\n attributes = parseASCII(data, header);\n }\n return normalizePLY(header, attributes);\n}\n/**\n * @param data\n * @param options\n * @returns header\n */\nfunction parseHeader(data, options) {\n const PLY_HEADER_PATTERN = /ply([\\s\\S]*)end_header\\s/;\n let headerText = '';\n let headerLength = 0;\n const result = PLY_HEADER_PATTERN.exec(data);\n if (result !== null) {\n headerText = result[1];\n headerLength = result[0].length;\n }\n const lines = headerText.split('\\n');\n const header = parseHeaderLines(lines, headerLength, options);\n return header;\n}\n/**\n * @param lines\n * @param headerLength\n * @param options\n * @returns header\n */\n// eslint-disable-next-line complexity\nfunction parseHeaderLines(lines, headerLength, options) {\n const header = {\n comments: [],\n elements: [],\n headerLength\n };\n let lineType;\n let lineValues;\n let currentElement = null;\n for (let i = 0; i < lines.length; i++) {\n let line = lines[i];\n line = line.trim();\n if (line === '') {\n // eslint-disable-next-line\n continue;\n }\n lineValues = line.split(/\\s+/);\n lineType = lineValues.shift();\n line = lineValues.join(' ');\n switch (lineType) {\n case 'format':\n header.format = lineValues[0];\n header.version = lineValues[1];\n break;\n case 'comment':\n header.comments.push(line);\n break;\n case 'element':\n // Start new element, store previous element\n if (currentElement) {\n header.elements.push(currentElement);\n }\n currentElement = {\n name: lineValues[0],\n count: parseInt(lineValues[1], 10),\n properties: []\n };\n break;\n case 'property':\n if (currentElement) {\n const property = makePLYElementProperty(lineValues);\n if (options?.propertyNameMapping && property.name in options?.propertyNameMapping) {\n property.name = options?.propertyNameMapping[property.name];\n }\n currentElement.properties.push(property);\n }\n break;\n default:\n // eslint-disable-next-line\n console.log('unhandled', lineType, lineValues);\n }\n }\n // Store in-progress element\n if (currentElement) {\n header.elements.push(currentElement);\n }\n return header;\n}\n/** Generate attributes arrays from the header */\n// eslint-disable-next-line complexity\nfunction getPLYAttributes(header) {\n // TODO Generate only the attribute arrays actually in the header\n const attributes = {\n indices: [],\n vertices: [],\n normals: [],\n uvs: [],\n colors: []\n };\n for (const element of header.elements) {\n if (element.name === 'vertex') {\n for (const property of element.properties) {\n switch (property.name) {\n case 'x':\n case 'y':\n case 'z':\n case 'nx':\n case 'ny':\n case 'nz':\n case 's':\n case 't':\n case 'red':\n case 'green':\n case 'blue':\n break;\n default:\n // Add any non-geometry attributes\n attributes[property.name] = [];\n break;\n }\n }\n }\n }\n return attributes;\n}\n/**\n * @param propertyValues\n * @returns property of ply element\n */\nfunction makePLYElementProperty(propertyValues) {\n const type = propertyValues[0];\n switch (type) {\n case 'list':\n return {\n type,\n name: propertyValues[3],\n countType: propertyValues[1],\n itemType: propertyValues[2]\n };\n default:\n return {\n type,\n name: propertyValues[1]\n };\n }\n}\n/**\n * Parses ASCII number\n * @param n\n * @param type\n * @returns\n */\n// eslint-disable-next-line complexity\nfunction parseASCIINumber(n, type) {\n switch (type) {\n case 'char':\n case 'uchar':\n case 'short':\n case 'ushort':\n case 'int':\n case 'uint':\n case 'int8':\n case 'uint8':\n case 'int16':\n case 'uint16':\n case 'int32':\n case 'uint32':\n return parseInt(n, 10);\n case 'float':\n case 'double':\n case 'float32':\n case 'float64':\n return parseFloat(n);\n default:\n throw new Error(type);\n }\n}\n/**\n * @param properties\n * @param line\n * @returns ASCII element\n */\nfunction parsePLYElement(properties, line) {\n const values = line.split(/\\s+/);\n const element = {};\n for (let i = 0; i < properties.length; i++) {\n if (properties[i].type === 'list') {\n const list = [];\n const n = parseASCIINumber(values.shift(), properties[i].countType);\n for (let j = 0; j < n; j++) {\n list.push(parseASCIINumber(values.shift(), properties[i].itemType));\n }\n element[properties[i].name] = list;\n }\n else {\n element[properties[i].name] = parseASCIINumber(values.shift(), properties[i].type);\n }\n }\n return element;\n}\n/**\n * @param data\n * @param header\n * @returns [attributes]\n */\nfunction parseASCII(data, header) {\n // PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)\n const attributes = getPLYAttributes(header);\n let result;\n const patternBody = /end_header\\s([\\s\\S]*)$/;\n let body = '';\n if ((result = patternBody.exec(data)) !== null) {\n body = result[1];\n }\n const lines = body.split('\\n');\n let currentElement = 0;\n let currentElementCount = 0;\n for (let i = 0; i < lines.length; i++) {\n let line = lines[i];\n line = line.trim();\n if (line !== '') {\n if (currentElementCount >= header.elements[currentElement].count) {\n currentElement++;\n currentElementCount = 0;\n }\n const element = parsePLYElement(header.elements[currentElement].properties, line);\n handleElement(attributes, header.elements[currentElement].name, element);\n currentElementCount++;\n }\n }\n return attributes;\n}\n/**\n * @param buffer\n * @param elementName\n * @param element\n */\n// eslint-disable-next-line complexity\nfunction handleElement(buffer, elementName, element = {}) {\n if (elementName === 'vertex') {\n for (const propertyName of Object.keys(element)) {\n switch (propertyName) {\n case 'x':\n buffer.vertices.push(element.x, element.y, element.z);\n break;\n case 'y':\n case 'z':\n break;\n case 'nx':\n if ('nx' in element && 'ny' in element && 'nz' in element) {\n buffer.normals.push(element.nx, element.ny, element.nz);\n }\n break;\n case 'ny':\n case 'nz':\n break;\n case 's':\n if ('s' in element && 't' in element) {\n buffer.uvs.push(element.s, element.t);\n }\n break;\n case 't':\n break;\n case 'red':\n if ('red' in element && 'green' in element && 'blue' in element) {\n buffer.colors.push(element.red, element.green, element.blue);\n }\n break;\n case 'green':\n case 'blue':\n break;\n default:\n buffer[propertyName].push(element[propertyName]);\n }\n }\n }\n else if (elementName === 'face') {\n const vertexIndices = element.vertex_indices || element.vertex_index; // issue #9338\n if (vertexIndices.length === 3) {\n buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);\n }\n else if (vertexIndices.length === 4) {\n buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);\n buffer.indices.push(vertexIndices[1], vertexIndices[2], vertexIndices[3]);\n }\n }\n}\n/**\n * Reads binary data\n * @param dataview\n * @param at\n * @param type\n * @param littleEndian\n * @returns [number, number]\n */\n// eslint-disable-next-line complexity\nfunction binaryRead(dataview, at, type, littleEndian) {\n switch (type) {\n // corespondences for non-specific length types here match rply:\n case 'int8':\n case 'char':\n return [dataview.getInt8(at), 1];\n case 'uint8':\n case 'uchar':\n return [dataview.getUint8(at), 1];\n case 'int16':\n case 'short':\n return [dataview.getInt16(at, littleEndian), 2];\n case 'uint16':\n case 'ushort':\n return [dataview.getUint16(at, littleEndian), 2];\n case 'int32':\n case 'int':\n return [dataview.getInt32(at, littleEndian), 4];\n case 'uint32':\n case 'uint':\n return [dataview.getUint32(at, littleEndian), 4];\n case 'float32':\n case 'float':\n return [dataview.getFloat32(at, littleEndian), 4];\n case 'float64':\n case 'double':\n return [dataview.getFloat64(at, littleEndian), 8];\n default:\n throw new Error(type);\n }\n}\n/**\n * Reads binary data\n * @param dataview\n * @param at\n * @param properties\n * @param littleEndian\n * @returns [object, number]\n */\nfunction binaryReadElement(dataview, at, properties, littleEndian) {\n const element = {};\n let result;\n let read = 0;\n for (let i = 0; i < properties.length; i++) {\n if (properties[i].type === 'list') {\n const list = [];\n result = binaryRead(dataview, at + read, properties[i].countType, littleEndian);\n const n = result[0];\n read += result[1];\n for (let j = 0; j < n; j++) {\n result = binaryRead(dataview, at + read, properties[i].itemType, littleEndian);\n // @ts-ignore\n list.push(result[0]);\n read += result[1];\n }\n element[properties[i].name] = list;\n }\n else {\n result = binaryRead(dataview, at + read, properties[i].type, littleEndian);\n element[properties[i].name] = result[0];\n read += result[1];\n }\n }\n return [element, read];\n}\n/**\n * Parses binary data\n * @param data\n * @param header\n * @returns [attributes] of data\n */\nfunction parseBinary(data, header) {\n const attributes = getPLYAttributes(header);\n const littleEndian = header.format === 'binary_little_endian';\n const body = new DataView(data, header.headerLength);\n let result;\n let loc = 0;\n for (let currentElement = 0; currentElement < header.elements.length; currentElement++) {\n const count = header.elements[currentElement].count;\n for (let currentElementCount = 0; currentElementCount < count; currentElementCount++) {\n result = binaryReadElement(body, loc, header.elements[currentElement].properties, littleEndian);\n loc += result[1];\n const element = result[0];\n handleElement(attributes, header.elements[currentElement].name, element);\n }\n }\n return attributes;\n}\n", "// PLY Loader, adapted from THREE.js (MIT license)\n//\n// Attributions per original THREE.js source file:\n//\n// @author Wei Meng / http://about.me/menway\n//\n// Description: A loader for PLY ASCII files (known as the Polygon File Format\n// or the Stanford Triangle Format).\n//\n// Limitations: ASCII decoding assumes file is UTF-8.\n//\n// If the PLY file uses non standard property names, they can be mapped while\n// loading. For example, the following maps the properties\n// \u201Cdiffuse_(red|green|blue)\u201D in the file to standard color names.\n//\n// parsePLY(data, {\n// propertyNameMapping: {\n// diffuse_red: 'red',\n// diffuse_green: 'green',\n// diffuse_blue: 'blue'\n// }\n// });\nimport { makeLineIterator, makeTextDecoderIterator, forEach } from '@loaders.gl/loader-utils';\nimport normalizePLY from \"./normalize-ply.js\";\nlet currentElement;\n/**\n * PARSER\n * @param iterator\n * @param options\n */\nexport async function* parsePLYInBatches(iterator, options) {\n const lineIterator = makeLineIterator(makeTextDecoderIterator(iterator));\n const header = await parsePLYHeader(lineIterator, options);\n let attributes;\n switch (header.format) {\n case 'ascii':\n attributes = await parseASCII(lineIterator, header);\n break;\n default:\n throw new Error('Binary PLY can not yet be parsed in streaming mode');\n // attributes = await parseBinary(lineIterator, header);\n }\n yield normalizePLY(header, attributes, options);\n}\n/**\n * Parses header\n * @param lineIterator\n * @param options\n * @returns\n */\nasync function parsePLYHeader(lineIterator, options) {\n const header = {\n comments: [],\n elements: []\n // headerLength\n };\n // Note: forEach does not reset iterator if exiting loop prematurely\n // so that iteration can continue in a second loop\n await forEach(lineIterator, (line) => {\n line = line.trim();\n // End of header\n if (line === 'end_header') {\n return true; // Returning true cancels `forEach`\n }\n // Ignore empty lines\n if (line === '') {\n // eslint-disable-next-line\n return false; // Returning false does not cancel `forEach`\n }\n const lineValues = line.split(/\\s+/);\n const lineType = lineValues.shift();\n line = lineValues.join(' ');\n switch (lineType) {\n case 'ply':\n // First line magic characters, ignore\n break;\n case 'format':\n header.format = lineValues[0];\n header.version = lineValues[1];\n break;\n case 'comment':\n header.comments.push(line);\n break;\n case 'element':\n if (currentElement) {\n header.elements.push(currentElement);\n }\n currentElement = {\n name: lineValues[0],\n count: parseInt(lineValues[1], 10),\n properties: []\n };\n break;\n case 'property':\n const property = makePLYElementProperty(lineValues, options.propertyNameMapping);\n currentElement.properties.push(property);\n break;\n default:\n // eslint-disable-next-line\n console.log('unhandled', lineType, lineValues);\n }\n return false;\n });\n if (currentElement) {\n header.elements.push(currentElement);\n }\n return header;\n}\nfunction makePLYElementProperty(propertyValues, propertyNameMapping) {\n const type = propertyValues[0];\n switch (type) {\n case 'list':\n return {\n type,\n name: propertyValues[3],\n countType: propertyValues[1],\n itemType: propertyValues[2]\n };\n default:\n return {\n type,\n name: propertyValues[1]\n };\n }\n}\n// ASCII PARSING\n/**\n * @param lineIterator\n * @param header\n * @returns\n */\nasync function parseASCII(lineIterator, header) {\n // PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)\n const attributes = {\n indices: [],\n vertices: [],\n normals: [],\n uvs: [],\n colors: []\n };\n let currentElement = 0;\n let currentElementCount = 0;\n for await (let line of lineIterator) {\n line = line.trim();\n if (line !== '') {\n if (currentElementCount >= header.elements[currentElement].count) {\n currentElement++;\n currentElementCount = 0;\n }\n const element = parsePLYElement(header.elements[currentElement].properties, line);\n handleElement(attributes, header.elements[currentElement].name, element);\n currentElementCount++;\n }\n }\n return attributes;\n}\n/**\n * Parses ASCII number\n * @param n\n * @param type\n * @returns ASCII number\n */\n// eslint-disable-next-line complexity\nfunction parseASCIINumber(n, type) {\n switch (type) {\n case 'char':\n case 'uchar':\n case 'short':\n case 'ushort':\n case 'int':\n case 'uint':\n case 'int8':\n case 'uint8':\n case 'int16':\n case 'uint16':\n case 'int32':\n case 'uint32':\n return parseInt(n, 10);\n case 'float':\n case 'double':\n case 'float32':\n case 'float64':\n return parseFloat(n);\n default:\n throw new Error(type);\n }\n}\n/**\n * Parses ASCII element\n * @param properties\n * @param line\n * @returns element\n */\nfunction parsePLYElement(properties, line) {\n const values = line.split(/\\s+/);\n const element = {};\n for (let i = 0; i < properties.length; i++) {\n if (properties[i].type === 'list') {\n const list = [];\n const n = parseASCIINumber(values.shift(), properties[i].countType);\n for (let j = 0; j < n; j++) {\n list.push(parseASCIINumber(values.shift(), properties[i].itemType));\n }\n element[properties[i].name] = list;\n }\n else {\n element[properties[i].name] = parseASCIINumber(values.shift(), properties[i].type);\n }\n }\n return element;\n}\n/**\n * @param buffer\n * @param elementName\n * @param element\n */\n// HELPER FUNCTIONS\n// eslint-disable-next-line complexity\nfunction handleElement(buffer, elementName, element = {}) {\n switch (elementName) {\n case 'vertex':\n buffer.vertices.push(element.x, element.y, element.z);\n if ('nx' in element && 'ny' in element && 'nz' in element) {\n buffer.normals.push(element.nx, element.ny, element.nz);\n }\n if ('s' in element && 't' in element) {\n buffer.uvs.push(element.s, element.t);\n }\n if ('red' in element && 'green' in element && 'blue' in element) {\n buffer.colors.push(element.red / 255.0, element.green / 255.0, element.blue / 255.0);\n }\n break;\n case 'face':\n const vertexIndices = element.vertex_indices || element.vertex_index; // issue #9338\n if (vertexIndices.length === 3) {\n buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);\n }\n else if (vertexIndices.length === 4) {\n buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);\n buffer.indices.push(vertexIndices[1], vertexIndices[2], vertex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,EACR;AACJ;;;AL1OO,IAAME,aAAY;AAAA,EACrB,GAAG;AAAA;AAAA,EAEH,OAAO,OAAO,aAAa,YAAY,SAAS,aAAa,mCAAS,GAAG;AAAA;AAAA,EACzE,eAAe,CAAC,aAAa,YAAY,SAAS,aAAa,mCAAS,GAAG;AAAA,EAC3E,WAAW,CAAC,aAAa,YAAY,SAAS,aAAa,mCAAS,GAAG;AAAA,EACvE,gBAAgB,CAAC,aAAa,YAAY,kBAAkB,aAAa,mCAAS,GAAG;AACzF;",
|
|
6
|
+
"names": ["PLYLoader", "import_schema", "currentElement", "parseASCII", "makePLYElementProperty", "currentElement", "parsePLYElement", "handleElement", "parseASCIINumber", "PLYLoader"]
|
|
7
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { LoaderOptions, LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
-
import type { PLYMesh } from
|
|
3
|
-
import { PLYLoader as PLYWorkerLoader } from
|
|
4
|
-
import { ParsePLYOptions } from
|
|
2
|
+
import type { PLYMesh } from "./lib/ply-types.js";
|
|
3
|
+
import { PLYLoader as PLYWorkerLoader } from "./ply-loader.js";
|
|
4
|
+
import { ParsePLYOptions } from "./lib/parse-ply.js";
|
|
5
5
|
export { PLYWorkerLoader };
|
|
6
6
|
export type PLYLoaderOptions = LoaderOptions & {
|
|
7
7
|
ply?: ParsePLYOptions;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAC,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAC,OAAO,EAAC,2BAAwB;AAC7C,OAAO,EAAC,SAAS,IAAI,eAAe,EAAC,wBAAqB;AAC1D,OAAO,EAAC,eAAe,EAAW,2BAAwB;AAK1D,OAAO,EAAC,eAAe,EAAC,CAAC;AAEzB,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,eAAe,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,gBAAgB,CAOtE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { PLYLoader as PLYWorkerLoader } from "./ply-loader.js";
|
|
2
5
|
import { parsePLY } from "./lib/parse-ply.js";
|
|
3
6
|
import { parsePLYInBatches } from "./lib/parse-ply-in-batches.js";
|
|
7
|
+
// PLYLoader
|
|
4
8
|
export { PLYWorkerLoader };
|
|
9
|
+
/**
|
|
10
|
+
* Loader for PLY - Polygon File Format
|
|
11
|
+
*/
|
|
5
12
|
export const PLYLoader = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
...PLYWorkerLoader,
|
|
14
|
+
// Note: parsePLY supports both text and binary
|
|
15
|
+
parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply), // TODO - this may not detect text correctly?
|
|
16
|
+
parseTextSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
|
|
17
|
+
parseSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
|
|
18
|
+
parseInBatches: (arrayBuffer, options) => parsePLYInBatches(arrayBuffer, options?.ply)
|
|
11
19
|
};
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-ply-schema.d.ts","sourceRoot":"","sources":["../../src/lib/get-ply-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,cAAc,EAAmB,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAC,SAAS,EAAC,
|
|
1
|
+
{"version":3,"file":"get-ply-schema.d.ts","sourceRoot":"","sources":["../../src/lib/get-ply-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,cAAc,EAAmB,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAC,SAAS,EAAC,uBAAoB;AAE3C;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,GAAG,MAAM,CAIrF"}
|
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
import { deduceMeshSchema } from '@loaders.gl/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Gets schema from PLY header
|
|
4
|
+
* @param plyHeader
|
|
5
|
+
* @param metadata
|
|
6
|
+
* @returns Schema
|
|
7
|
+
*/
|
|
2
8
|
export function getPLYSchema(plyHeader, attributes) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
9
|
+
const metadata = makeMetadataFromPlyHeader(plyHeader);
|
|
10
|
+
const schema = deduceMeshSchema(attributes, metadata);
|
|
11
|
+
return schema;
|
|
6
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Make arrow like schema metadata by PlyHeader properties
|
|
15
|
+
* @param plyHeader
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
7
18
|
function makeMetadataFromPlyHeader(plyHeader) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
/* eslint-disable camelcase */
|
|
20
|
+
const metadata = {};
|
|
21
|
+
metadata.ply_comments = JSON.stringify(plyHeader.comments);
|
|
22
|
+
metadata.ply_elements = JSON.stringify(plyHeader.elements);
|
|
23
|
+
if (plyHeader.format !== undefined) {
|
|
24
|
+
metadata.ply_format = plyHeader.format;
|
|
25
|
+
}
|
|
26
|
+
if (plyHeader.version !== undefined) {
|
|
27
|
+
metadata.ply_version = plyHeader.version;
|
|
28
|
+
}
|
|
29
|
+
if (plyHeader.headerLength !== undefined) {
|
|
30
|
+
metadata.ply_headerLength = plyHeader.headerLength.toString(10);
|
|
31
|
+
}
|
|
32
|
+
return metadata;
|
|
21
33
|
}
|
|
22
|
-
//# sourceMappingURL=get-ply-schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-ply.d.ts","sourceRoot":"","sources":["../../src/lib/normalize-ply.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAC,
|
|
1
|
+
{"version":3,"file":"normalize-ply.d.ts","sourceRoot":"","sources":["../../src/lib/normalize-ply.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAC,uBAAoB;AAG/E;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,SAAS,EAAE,UAAU,GAAG,SAAS,EACjC,aAAa,EAAE,aAAa,EAC5B,OAAO,CAAC,EAAE,EAAE,GACX,OAAO,CAgCT"}
|