@loaders.gl/obj 4.0.0-alpha.1 → 4.0.0-alpha.11

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 (89) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/dist.min.js +744 -0
  5. package/dist/es5/bundle.js +6 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/index.js +74 -0
  8. package/dist/es5/index.js.map +1 -0
  9. package/dist/es5/lib/get-obj-schema.js +54 -0
  10. package/dist/es5/lib/get-obj-schema.js.map +1 -0
  11. package/dist/es5/lib/obj-types.js +2 -0
  12. package/dist/es5/lib/obj-types.js.map +1 -0
  13. package/dist/es5/lib/parse-mtl.js +86 -0
  14. package/dist/es5/lib/parse-mtl.js.map +1 -0
  15. package/dist/es5/lib/parse-obj-meshes.js +486 -0
  16. package/dist/es5/lib/parse-obj-meshes.js.map +1 -0
  17. package/dist/es5/lib/parse-obj.js +100 -0
  18. package/dist/es5/lib/parse-obj.js.map +1 -0
  19. package/dist/es5/mtl-loader.js +26 -0
  20. package/dist/es5/mtl-loader.js.map +1 -0
  21. package/dist/es5/obj-loader.js +27 -0
  22. package/dist/es5/obj-loader.js.map +1 -0
  23. package/dist/es5/workers/obj-worker.js +6 -0
  24. package/dist/es5/workers/obj-worker.js.map +1 -0
  25. package/dist/esm/bundle.js +4 -0
  26. package/dist/esm/bundle.js.map +1 -0
  27. package/dist/esm/index.js +18 -0
  28. package/dist/esm/index.js.map +1 -0
  29. package/dist/esm/lib/get-obj-schema.js +49 -0
  30. package/dist/esm/lib/get-obj-schema.js.map +1 -0
  31. package/dist/esm/lib/obj-types.js +2 -0
  32. package/dist/esm/lib/obj-types.js.map +1 -0
  33. package/dist/esm/lib/parse-mtl.js +68 -0
  34. package/dist/esm/lib/parse-mtl.js.map +1 -0
  35. package/dist/esm/lib/parse-obj-meshes.js +385 -0
  36. package/dist/esm/lib/parse-obj-meshes.js.map +1 -0
  37. package/dist/{lib/load-obj.js → esm/lib/parse-obj.js} +5 -15
  38. package/dist/esm/lib/parse-obj.js.map +1 -0
  39. package/dist/esm/mtl-loader.js +16 -0
  40. package/dist/esm/mtl-loader.js.map +1 -0
  41. package/dist/esm/obj-loader.js +19 -0
  42. package/dist/esm/obj-loader.js.map +1 -0
  43. package/dist/esm/workers/obj-worker.js +4 -0
  44. package/dist/esm/workers/obj-worker.js.map +1 -0
  45. package/dist/index.d.ts +18 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +26 -8
  48. package/dist/lib/get-obj-schema.d.ts +4 -0
  49. package/dist/lib/get-obj-schema.d.ts.map +1 -0
  50. package/dist/lib/get-obj-schema.js +33 -33
  51. package/dist/lib/obj-types.d.ts +1 -0
  52. package/dist/lib/obj-types.d.ts.map +1 -0
  53. package/dist/lib/obj-types.js +1 -2
  54. package/dist/lib/parse-mtl.d.ts +34 -0
  55. package/dist/lib/parse-mtl.d.ts.map +1 -0
  56. package/dist/lib/parse-mtl.js +201 -0
  57. package/dist/lib/parse-obj-meshes.d.ts +5 -0
  58. package/dist/lib/parse-obj-meshes.d.ts.map +1 -0
  59. package/dist/lib/parse-obj-meshes.js +440 -0
  60. package/dist/lib/parse-obj.d.ts +3 -0
  61. package/dist/lib/parse-obj.d.ts.map +1 -0
  62. package/dist/lib/parse-obj.js +63 -449
  63. package/dist/mtl-loader.d.ts +12 -0
  64. package/dist/mtl-loader.d.ts.map +1 -0
  65. package/dist/mtl-loader.js +24 -0
  66. package/dist/obj-loader.d.ts +11 -0
  67. package/dist/obj-loader.d.ts.map +1 -0
  68. package/dist/obj-loader.js +24 -18
  69. package/dist/obj-worker.js +213 -507
  70. package/dist/workers/obj-worker.d.ts +2 -0
  71. package/dist/workers/obj-worker.d.ts.map +1 -0
  72. package/dist/workers/obj-worker.js +5 -4
  73. package/package.json +9 -9
  74. package/src/index.ts +25 -4
  75. package/src/lib/get-obj-schema.ts +24 -20
  76. package/src/lib/parse-mtl.ts +246 -0
  77. package/src/lib/parse-obj-meshes.ts +525 -0
  78. package/src/lib/parse-obj.ts +67 -508
  79. package/src/mtl-loader.ts +31 -0
  80. package/src/obj-loader.ts +8 -3
  81. package/dist/bundle.js.map +0 -1
  82. package/dist/index.js.map +0 -1
  83. package/dist/lib/get-obj-schema.js.map +0 -1
  84. package/dist/lib/load-obj.js.map +0 -1
  85. package/dist/lib/obj-types.js.map +0 -1
  86. package/dist/lib/parse-obj.js.map +0 -1
  87. package/dist/obj-loader.js.map +0 -1
  88. package/src/lib/load-obj.ts +0 -83
  89. /package/src/workers/{obj-worker.js → obj-worker.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,9 +1,27 @@
1
- import loadOBJ from './lib/load-obj';
2
- import { OBJLoader as OBJWorkerLoader } from './obj-loader';
3
- export { OBJWorkerLoader };
4
- export const OBJLoader = { ...OBJWorkerLoader,
5
- parse: async (arrayBuffer, options) => loadOBJ(new TextDecoder().decode(arrayBuffer), options),
6
- parseTextSync: loadOBJ
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._typecheckMTLLoader = exports._typecheckOBJLoader = exports.MTLLoader = exports.OBJLoader = exports.OBJWorkerLoader = void 0;
4
+ const parse_obj_1 = require("./lib/parse-obj");
5
+ const obj_loader_1 = require("./obj-loader");
6
+ Object.defineProperty(exports, "OBJWorkerLoader", { enumerable: true, get: function () { return obj_loader_1.OBJLoader; } });
7
+ const parse_mtl_1 = require("./lib/parse-mtl");
8
+ const mtl_loader_1 = require("./mtl-loader");
9
+ /**
10
+ * Loader for the OBJ geometry format
11
+ */
12
+ exports.OBJLoader = {
13
+ ...obj_loader_1.OBJLoader,
14
+ parse: async (arrayBuffer, options) => (0, parse_obj_1.parseOBJ)(new TextDecoder().decode(arrayBuffer), options),
15
+ parseTextSync: (text, options) => (0, parse_obj_1.parseOBJ)(text, options)
7
16
  };
8
- export const _typecheckOBJLoader = OBJLoader;
9
- //# sourceMappingURL=index.js.map
17
+ // MTLLoader
18
+ /**
19
+ * Loader for the MTL material format
20
+ */
21
+ exports.MTLLoader = {
22
+ ...mtl_loader_1.MTLLoader,
23
+ parse: async (arrayBuffer, options) => (0, parse_mtl_1.parseMTL)(new TextDecoder().decode(arrayBuffer), options?.mtl),
24
+ parseTextSync: (text, options) => (0, parse_mtl_1.parseMTL)(text, options?.mtl)
25
+ };
26
+ exports._typecheckOBJLoader = exports.OBJLoader;
27
+ exports._typecheckMTLLoader = exports.MTLLoader;
@@ -0,0 +1,4 @@
1
+ import type { Schema, MeshAttribute } from '@loaders.gl/schema';
2
+ /** Get Mesh Schema */
3
+ export declare function getOBJSchema(attributes: Record<string, MeshAttribute>, metadata?: Record<string, unknown>): Schema;
4
+ //# sourceMappingURL=get-obj-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-obj-schema.d.ts","sourceRoot":"","sources":["../../src/lib/get-obj-schema.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAyB,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAGrF,sBAAsB;AACtB,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EACzC,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACrC,MAAM,CAgBR"}
@@ -1,37 +1,37 @@
1
- import { Schema, Field, FixedSizeList, getArrowTypeFromTypedArray } from '@loaders.gl/schema';
2
- export function getOBJSchema(attributes, metadata = {}) {
3
- let metadataMap;
4
-
5
- for (const key in metadata) {
6
- metadataMap = metadataMap || new Map();
7
-
8
- if (key !== 'value') {
9
- metadataMap.set(key, JSON.stringify(metadata[key]));
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getOBJSchema = void 0;
5
+ const schema_1 = require("@loaders.gl/schema");
6
+ /** Get Mesh Schema */
7
+ function getOBJSchema(attributes, metadata = {}) {
8
+ const stringMetadata = {};
9
+ for (const key in metadata) {
10
+ if (key !== 'value') {
11
+ stringMetadata[key] = JSON.stringify(metadata[key]);
12
+ }
10
13
  }
11
- }
12
-
13
- const fields = [];
14
-
15
- for (const attributeName in attributes) {
16
- const attribute = attributes[attributeName];
17
- const field = getArrowFieldFromAttribute(attributeName, attribute);
18
- fields.push(field);
19
- }
20
-
21
- return new Schema(fields, metadataMap);
14
+ const fields = [];
15
+ for (const attributeName in attributes) {
16
+ const attribute = attributes[attributeName];
17
+ const field = getFieldFromAttribute(attributeName, attribute);
18
+ fields.push(field);
19
+ }
20
+ return { fields, metadata: stringMetadata };
22
21
  }
23
-
24
- function getArrowFieldFromAttribute(attributeName, attribute) {
25
- const metadataMap = new Map();
26
-
27
- for (const key in attribute) {
28
- if (key !== 'value') {
29
- metadataMap.set(key, JSON.stringify(attribute[key]));
22
+ exports.getOBJSchema = getOBJSchema;
23
+ /** Get a Field describing the column from an OBJ attribute */
24
+ function getFieldFromAttribute(name, attribute) {
25
+ const metadata = {};
26
+ for (const key in attribute) {
27
+ if (key !== 'value') {
28
+ metadata[key] = JSON.stringify(attribute[key]);
29
+ }
30
+ }
31
+ let { type } = (0, schema_1.getDataTypeFromArray)(attribute.value);
32
+ const isSingleValue = attribute.size === 1 || attribute.size === undefined;
33
+ if (!isSingleValue) {
34
+ type = { type: 'fixed-size-list', listSize: attribute.size, children: [{ name: 'values', type }] };
30
35
  }
31
- }
32
-
33
- const type = getArrowTypeFromTypedArray(attribute.value);
34
- const isSingleValue = !('size' in attribute) || attribute.size === 1;
35
- return isSingleValue ? new Field(attributeName, type, false, metadataMap) : new Field(attributeName, new FixedSizeList(attribute.size, new Field('value', type)), false, metadataMap);
36
+ return { name, type, nullable: false, metadata };
36
37
  }
37
- //# sourceMappingURL=get-obj-schema.js.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=obj-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"obj-types.d.ts","sourceRoot":"","sources":["../../src/lib/obj-types.ts"],"names":[],"mappings":""}
@@ -1,2 +1 @@
1
-
2
- //# sourceMappingURL=obj-types.js.map
1
+ "use strict";
@@ -0,0 +1,34 @@
1
+ export type MTLMaterial = {
2
+ name: string;
3
+ ambientColor?: [number, number, number];
4
+ diffuseColor?: [number, number, number];
5
+ specularColor?: [number, number, number];
6
+ emissiveColor?: [number, number, number];
7
+ shininess?: number;
8
+ refraction?: number;
9
+ illumination?: number;
10
+ diffuseTextureUrl?: string;
11
+ emissiveTextureUrl?: string;
12
+ specularTextureUrl?: string;
13
+ };
14
+ /**
15
+ * Set of options on how to construct materials
16
+ * @param normalizeRGB: RGBs need to be normalized to 0-1 from 0-255 (Default: false, assumed to be already normalized)
17
+ * @param ignoreZeroRGBs: Ignore values of RGBs (Ka,Kd,Ks) that are all 0's Default: false
18
+ * @param baseUrl - Url relative to which textures are loaded
19
+ */
20
+ export type ParseMTLOptions = {
21
+ normalizeRGB?: boolean;
22
+ ignoreZeroRGBs?: boolean;
23
+ baseUrl?: string;
24
+ };
25
+ /**
26
+ * Parses a MTL file.
27
+ * Parses a Wavefront .mtl file specifying materials
28
+ * http://paulbourke.net/dataformats/mtl/
29
+ * https://www.loc.gov/preservation/digital/formats/fdd/fdd000508.shtml
30
+ *
31
+ * @param text - Content of MTL file
32
+ */
33
+ export declare function parseMTL(text: string, options?: ParseMTLOptions): MTLMaterial[];
34
+ //# sourceMappingURL=parse-mtl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-mtl.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mtl.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAEzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAIF;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;GAOG;AAEH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,WAAW,EAAE,CA2H/E"}
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ // Forked from THREE.js under MIT license
4
+ // https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/MTLLoader.js
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseMTL = void 0;
7
+ const DELIMITER_PATTERN = /\s+/;
8
+ /**
9
+ * Parses a MTL file.
10
+ * Parses a Wavefront .mtl file specifying materials
11
+ * http://paulbourke.net/dataformats/mtl/
12
+ * https://www.loc.gov/preservation/digital/formats/fdd/fdd000508.shtml
13
+ *
14
+ * @param text - Content of MTL file
15
+ */
16
+ // eslint-disable-next-line complexity
17
+ function parseMTL(text, options) {
18
+ // const materialsInfo: Record<string, MTLMaterial> = {};
19
+ const materials = [];
20
+ let currentMaterial = { name: 'placeholder' };
21
+ const lines = text.split('\n');
22
+ for (let line of lines) {
23
+ line = line.trim();
24
+ if (line.length === 0 || line.charAt(0) === '#') {
25
+ // Blank line or comment ignore
26
+ continue; // eslint-disable-line no-continue
27
+ }
28
+ const pos = line.indexOf(' ');
29
+ let key = pos >= 0 ? line.substring(0, pos) : line;
30
+ key = key.toLowerCase();
31
+ let value = pos >= 0 ? line.substring(pos + 1) : '';
32
+ value = value.trim();
33
+ switch (key) {
34
+ case 'newmtl':
35
+ // New material
36
+ currentMaterial = { name: value };
37
+ // insert into map
38
+ materials.push(currentMaterial);
39
+ break;
40
+ case 'ka': // Ka
41
+ currentMaterial.ambientColor = parseColor(value);
42
+ break;
43
+ case 'kd':
44
+ // Kd: Diffuse color (color under white light) using RGB values
45
+ currentMaterial.diffuseColor = parseColor(value);
46
+ break;
47
+ case 'map_kd':
48
+ // Diffuse texture map
49
+ currentMaterial.diffuseTextureUrl = value;
50
+ // setMapForType('map', value);
51
+ break;
52
+ case 'ks':
53
+ // Specular color (color when light is reflected from shiny surface) using RGB values
54
+ currentMaterial.specularColor = parseColor(value);
55
+ break;
56
+ case 'map_ks':
57
+ // Specular map
58
+ currentMaterial.specularTextureUrl = value;
59
+ // setMapForType('specularMap', value);
60
+ break;
61
+ case 'ke':
62
+ // Emissive using RGB values
63
+ currentMaterial.emissiveColor = parseColor(value);
64
+ break;
65
+ case 'map_ke':
66
+ // Emissive map
67
+ currentMaterial.emissiveTextureUrl = value;
68
+ // setMapForType('emissiveMap', value);
69
+ break;
70
+ case 'ns':
71
+ // Ns is material specular exponent (defines the focus of the specular highlight)
72
+ // A high exponent results in a tight, concentrated highlight. Ns values normally range from 0 to 1000.
73
+ currentMaterial.shininess = parseFloat(value);
74
+ break;
75
+ case 'map_ns':
76
+ // Ns is material specular exponent
77
+ // TODO?
78
+ // currentMaterial.shininessMap = parseFloat(value);
79
+ break;
80
+ case 'ni':
81
+ currentMaterial.refraction = parseFloat(value);
82
+ break;
83
+ case 'illum':
84
+ currentMaterial.illumination = parseFloat(value);
85
+ break;
86
+ default:
87
+ // log unknown message?
88
+ break;
89
+ /*
90
+ case 'norm':
91
+ setMapForType('normalMap', value);
92
+ break;
93
+
94
+ case 'map_bump':
95
+ case 'bump':
96
+ // Bump texture map
97
+ setMapForType('bumpMap', value);
98
+ break;
99
+
100
+ case 'd':
101
+ n = parseFloat(value);
102
+ if (n < 1) {
103
+ params.opacity = n;
104
+ params.transparent = true;
105
+ }
106
+ break;
107
+
108
+ case 'map_d':
109
+ // Alpha map
110
+ setMapForType('alphaMap', value);
111
+ params.transparent = true;
112
+ break;
113
+
114
+ case 'tr':
115
+ n = parseFloat(value);
116
+ if (this.options && this.options.invertTrProperty) n = 1 - n;
117
+ if (n > 0) {
118
+ params.opacity = 1 - n;
119
+ params.transparent = true;
120
+ }
121
+ */
122
+ }
123
+ }
124
+ return materials;
125
+ }
126
+ exports.parseMTL = parseMTL;
127
+ function parseColor(value, options) {
128
+ const rgb = value.split(DELIMITER_PATTERN, 3);
129
+ const color = [
130
+ parseFloat(rgb[0]),
131
+ parseFloat(rgb[1]),
132
+ parseFloat(rgb[2])
133
+ ];
134
+ // TODO auto detect big values?
135
+ // if (this.options && this.options.normalizeRGB) {
136
+ // value = [ value[ 0 ] / 255, value[ 1 ] / 255, value[ 2 ] / 255 ];
137
+ // }
138
+ // if (this.options && this.options.ignoreZeroRGBs) {
139
+ // if (value[ 0 ] === 0 && value[ 1 ] === 0 && value[ 2 ] === 0) {
140
+ // // ignore
141
+ // save = false;
142
+ // }
143
+ // }
144
+ return color;
145
+ }
146
+ /* TODO parse url options
147
+ function parseTexture(value, matParams) {
148
+ const texParams = {
149
+ scale: new Vector2(1, 1),
150
+ offset: new Vector2(0, 0)
151
+ };
152
+
153
+ const items = value.split(/\s+/);
154
+ let pos;
155
+
156
+ pos = items.indexOf('-bm');
157
+ if (pos >= 0) {
158
+ matParams.bumpScale = parseFloat(items[ pos + 1 ]);
159
+ items.splice(pos, 2);
160
+ }
161
+
162
+ pos = items.indexOf('-s');
163
+ if (pos >= 0) {
164
+ texParams.scale.set(parseFloat(items[ pos + 1 ]), parseFloat(items[ pos + 2 ]));
165
+ items.splice(pos, 4); // we expect 3 parameters here!
166
+
167
+ }
168
+
169
+ pos = items.indexOf('-o');
170
+
171
+ if (pos >= 0) {
172
+ texParams.offset.set(parseFloat(items[ pos + 1 ]), parseFloat(items[ pos + 2 ]));
173
+ items.splice(pos, 4); // we expect 3 parameters here!
174
+ }
175
+
176
+ texParams.url = items.join(' ').trim();
177
+ return texParams;
178
+ }
179
+
180
+ *function resolveURL(baseUrl, url) {
181
+ * baseUrl?: string;
182
+ // Absolute URL
183
+ if (/^https?:\/\//i.test(url)) return url;
184
+ return baseUrl + url;
185
+ }
186
+
187
+ function setMapForType(mapType, value) {
188
+ if (params[ mapType ]) return; // Keep the first encountered texture
189
+
190
+ const texParams = scope.getTextureParams(value, params);
191
+ const map = scope.loadTexture(resolveURL(scope.baseUrl, texParams.url));
192
+
193
+ map.repeat.copy(texParams.scale);
194
+ map.offset.copy(texParams.offset);
195
+
196
+ map.wrapS = scope.wrap;
197
+ map.wrapT = scope.wrap;
198
+
199
+ params[ mapType ] = map;
200
+ }
201
+ */
@@ -0,0 +1,5 @@
1
+ export declare function parseOBJMeshes(text: any): {
2
+ meshes: never[];
3
+ materials: never[];
4
+ };
5
+ //# sourceMappingURL=parse-obj-meshes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-obj-meshes.d.ts","sourceRoot":"","sources":["../../src/lib/parse-obj-meshes.ts"],"names":[],"mappings":"AAgTA,wBAAgB,cAAc,CAAC,IAAI,KAAA;;;EA4NlC"}