@loaders.gl/obj 4.0.0-alpha.9 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -13,6 +13,4 @@ export declare const OBJLoader: LoaderWithParser<Mesh, never, OBJLoaderOptions>;
13
13
  * Loader for the MTL material format
14
14
  */
15
15
  export declare const MTLLoader: LoaderWithParser<MTLMaterial[], never, MTLLoaderOptions>;
16
- export declare const _typecheckOBJLoader: LoaderWithParser;
17
- export declare const _typecheckMTLLoader: LoaderWithParser;
18
16
  //# 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,KAAK,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAC;AAE7C,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,SAAS,IAAI,eAAe,EAAC,MAAM,cAAc,CAAC;AAE1D,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAKnD,OAAO,EAAC,eAAe,EAAC,CAAC;AAEzB;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,gBAAgB,CAKrE,CAAC;AAIF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAAgB,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,gBAAgB,CAK9E,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC;AAC/D,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;AAC/D,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAC;AAE7C,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,SAAS,IAAI,eAAe,EAAC,MAAM,cAAc,CAAC;AAE1D,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAKnD,OAAO,EAAC,eAAe,EAAC,CAAC;AAEzB;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,gBAAgB,CAKrE,CAAC;AAIF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAAgB,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,gBAAgB,CAK9E,CAAC"}
@@ -8,5 +8,4 @@ export type MTLLoaderOptions = LoaderOptions & {
8
8
  * Parses a Wavefront .mtl file specifying materials
9
9
  */
10
10
  export declare const MTLLoader: Loader<MTLMaterial[], never, LoaderOptions>;
11
- export declare const _typecheckMTLLoader: Loader;
12
11
  //# sourceMappingURL=mtl-loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mtl-loader.d.ts","sourceRoot":"","sources":["../src/mtl-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,iBAAiB,CAAC;AAMlE,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,eAAe,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,aAAa,CAYjE,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,MAAkB,CAAC"}
1
+ {"version":3,"file":"mtl-loader.d.ts","sourceRoot":"","sources":["../src/mtl-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,iBAAiB,CAAC;AAMlE,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,eAAe,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,aAAa,CAYjE,CAAC"}
@@ -7,5 +7,4 @@ export type OBJLoaderOptions = LoaderOptions & {
7
7
  * Worker loader for the OBJ geometry format
8
8
  */
9
9
  export declare const OBJLoader: Loader<Mesh, never, OBJLoaderOptions>;
10
- export declare const _typecheckOBJLoader: Loader;
11
10
  //# sourceMappingURL=obj-loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"obj-loader.d.ts","sourceRoot":"","sources":["../src/obj-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAC;AAMxC,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,EAAE,CAAC;CACV,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,gBAAgB,CAY3D,CAAC;AAOF,eAAO,MAAM,mBAAmB,EAAE,MAAkB,CAAC"}
1
+ {"version":3,"file":"obj-loader.d.ts","sourceRoot":"","sources":["../src/obj-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAC;AAMxC,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,EAAE,CAAC;CACV,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,gBAAgB,CAY3D,CAAC"}
@@ -125,7 +125,7 @@
125
125
  options,
126
126
  context: {
127
127
  ...context,
128
- parse: parseOnMainThread
128
+ _parse: parseOnMainThread
129
129
  }
130
130
  });
131
131
  WorkerBody.postMessage("done", { result });
@@ -138,7 +138,7 @@
138
138
  }
139
139
  };
140
140
  }
141
- function parseOnMainThread(arrayBuffer, options) {
141
+ function parseOnMainThread(arrayBuffer, loader, options, context) {
142
142
  return new Promise((resolve, reject) => {
143
143
  const id = requestId++;
144
144
  const onMessage = (type, payload2) => {
@@ -162,7 +162,12 @@
162
162
  WorkerBody.postMessage("process", payload);
163
163
  });
164
164
  }
165
- async function parseData({ loader, arrayBuffer, options, context }) {
165
+ async function parseData({
166
+ loader,
167
+ arrayBuffer,
168
+ options,
169
+ context
170
+ }) {
166
171
  let data;
167
172
  let parser;
168
173
  if (loader.parseSync || loader.parse) {
@@ -504,7 +509,7 @@
504
509
  switch (data[0]) {
505
510
  case "v":
506
511
  state.vertices.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
507
- if (data.length === 8) {
512
+ if (data.length >= 7) {
508
513
  state.colors.push(parseFloat(data[4]), parseFloat(data[5]), parseFloat(data[6]));
509
514
  }
510
515
  break;
@@ -720,7 +725,7 @@
720
725
  }
721
726
 
722
727
  // src/obj-loader.ts
723
- var VERSION = true ? "4.0.0-alpha.9" : "latest";
728
+ var VERSION = true ? "4.0.0-beta.1" : "latest";
724
729
  var OBJLoader = {
725
730
  name: "OBJ",
726
731
  id: "obj",
@@ -808,7 +813,7 @@
808
813
  }
809
814
 
810
815
  // src/mtl-loader.ts
811
- var VERSION2 = true ? "4.0.0-alpha.9" : "latest";
816
+ var VERSION2 = true ? "4.0.0-beta.1" : "latest";
812
817
  var MTLLoader = {
813
818
  name: "MTL",
814
819
  id: "mtl",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/obj",
3
- "version": "4.0.0-alpha.9",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "Framework-independent loader for the OBJ format",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -34,8 +34,8 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@babel/runtime": "^7.3.1",
37
- "@loaders.gl/loader-utils": "4.0.0-alpha.9",
38
- "@loaders.gl/schema": "4.0.0-alpha.9"
37
+ "@loaders.gl/loader-utils": "4.0.0-beta.1",
38
+ "@loaders.gl/schema": "4.0.0-beta.1"
39
39
  },
40
- "gitHead": "03ff81ab468f20f3bddeec787aa88d477a7e1c72"
40
+ "gitHead": "35c625e67132b0784e597d9ddabae8aefea29ff2"
41
41
  }
package/src/index.ts CHANGED
@@ -34,6 +34,3 @@ export const MTLLoader: LoaderWithParser<MTLMaterial[], never, MTLLoaderOptions>
34
34
  parseMTL(new TextDecoder().decode(arrayBuffer), options?.mtl),
35
35
  parseTextSync: (text: string, options?: MTLLoaderOptions) => parseMTL(text, options?.mtl)
36
36
  };
37
-
38
- export const _typecheckOBJLoader: LoaderWithParser = OBJLoader;
39
- export const _typecheckMTLLoader: LoaderWithParser = MTLLoader;
@@ -343,7 +343,7 @@ export function parseOBJMeshes(text) {
343
343
  switch (data[0]) {
344
344
  case 'v':
345
345
  state.vertices.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
346
- if (data.length === 8) {
346
+ if (data.length >= 7) {
347
347
  state.colors.push(parseFloat(data[4]), parseFloat(data[5]), parseFloat(data[6]));
348
348
  }
349
349
  break;
package/src/mtl-loader.ts CHANGED
@@ -27,5 +27,3 @@ export const MTLLoader: Loader<MTLMaterial[], never, LoaderOptions> = {
27
27
  mtl: {}
28
28
  }
29
29
  };
30
-
31
- export const _typecheckMTLLoader: Loader = MTLLoader;
package/src/obj-loader.ts CHANGED
@@ -30,5 +30,3 @@ function testOBJFile(text: string): boolean {
30
30
  // TODO - There could be comment line first
31
31
  return text[0] === 'v';
32
32
  }
33
-
34
- export const _typecheckOBJLoader: Loader = OBJLoader;
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- const moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
package/dist/index.js DELETED
@@ -1,27 +0,0 @@
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)
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)
25
- };
26
- exports._typecheckOBJLoader = exports.OBJLoader;
27
- exports._typecheckMTLLoader = exports.MTLLoader;
@@ -1,37 +0,0 @@
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
- }
13
- }
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 };
21
- }
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 }] };
35
- }
36
- return { name, type, nullable: false, metadata };
37
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,201 +0,0 @@
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
- */