@loaders.gl/obj 4.0.0-alpha.5 → 4.0.0-alpha.7

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 (80) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +97 -549
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/index.js +74 -0
  6. package/dist/es5/index.js.map +1 -0
  7. package/dist/es5/lib/get-obj-schema.js +54 -0
  8. package/dist/es5/lib/get-obj-schema.js.map +1 -0
  9. package/dist/es5/lib/obj-types.js +2 -0
  10. package/dist/es5/lib/obj-types.js.map +1 -0
  11. package/dist/es5/lib/parse-mtl.js +86 -0
  12. package/dist/es5/lib/parse-mtl.js.map +1 -0
  13. package/dist/es5/lib/parse-obj-meshes.js +486 -0
  14. package/dist/es5/lib/parse-obj-meshes.js.map +1 -0
  15. package/dist/es5/lib/parse-obj.js +100 -0
  16. package/dist/es5/lib/parse-obj.js.map +1 -0
  17. package/dist/es5/mtl-loader.js +26 -0
  18. package/dist/es5/mtl-loader.js.map +1 -0
  19. package/dist/es5/obj-loader.js +27 -0
  20. package/dist/es5/obj-loader.js.map +1 -0
  21. package/dist/es5/workers/obj-worker.js +6 -0
  22. package/dist/es5/workers/obj-worker.js.map +1 -0
  23. package/dist/esm/bundle.js +4 -0
  24. package/dist/esm/bundle.js.map +1 -0
  25. package/dist/esm/index.js +18 -0
  26. package/dist/esm/index.js.map +1 -0
  27. package/dist/esm/lib/get-obj-schema.js +49 -0
  28. package/dist/esm/lib/get-obj-schema.js.map +1 -0
  29. package/dist/esm/lib/obj-types.js +2 -0
  30. package/dist/esm/lib/obj-types.js.map +1 -0
  31. package/dist/esm/lib/parse-mtl.js +68 -0
  32. package/dist/esm/lib/parse-mtl.js.map +1 -0
  33. package/dist/esm/lib/parse-obj-meshes.js +385 -0
  34. package/dist/esm/lib/parse-obj-meshes.js.map +1 -0
  35. package/dist/esm/lib/parse-obj.js +82 -0
  36. package/dist/esm/lib/parse-obj.js.map +1 -0
  37. package/dist/esm/mtl-loader.js +16 -0
  38. package/dist/esm/mtl-loader.js.map +1 -0
  39. package/dist/esm/obj-loader.js +19 -0
  40. package/dist/esm/obj-loader.js.map +1 -0
  41. package/dist/esm/workers/obj-worker.js +4 -0
  42. package/dist/esm/workers/obj-worker.js.map +1 -0
  43. package/dist/index.d.ts +4 -58
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +25 -14
  46. package/dist/lib/get-obj-schema.d.ts +3 -2
  47. package/dist/lib/get-obj-schema.d.ts.map +1 -1
  48. package/dist/lib/get-obj-schema.js +33 -33
  49. package/dist/lib/obj-types.js +1 -2
  50. package/dist/lib/parse-mtl.d.ts +2 -2
  51. package/dist/lib/parse-mtl.d.ts.map +1 -1
  52. package/dist/lib/parse-mtl.js +185 -70
  53. package/dist/lib/parse-obj-meshes.js +408 -426
  54. package/dist/lib/parse-obj.d.ts +2 -13
  55. package/dist/lib/parse-obj.d.ts.map +1 -1
  56. package/dist/lib/parse-obj.js +66 -86
  57. package/dist/mtl-loader.d.ts +3 -15
  58. package/dist/mtl-loader.d.ts.map +1 -1
  59. package/dist/mtl-loader.js +23 -15
  60. package/dist/obj-loader.d.ts +3 -16
  61. package/dist/obj-loader.d.ts.map +1 -1
  62. package/dist/obj-loader.js +24 -18
  63. package/dist/obj-worker.js +133 -517
  64. package/dist/workers/obj-worker.js +5 -4
  65. package/package.json +6 -6
  66. package/src/index.ts +6 -3
  67. package/src/lib/get-obj-schema.ts +24 -20
  68. package/src/lib/parse-obj.ts +4 -3
  69. package/src/mtl-loader.ts +2 -2
  70. package/src/obj-loader.ts +2 -1
  71. package/dist/bundle.js.map +0 -1
  72. package/dist/index.js.map +0 -1
  73. package/dist/lib/get-obj-schema.js.map +0 -1
  74. package/dist/lib/obj-types.js.map +0 -1
  75. package/dist/lib/parse-mtl.js.map +0 -1
  76. package/dist/lib/parse-obj-meshes.js.map +0 -1
  77. package/dist/lib/parse-obj.js.map +0 -1
  78. package/dist/mtl-loader.js.map +0 -1
  79. package/dist/obj-loader.js.map +0 -1
  80. package/dist/workers/obj-worker.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,72 +1,18 @@
1
1
  import type { LoaderWithParser } from '@loaders.gl/loader-utils';
2
+ import type { Mesh } from '@loaders.gl/schema';
2
3
  import type { OBJLoaderOptions } from './obj-loader';
3
4
  import { OBJLoader as OBJWorkerLoader } from './obj-loader';
5
+ import type { MTLMaterial } from './lib/parse-mtl';
4
6
  import type { MTLLoaderOptions } from './mtl-loader';
5
7
  export { OBJWorkerLoader };
6
8
  /**
7
9
  * Loader for the OBJ geometry format
8
10
  */
9
- export declare const OBJLoader: {
10
- parse: (arrayBuffer: ArrayBuffer, options?: OBJLoaderOptions | undefined) => Promise<{
11
- /**
12
- * Loader for the MTL material format
13
- */
14
- loaderData: {
15
- header: {};
16
- };
17
- schema: import("@loaders.gl/schema").Schema;
18
- header: {
19
- vertexCount: number;
20
- boundingBox: [[number, number, number], [number, number, number]];
21
- };
22
- mode: number;
23
- attributes: import("@loaders.gl/schema").MeshAttributes;
24
- }>;
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
- };
40
- name: string;
41
- id: string;
42
- module: string;
43
- version: any;
44
- worker: boolean;
45
- extensions: string[];
46
- mimeTypes: string[];
47
- testText: (text: string) => boolean;
48
- options: {
49
- obj: {};
50
- };
51
- };
11
+ export declare const OBJLoader: LoaderWithParser<Mesh, never, OBJLoaderOptions>;
52
12
  /**
53
13
  * Loader for the MTL material format
54
14
  */
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
- };
15
+ export declare const MTLLoader: LoaderWithParser<MTLMaterial[], never, MTLLoaderOptions>;
70
16
  export declare const _typecheckOBJLoader: LoaderWithParser;
71
17
  export declare const _typecheckMTLLoader: LoaderWithParser;
72
18
  //# 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;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"}
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"}
package/dist/index.js CHANGED
@@ -1,16 +1,27 @@
1
- import { parseOBJ } from './lib/parse-obj';
2
- import { parseMTL } from './lib/parse-mtl';
3
- import { OBJLoader as OBJWorkerLoader } from './obj-loader';
4
- import { MTLLoader as MTLWorkerLoader } from './mtl-loader';
5
- export { OBJWorkerLoader };
6
- export const OBJLoader = { ...OBJWorkerLoader,
7
- parse: async (arrayBuffer, options) => parseOBJ(new TextDecoder().decode(arrayBuffer), options),
8
- parseTextSync: (text, options) => parseOBJ(text, options)
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)
9
16
  };
10
- export const MTLLoader = { ...MTLWorkerLoader,
11
- parse: async (arrayBuffer, options) => parseMTL(new TextDecoder().decode(arrayBuffer), options === null || options === void 0 ? void 0 : options.mtl),
12
- parseTextSync: (text, options) => parseMTL(text, options === null || options === void 0 ? void 0 : options.mtl)
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)
13
25
  };
14
- export const _typecheckOBJLoader = OBJLoader;
15
- export const _typecheckMTLLoader = MTLLoader;
16
- //# sourceMappingURL=index.js.map
26
+ exports._typecheckOBJLoader = exports.OBJLoader;
27
+ exports._typecheckMTLLoader = exports.MTLLoader;
@@ -1,3 +1,4 @@
1
- import { Schema } from '@loaders.gl/schema';
2
- export declare function getOBJSchema(attributes: any, metadata?: {}): Schema;
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;
3
4
  //# sourceMappingURL=get-obj-schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-obj-schema.d.ts","sourceRoot":"","sources":["../../src/lib/get-obj-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAmD,MAAM,oBAAoB,CAAC;AAE5F,wBAAgB,YAAY,CAAC,UAAU,KAAA,EAAE,QAAQ,KAAK,UAgBrD"}
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
@@ -1,2 +1 @@
1
-
2
- //# sourceMappingURL=obj-types.js.map
1
+ "use strict";
@@ -1,4 +1,4 @@
1
- export declare type MTLMaterial = {
1
+ export type MTLMaterial = {
2
2
  name: string;
3
3
  ambientColor?: [number, number, number];
4
4
  diffuseColor?: [number, number, number];
@@ -17,7 +17,7 @@ export declare type MTLMaterial = {
17
17
  * @param ignoreZeroRGBs: Ignore values of RGBs (Ka,Kd,Ks) that are all 0's Default: false
18
18
  * @param baseUrl - Url relative to which textures are loaded
19
19
  */
20
- export declare type ParseMTLOptions = {
20
+ export type ParseMTLOptions = {
21
21
  normalizeRGB?: boolean;
22
22
  ignoreZeroRGBs?: boolean;
23
23
  baseUrl?: string;
@@ -1 +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"}
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"}
@@ -1,86 +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;
1
7
  const DELIMITER_PATTERN = /\s+/;
2
- export function parseMTL(text, options) {
3
- const materials = [];
4
- let currentMaterial = {
5
- name: 'placeholder'
6
- };
7
- const lines = text.split('\n');
8
-
9
- for (let line of lines) {
10
- line = line.trim();
11
-
12
- if (line.length === 0 || line.charAt(0) === '#') {
13
- continue;
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
+ }
14
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
+ };
15
152
 
16
- const pos = line.indexOf(' ');
17
- let key = pos >= 0 ? line.substring(0, pos) : line;
18
- key = key.toLowerCase();
19
- let value = pos >= 0 ? line.substring(pos + 1) : '';
20
- value = value.trim();
21
-
22
- switch (key) {
23
- case 'newmtl':
24
- currentMaterial = {
25
- name: value
26
- };
27
- materials.push(currentMaterial);
28
- break;
153
+ const items = value.split(/\s+/);
154
+ let pos;
29
155
 
30
- case 'ka':
31
- currentMaterial.ambientColor = parseColor(value);
32
- break;
156
+ pos = items.indexOf('-bm');
157
+ if (pos >= 0) {
158
+ matParams.bumpScale = parseFloat(items[ pos + 1 ]);
159
+ items.splice(pos, 2);
160
+ }
33
161
 
34
- case 'kd':
35
- currentMaterial.diffuseColor = parseColor(value);
36
- break;
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!
37
166
 
38
- case 'map_kd':
39
- currentMaterial.diffuseTextureUrl = value;
40
- break;
167
+ }
41
168
 
42
- case 'ks':
43
- currentMaterial.specularColor = parseColor(value);
44
- break;
169
+ pos = items.indexOf('-o');
45
170
 
46
- case 'map_ks':
47
- currentMaterial.specularTextureUrl = value;
48
- break;
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
+ }
49
175
 
50
- case 'ke':
51
- currentMaterial.emissiveColor = parseColor(value);
52
- break;
176
+ texParams.url = items.join(' ').trim();
177
+ return texParams;
178
+ }
53
179
 
54
- case 'map_ke':
55
- currentMaterial.emissiveTextureUrl = value;
56
- break;
180
+ *function resolveURL(baseUrl, url) {
181
+ * baseUrl?: string;
182
+ // Absolute URL
183
+ if (/^https?:\/\//i.test(url)) return url;
184
+ return baseUrl + url;
185
+ }
57
186
 
58
- case 'ns':
59
- currentMaterial.shininess = parseFloat(value);
60
- break;
187
+ function setMapForType(mapType, value) {
188
+ if (params[ mapType ]) return; // Keep the first encountered texture
61
189
 
62
- case 'map_ns':
63
- break;
190
+ const texParams = scope.getTextureParams(value, params);
191
+ const map = scope.loadTexture(resolveURL(scope.baseUrl, texParams.url));
64
192
 
65
- case 'ni':
66
- currentMaterial.refraction = parseFloat(value);
67
- break;
193
+ map.repeat.copy(texParams.scale);
194
+ map.offset.copy(texParams.offset);
68
195
 
69
- case 'illum':
70
- currentMaterial.illumination = parseFloat(value);
71
- break;
196
+ map.wrapS = scope.wrap;
197
+ map.wrapT = scope.wrap;
72
198
 
73
- default:
74
- break;
75
- }
199
+ params[ mapType ] = map;
76
200
  }
77
-
78
- return materials;
79
- }
80
-
81
- function parseColor(value, options) {
82
- const rgb = value.split(DELIMITER_PATTERN, 3);
83
- const color = [parseFloat(rgb[0]), parseFloat(rgb[1]), parseFloat(rgb[2])];
84
- return color;
85
- }
86
- //# sourceMappingURL=parse-mtl.js.map
201
+ */