@loaders.gl/obj 3.1.3 → 3.1.4

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 (58) hide show
  1. package/dist/dist.min.js +269 -164
  2. package/dist/es5/index.js +42 -4
  3. package/dist/es5/index.js.map +1 -1
  4. package/dist/es5/lib/parse-mtl.js +110 -0
  5. package/dist/es5/lib/parse-mtl.js.map +1 -0
  6. package/dist/es5/lib/parse-obj-meshes.js +559 -0
  7. package/dist/es5/lib/parse-obj-meshes.js.map +1 -0
  8. package/dist/es5/lib/parse-obj.js +84 -526
  9. package/dist/es5/lib/parse-obj.js.map +1 -1
  10. package/dist/es5/mtl-loader.js +26 -0
  11. package/dist/es5/mtl-loader.js.map +1 -0
  12. package/dist/es5/obj-loader.js +1 -1
  13. package/dist/es5/obj-loader.js.map +1 -1
  14. package/dist/esm/index.js +10 -3
  15. package/dist/esm/index.js.map +1 -1
  16. package/dist/esm/lib/parse-mtl.js +86 -0
  17. package/dist/esm/lib/parse-mtl.js.map +1 -0
  18. package/dist/esm/lib/parse-obj-meshes.js +458 -0
  19. package/dist/esm/lib/parse-obj-meshes.js.map +1 -0
  20. package/dist/esm/lib/parse-obj.js +71 -437
  21. package/dist/esm/lib/parse-obj.js.map +1 -1
  22. package/dist/esm/mtl-loader.js +16 -0
  23. package/dist/esm/mtl-loader.js.map +1 -0
  24. package/dist/esm/obj-loader.js +1 -1
  25. package/dist/esm/obj-loader.js.map +1 -1
  26. package/dist/index.d.ts +41 -4
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +16 -7
  29. package/dist/lib/parse-mtl.d.ts +34 -0
  30. package/dist/lib/parse-mtl.d.ts.map +1 -0
  31. package/dist/lib/parse-mtl.js +201 -0
  32. package/dist/lib/parse-obj-meshes.d.ts +5 -0
  33. package/dist/lib/parse-obj-meshes.d.ts.map +1 -0
  34. package/dist/lib/parse-obj-meshes.js +440 -0
  35. package/dist/lib/parse-obj.d.ts +12 -4
  36. package/dist/lib/parse-obj.d.ts.map +1 -1
  37. package/dist/lib/parse-obj.js +67 -434
  38. package/dist/mtl-loader.d.ts +24 -0
  39. package/dist/mtl-loader.d.ts.map +1 -0
  40. package/dist/mtl-loader.js +24 -0
  41. package/dist/obj-loader.d.ts +5 -2
  42. package/dist/obj-loader.d.ts.map +1 -1
  43. package/dist/obj-worker.js +99 -9
  44. package/package.json +5 -5
  45. package/src/index.ts +21 -3
  46. package/src/lib/parse-mtl.ts +246 -0
  47. package/src/lib/parse-obj-meshes.ts +525 -0
  48. package/src/lib/parse-obj.ts +66 -508
  49. package/src/mtl-loader.ts +31 -0
  50. package/src/obj-loader.ts +6 -2
  51. package/dist/es5/lib/load-obj.js +0 -121
  52. package/dist/es5/lib/load-obj.js.map +0 -1
  53. package/dist/esm/lib/load-obj.js +0 -92
  54. package/dist/esm/lib/load-obj.js.map +0 -1
  55. package/dist/lib/load-obj.d.ts +0 -14
  56. package/dist/lib/load-obj.d.ts.map +0 -1
  57. package/dist/lib/load-obj.js +0 -73
  58. package/src/lib/load-obj.ts +0 -83
package/dist/index.d.ts CHANGED
@@ -1,12 +1,16 @@
1
1
  import type { LoaderWithParser } from '@loaders.gl/loader-utils';
2
- import loadOBJ from './lib/load-obj';
2
+ import type { OBJLoaderOptions } from './obj-loader';
3
3
  import { OBJLoader as OBJWorkerLoader } from './obj-loader';
4
+ import type { MTLLoaderOptions } from './mtl-loader';
4
5
  export { OBJWorkerLoader };
5
6
  /**
6
7
  * Loader for the OBJ geometry format
7
8
  */
8
9
  export declare const OBJLoader: {
9
- parse: (arrayBuffer: any, options: any) => Promise<{
10
+ parse: (arrayBuffer: ArrayBuffer, options?: OBJLoaderOptions | undefined) => Promise<{
11
+ /**
12
+ * Loader for the MTL material format
13
+ */
10
14
  loaderData: {
11
15
  header: {};
12
16
  };
@@ -18,7 +22,21 @@ export declare const OBJLoader: {
18
22
  mode: number;
19
23
  attributes: import("@loaders.gl/schema").MeshAttributes;
20
24
  }>;
21
- parseTextSync: typeof loadOBJ;
25
+ parseTextSync: (text: string, options?: OBJLoaderOptions | undefined) => {
26
+ /**
27
+ * Loader for the MTL material format
28
+ */
29
+ loaderData: {
30
+ header: {};
31
+ };
32
+ schema: import("@loaders.gl/schema").Schema;
33
+ header: {
34
+ vertexCount: number;
35
+ boundingBox: [[number, number, number], [number, number, number]];
36
+ };
37
+ mode: number;
38
+ attributes: import("@loaders.gl/schema").MeshAttributes;
39
+ };
22
40
  name: string;
23
41
  id: string;
24
42
  module: string;
@@ -26,10 +44,29 @@ export declare const OBJLoader: {
26
44
  worker: boolean;
27
45
  extensions: string[];
28
46
  mimeTypes: string[];
29
- testText: (text: any) => boolean;
47
+ testText: (text: string) => boolean;
30
48
  options: {
31
49
  obj: {};
32
50
  };
33
51
  };
52
+ /**
53
+ * Loader for the MTL material format
54
+ */
55
+ export declare const MTLLoader: {
56
+ parse: (arrayBuffer: ArrayBuffer, options?: MTLLoaderOptions | undefined) => Promise<import("./lib/parse-mtl").MTLMaterial[]>;
57
+ parseTextSync: (text: string, options?: MTLLoaderOptions | undefined) => import("./lib/parse-mtl").MTLMaterial[];
58
+ name: string;
59
+ id: string;
60
+ module: string;
61
+ version: any;
62
+ worker: boolean;
63
+ extensions: string[];
64
+ mimeTypes: string[];
65
+ testText: (text: string) => boolean;
66
+ options: {
67
+ mtl: {};
68
+ };
69
+ };
34
70
  export declare const _typecheckOBJLoader: LoaderWithParser;
71
+ export declare const _typecheckMTLLoader: LoaderWithParser;
35
72
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAC,SAAS,IAAI,eAAe,EAAC,MAAM,cAAc,CAAC;AAI1D,OAAO,EAAC,eAAe,EAAC,CAAC;AAEzB;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;CAIrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAG/D,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,SAAS,IAAI,eAAe,EAAC,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAKnD,OAAO,EAAC,eAAe,EAAC,CAAC;AAEzB;;GAEG;AACH,eAAO,MAAM,SAAS;yBAEO,WAAW;QAOxC;;WAEG;;;;;;;;;;;;0BAPqB,MAAM;QAK9B;;WAEG;;;;;;;;;;;;;;;;;;;;;;;CANF,CAAC;AAIF;;GAEG;AACH,eAAO,MAAM,SAAS;yBAEO,WAAW;0BAEhB,MAAM;;;;;;;;;;;;CAC7B,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC;AAC/D,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC"}
package/dist/index.js CHANGED
@@ -1,18 +1,27 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports._typecheckOBJLoader = exports.OBJLoader = exports.OBJWorkerLoader = void 0;
7
- const load_obj_1 = __importDefault(require("./lib/load-obj"));
3
+ exports._typecheckMTLLoader = exports._typecheckOBJLoader = exports.MTLLoader = exports.OBJLoader = exports.OBJWorkerLoader = void 0;
4
+ const parse_obj_1 = require("./lib/parse-obj");
5
+ const parse_mtl_1 = require("./lib/parse-mtl");
8
6
  const obj_loader_1 = require("./obj-loader");
9
7
  Object.defineProperty(exports, "OBJWorkerLoader", { enumerable: true, get: function () { return obj_loader_1.OBJLoader; } });
8
+ const mtl_loader_1 = require("./mtl-loader");
10
9
  /**
11
10
  * Loader for the OBJ geometry format
12
11
  */
13
12
  exports.OBJLoader = {
14
13
  ...obj_loader_1.OBJLoader,
15
- parse: async (arrayBuffer, options) => (0, load_obj_1.default)(new TextDecoder().decode(arrayBuffer), options),
16
- parseTextSync: load_obj_1.default
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)
16
+ };
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)
17
25
  };
18
26
  exports._typecheckOBJLoader = exports.OBJLoader;
27
+ exports._typecheckMTLLoader = exports.MTLLoader;
@@ -0,0 +1,34 @@
1
+ export declare 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 declare 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,oBAAY,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,oBAAY,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"}