@loaders.gl/ply 3.4.0-alpha.1 → 3.4.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/dist.min.js +142 -70
  2. package/dist/es5/index.js +17 -13
  3. package/dist/es5/index.js.map +1 -1
  4. package/dist/es5/lib/get-ply-schema.js +0 -1
  5. package/dist/es5/lib/get-ply-schema.js.map +1 -1
  6. package/dist/es5/lib/normalize-ply.js +47 -25
  7. package/dist/es5/lib/normalize-ply.js.map +1 -1
  8. package/dist/es5/lib/parse-ply-in-batches.js +162 -172
  9. package/dist/es5/lib/parse-ply-in-batches.js.map +1 -1
  10. package/dist/es5/lib/parse-ply.js +114 -54
  11. package/dist/es5/lib/parse-ply.js.map +1 -1
  12. package/dist/es5/lib/ply-types.js.map +1 -1
  13. package/dist/es5/ply-loader.js +1 -3
  14. package/dist/es5/ply-loader.js.map +1 -1
  15. package/dist/es5/workers/ply-worker.js.map +1 -1
  16. package/dist/esm/bundle.js +0 -1
  17. package/dist/esm/bundle.js.map +1 -1
  18. package/dist/esm/index.js +6 -8
  19. package/dist/esm/index.js.map +1 -1
  20. package/dist/esm/lib/get-ply-schema.js +0 -1
  21. package/dist/esm/lib/get-ply-schema.js.map +1 -1
  22. package/dist/esm/lib/normalize-ply.js +46 -26
  23. package/dist/esm/lib/normalize-ply.js.map +1 -1
  24. package/dist/esm/lib/parse-ply-in-batches.js +18 -27
  25. package/dist/esm/lib/parse-ply-in-batches.js.map +1 -1
  26. package/dist/esm/lib/parse-ply.js +92 -56
  27. package/dist/esm/lib/parse-ply.js.map +1 -1
  28. package/dist/esm/lib/ply-types.js.map +1 -1
  29. package/dist/esm/ply-loader.js +1 -4
  30. package/dist/esm/ply-loader.js.map +1 -1
  31. package/dist/index.d.ts +3 -5
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +6 -9
  34. package/dist/lib/normalize-ply.js +33 -11
  35. package/dist/lib/parse-ply-in-batches.d.ts +1 -1
  36. package/dist/lib/parse-ply-in-batches.d.ts.map +1 -1
  37. package/dist/lib/parse-ply-in-batches.js +19 -18
  38. package/dist/lib/parse-ply.d.ts +4 -1
  39. package/dist/lib/parse-ply.d.ts.map +1 -1
  40. package/dist/lib/parse-ply.js +103 -47
  41. package/dist/lib/ply-types.d.ts +19 -11
  42. package/dist/lib/ply-types.d.ts.map +1 -1
  43. package/dist/ply-worker.js +143 -71
  44. package/package.json +4 -4
  45. package/src/index.ts +6 -6
  46. package/src/lib/normalize-ply.ts +34 -12
  47. package/src/lib/parse-ply-in-batches.ts +20 -22
  48. package/src/lib/parse-ply.ts +114 -55
  49. package/src/lib/ply-types.ts +21 -12
@@ -222,7 +222,7 @@
222
222
  }
223
223
 
224
224
  // src/ply-loader.ts
225
- var VERSION = true ? "3.4.0-alpha.1" : "latest";
225
+ var VERSION = true ? "3.4.0-alpha.3" : "latest";
226
226
  var PLYLoader = {
227
227
  name: "PLY",
228
228
  id: "ply",
@@ -821,15 +821,36 @@
821
821
  }
822
822
  function getMeshAttributes(attributes) {
823
823
  const accessors = {};
824
- accessors.POSITION = { value: new Float32Array(attributes.vertices), size: 3 };
825
- if (attributes.normals.length > 0) {
826
- accessors.NORMAL = { value: new Float32Array(attributes.normals), size: 3 };
827
- }
828
- if (attributes.uvs.length > 0) {
829
- accessors.TEXCOORD_0 = { value: new Float32Array(attributes.uvs), size: 2 };
830
- }
831
- if (attributes.colors.length > 0) {
832
- accessors.COLOR_0 = { value: new Uint8Array(attributes.colors), size: 3, normalized: true };
824
+ for (const attributeName of Object.keys(attributes)) {
825
+ switch (attributeName) {
826
+ case "vertices":
827
+ if (attributes.vertices.length > 0) {
828
+ accessors.POSITION = { value: new Float32Array(attributes.vertices), size: 3 };
829
+ }
830
+ break;
831
+ case "normals":
832
+ if (attributes.normals.length > 0) {
833
+ accessors.NORMAL = { value: new Float32Array(attributes.normals), size: 3 };
834
+ }
835
+ break;
836
+ case "uvs":
837
+ if (attributes.uvs.length > 0) {
838
+ accessors.TEXCOORD_0 = { value: new Float32Array(attributes.uvs), size: 2 };
839
+ }
840
+ break;
841
+ case "colors":
842
+ if (attributes.colors.length > 0) {
843
+ accessors.COLOR_0 = { value: new Uint8Array(attributes.colors), size: 3, normalized: true };
844
+ }
845
+ break;
846
+ case "indices":
847
+ break;
848
+ default:
849
+ if (attributes[attributeName].length > 0) {
850
+ accessors[attributeName] = { value: new Float32Array(attributes[attributeName]), size: 1 };
851
+ }
852
+ break;
853
+ }
833
854
  }
834
855
  return accessors;
835
856
  }
@@ -898,35 +919,72 @@
898
919
  };
899
920
  break;
900
921
  case "property":
901
- if (!currentElement2) {
902
- break;
922
+ if (currentElement2) {
923
+ const property = makePLYElementProperty(lineValues);
924
+ if (options?.propertyNameMapping && property.name in options?.propertyNameMapping) {
925
+ property.name = options?.propertyNameMapping[property.name];
926
+ }
927
+ currentElement2.properties.push(property);
903
928
  }
904
- currentElement2.properties.push(makePLYElementProperty(lineValues, options.propertyNameMapping));
905
929
  break;
906
930
  default:
907
931
  console.log("unhandled", lineType, lineValues);
908
932
  }
909
933
  }
910
- if (currentElement2 !== void 0) {
934
+ if (currentElement2) {
911
935
  header.elements.push(currentElement2);
912
936
  }
913
937
  return header;
914
938
  }
915
- function makePLYElementProperty(propertValues, propertyNameMapping) {
916
- const property = {
917
- type: propertValues[0]
939
+ function getPLYAttributes(header) {
940
+ const attributes = {
941
+ indices: [],
942
+ vertices: [],
943
+ normals: [],
944
+ uvs: [],
945
+ colors: []
918
946
  };
919
- if (property.type === "list") {
920
- property.name = propertValues[3];
921
- property.countType = propertValues[1];
922
- property.itemType = propertValues[2];
923
- } else {
924
- property.name = propertValues[1];
947
+ for (const element of header.elements) {
948
+ if (element.name === "vertex") {
949
+ for (const property of element.properties) {
950
+ switch (property.name) {
951
+ case "x":
952
+ case "y":
953
+ case "z":
954
+ case "nx":
955
+ case "ny":
956
+ case "nz":
957
+ case "s":
958
+ case "t":
959
+ case "red":
960
+ case "green":
961
+ case "blue":
962
+ break;
963
+ default:
964
+ attributes[property.name] = [];
965
+ break;
966
+ }
967
+ }
968
+ }
925
969
  }
926
- if (propertyNameMapping && property.name in propertyNameMapping) {
927
- property.name = propertyNameMapping[property.name];
970
+ return attributes;
971
+ }
972
+ function makePLYElementProperty(propertyValues) {
973
+ const type = propertyValues[0];
974
+ switch (type) {
975
+ case "list":
976
+ return {
977
+ type,
978
+ name: propertyValues[3],
979
+ countType: propertyValues[1],
980
+ itemType: propertyValues[2]
981
+ };
982
+ default:
983
+ return {
984
+ type,
985
+ name: propertyValues[1]
986
+ };
928
987
  }
929
- return property;
930
988
  }
931
989
  function parseASCIINumber(n, type) {
932
990
  switch (type) {
@@ -952,7 +1010,7 @@
952
1010
  throw new Error(type);
953
1011
  }
954
1012
  }
955
- function parseASCIIElement(properties, line) {
1013
+ function parsePLYElement(properties, line) {
956
1014
  const values = line.split(/\s+/);
957
1015
  const element = {};
958
1016
  for (let i = 0; i < properties.length; i++) {
@@ -970,13 +1028,7 @@
970
1028
  return element;
971
1029
  }
972
1030
  function parseASCII(data, header) {
973
- const attributes = {
974
- indices: [],
975
- vertices: [],
976
- normals: [],
977
- uvs: [],
978
- colors: []
979
- };
1031
+ const attributes = getPLYAttributes(header);
980
1032
  let result;
981
1033
  const patternBody = /end_header\s([\s\S]*)$/;
982
1034
  let body = "";
@@ -994,7 +1046,7 @@
994
1046
  currentElement2++;
995
1047
  currentElementCount = 0;
996
1048
  }
997
- const element = parseASCIIElement(header.elements[currentElement2].properties, line);
1049
+ const element = parsePLYElement(header.elements[currentElement2].properties, line);
998
1050
  handleElement(attributes, header.elements[currentElement2].name, element);
999
1051
  currentElementCount++;
1000
1052
  }
@@ -1003,15 +1055,40 @@
1003
1055
  }
1004
1056
  function handleElement(buffer, elementName, element = {}) {
1005
1057
  if (elementName === "vertex") {
1006
- buffer.vertices.push(element.x, element.y, element.z);
1007
- if ("nx" in element && "ny" in element && "nz" in element) {
1008
- buffer.normals.push(element.nx, element.ny, element.nz);
1009
- }
1010
- if ("s" in element && "t" in element) {
1011
- buffer.uvs.push(element.s, element.t);
1012
- }
1013
- if ("red" in element && "green" in element && "blue" in element) {
1014
- buffer.colors.push(element.red, element.green, element.blue);
1058
+ for (const propertyName of Object.keys(element)) {
1059
+ switch (propertyName) {
1060
+ case "x":
1061
+ buffer.vertices.push(element.x, element.y, element.z);
1062
+ break;
1063
+ case "y":
1064
+ case "z":
1065
+ break;
1066
+ case "nx":
1067
+ if ("nx" in element && "ny" in element && "nz" in element) {
1068
+ buffer.normals.push(element.nx, element.ny, element.nz);
1069
+ }
1070
+ break;
1071
+ case "ny":
1072
+ case "nz":
1073
+ break;
1074
+ case "s":
1075
+ if ("s" in element && "t" in element) {
1076
+ buffer.uvs.push(element.s, element.t);
1077
+ }
1078
+ break;
1079
+ case "t":
1080
+ break;
1081
+ case "red":
1082
+ if ("red" in element && "green" in element && "blue" in element) {
1083
+ buffer.colors.push(element.red, element.green, element.blue);
1084
+ }
1085
+ break;
1086
+ case "green":
1087
+ case "blue":
1088
+ break;
1089
+ default:
1090
+ buffer[propertyName].push(element[propertyName]);
1091
+ }
1015
1092
  }
1016
1093
  } else if (elementName === "face") {
1017
1094
  const vertexIndices = element.vertex_indices || element.vertex_index;
@@ -1078,13 +1155,7 @@
1078
1155
  return [element, read];
1079
1156
  }
1080
1157
  function parseBinary(data, header) {
1081
- const attributes = {
1082
- indices: [],
1083
- vertices: [],
1084
- normals: [],
1085
- uvs: [],
1086
- colors: []
1087
- };
1158
+ const attributes = getPLYAttributes(header);
1088
1159
  const littleEndian = header.format === "binary_little_endian";
1089
1160
  const body = new DataView(data, header.headerLength);
1090
1161
  let result;
@@ -1166,21 +1237,22 @@
1166
1237
  }
1167
1238
  return header;
1168
1239
  }
1169
- function makePLYElementProperty2(propertValues, propertyNameMapping) {
1170
- const property = {
1171
- type: propertValues[0]
1172
- };
1173
- if (property.type === "list") {
1174
- property.name = propertValues[3];
1175
- property.countType = propertValues[1];
1176
- property.itemType = propertValues[2];
1177
- } else {
1178
- property.name = propertValues[1];
1179
- }
1180
- if (propertyNameMapping && property.name in propertyNameMapping) {
1181
- property.name = propertyNameMapping[property.name];
1240
+ function makePLYElementProperty2(propertyValues, propertyNameMapping) {
1241
+ const type = propertyValues[0];
1242
+ switch (type) {
1243
+ case "list":
1244
+ return {
1245
+ type,
1246
+ name: propertyValues[3],
1247
+ countType: propertyValues[1],
1248
+ itemType: propertyValues[2]
1249
+ };
1250
+ default:
1251
+ return {
1252
+ type,
1253
+ name: propertyValues[1]
1254
+ };
1182
1255
  }
1183
- return property;
1184
1256
  }
1185
1257
  async function parseASCII2(lineIterator, header) {
1186
1258
  const attributes = {
@@ -1199,7 +1271,7 @@
1199
1271
  currentElement2++;
1200
1272
  currentElementCount = 0;
1201
1273
  }
1202
- const element = parseASCIIElement2(header.elements[currentElement2].properties, line);
1274
+ const element = parsePLYElement2(header.elements[currentElement2].properties, line);
1203
1275
  handleElement2(attributes, header.elements[currentElement2].name, element);
1204
1276
  currentElementCount++;
1205
1277
  }
@@ -1230,7 +1302,7 @@
1230
1302
  throw new Error(type);
1231
1303
  }
1232
1304
  }
1233
- function parseASCIIElement2(properties, line) {
1305
+ function parsePLYElement2(properties, line) {
1234
1306
  const values = line.split(/\s+/);
1235
1307
  const element = {};
1236
1308
  for (let i = 0; i < properties.length; i++) {
@@ -1278,10 +1350,10 @@
1278
1350
  // src/index.ts
1279
1351
  var PLYLoader2 = {
1280
1352
  ...PLYLoader,
1281
- parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options),
1282
- parseTextSync: parsePLY,
1283
- parseSync: parsePLY,
1284
- parseInBatches: parsePLYInBatches
1353
+ parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
1354
+ parseTextSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
1355
+ parseSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
1356
+ parseInBatches: (arrayBuffer, options) => parsePLYInBatches(arrayBuffer, options?.ply)
1285
1357
  };
1286
1358
 
1287
1359
  // src/workers/ply-worker.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/ply",
3
- "version": "3.4.0-alpha.1",
3
+ "version": "3.4.0-alpha.3",
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": "3.4.0-alpha.1",
38
- "@loaders.gl/schema": "3.4.0-alpha.1"
37
+ "@loaders.gl/loader-utils": "3.4.0-alpha.3",
38
+ "@loaders.gl/schema": "3.4.0-alpha.3"
39
39
  },
40
- "gitHead": "4085b0323050e4361614471319a1fb4729547bbf"
40
+ "gitHead": "a954528dd1d78a1f128d8f6b07e4baeb7a296924"
41
41
  }
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type {LoaderWithParser} from '@loaders.gl/loader-utils';
2
2
  import {PLYLoader as PLYWorkerLoader} from './ply-loader';
3
- import parsePLY from './lib/parse-ply';
4
- import parsePLYInBatches from './lib/parse-ply-in-batches';
3
+ import {parsePLY} from './lib/parse-ply';
4
+ import {parsePLYInBatches} from './lib/parse-ply-in-batches';
5
5
 
6
6
  // PLYLoader
7
7
 
@@ -13,10 +13,10 @@ export {PLYWorkerLoader};
13
13
  export const PLYLoader = {
14
14
  ...PLYWorkerLoader,
15
15
  // Note: parsePLY supports both text and binary
16
- parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options), // TODO - this may not detect text correctly?
17
- parseTextSync: parsePLY,
18
- parseSync: parsePLY,
19
- parseInBatches: parsePLYInBatches
16
+ parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply), // TODO - this may not detect text correctly?
17
+ parseTextSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
18
+ parseSync: (arrayBuffer, options) => parsePLY(arrayBuffer, options?.ply),
19
+ parseInBatches: (arrayBuffer, options) => parsePLYInBatches(arrayBuffer, options?.ply)
20
20
  };
21
21
 
22
22
  export const _typecheckPLYLoader: LoaderWithParser = PLYLoader;
@@ -50,25 +50,47 @@ export default function normalizePLY(
50
50
  * @param attributes
51
51
  * @returns accessors []
52
52
  */
53
+ // eslint-disable-next-line complexity
53
54
  function getMeshAttributes(attributes: PLYAttributes): MeshAttributes {
54
55
  const accessors: MeshAttributes = {};
55
56
 
56
- accessors.POSITION = {value: new Float32Array(attributes.vertices), size: 3};
57
+ for (const attributeName of Object.keys(attributes)) {
58
+ switch (attributeName) {
59
+ case 'vertices':
60
+ if (attributes.vertices.length > 0) {
61
+ accessors.POSITION = {value: new Float32Array(attributes.vertices), size: 3};
62
+ }
63
+ break;
57
64
 
58
- // optional attributes data
65
+ // optional attributes data
66
+ case 'normals':
67
+ if (attributes.normals.length > 0) {
68
+ accessors.NORMAL = {value: new Float32Array(attributes.normals), size: 3};
69
+ }
70
+ break;
59
71
 
60
- if (attributes.normals.length > 0) {
61
- accessors.NORMAL = {value: new Float32Array(attributes.normals), size: 3};
62
- }
72
+ case 'uvs':
73
+ if (attributes.uvs.length > 0) {
74
+ accessors.TEXCOORD_0 = {value: new Float32Array(attributes.uvs), size: 2};
75
+ }
76
+ break;
63
77
 
64
- if (attributes.uvs.length > 0) {
65
- accessors.TEXCOORD_0 = {value: new Float32Array(attributes.uvs), size: 2};
66
- }
78
+ case 'colors':
79
+ if (attributes.colors.length > 0) {
80
+ // TODO - normalized shoud be based on `uchar` flag in source data?
81
+ accessors.COLOR_0 = {value: new Uint8Array(attributes.colors), size: 3, normalized: true};
82
+ }
83
+ break;
67
84
 
68
- if (attributes.colors.length > 0) {
69
- // TODO - normalized shoud be based on `uchar` flag in source data?
70
- accessors.COLOR_0 = {value: new Uint8Array(attributes.colors), size: 3, normalized: true};
71
- }
85
+ case 'indices':
86
+ break;
72
87
 
88
+ default:
89
+ if (attributes[attributeName].length > 0) {
90
+ accessors[attributeName] = {value: new Float32Array(attributes[attributeName]), size: 1};
91
+ }
92
+ break;
93
+ }
94
+ }
73
95
  return accessors;
74
96
  }
@@ -23,16 +23,16 @@
23
23
 
24
24
  import {makeLineIterator, makeTextDecoderIterator, forEach} from '@loaders.gl/loader-utils';
25
25
  import normalizePLY from './normalize-ply';
26
- import {PLYMesh, PLYHeader, ASCIIElement, PLYAttributes} from './ply-types';
26
+ import {PLYMesh, PLYHeader, PLYElement, PLYProperty, PLYAttributes} from './ply-types';
27
27
 
28
- let currentElement: ASCIIElement;
28
+ let currentElement: PLYElement;
29
29
 
30
30
  /**
31
31
  * PARSER
32
32
  * @param iterator
33
33
  * @param options
34
34
  */
35
- export default async function* parsePLYInBatches(
35
+ export async function* parsePLYInBatches(
36
36
  iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
37
37
  options: any
38
38
  ): AsyncIterable<PLYMesh> {
@@ -134,24 +134,22 @@ async function parsePLYHeader(
134
134
  return header;
135
135
  }
136
136
 
137
- function makePLYElementProperty(propertValues: string[], propertyNameMapping: []) {
138
- const property: {[index: string]: string} = {
139
- type: propertValues[0]
140
- };
141
-
142
- if (property.type === 'list') {
143
- property.name = propertValues[3];
144
- property.countType = propertValues[1];
145
- property.itemType = propertValues[2];
146
- } else {
147
- property.name = propertValues[1];
148
- }
149
-
150
- if (propertyNameMapping && property.name in propertyNameMapping) {
151
- property.name = propertyNameMapping[property.name];
137
+ function makePLYElementProperty(propertyValues: string[], propertyNameMapping: []): PLYProperty {
138
+ const type = propertyValues[0];
139
+ switch (type) {
140
+ case 'list':
141
+ return {
142
+ type,
143
+ name: propertyValues[3],
144
+ countType: propertyValues[1],
145
+ itemType: propertyValues[2]
146
+ };
147
+ default:
148
+ return {
149
+ type,
150
+ name: propertyValues[1]
151
+ };
152
152
  }
153
-
154
- return property;
155
153
  }
156
154
 
157
155
  // ASCII PARSING
@@ -182,7 +180,7 @@ async function parseASCII(lineIterator: AsyncIterable<string>, header: PLYHeader
182
180
  currentElementCount = 0;
183
181
  }
184
182
 
185
- const element = parseASCIIElement(header.elements[currentElement].properties, line);
183
+ const element = parsePLYElement(header.elements[currentElement].properties, line);
186
184
  handleElement(attributes, header.elements[currentElement].name, element);
187
185
  currentElementCount++;
188
186
  }
@@ -229,7 +227,7 @@ function parseASCIINumber(n: string, type: string): number {
229
227
  * @param line
230
228
  * @returns element
231
229
  */
232
- function parseASCIIElement(properties: any[], line: string) {
230
+ function parsePLYElement(properties: any[], line: string) {
233
231
  const values: any = line.split(/\s+/);
234
232
 
235
233
  const element = {};