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

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 (47) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/dist.min.js +1196 -0
  4. package/dist/index.d.ts +72 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +10 -3
  7. package/dist/index.js.map +1 -1
  8. package/dist/lib/get-obj-schema.d.ts +3 -0
  9. package/dist/lib/get-obj-schema.d.ts.map +1 -0
  10. package/dist/lib/obj-types.d.ts +1 -0
  11. package/dist/lib/obj-types.d.ts.map +1 -0
  12. package/dist/lib/parse-mtl.d.ts +34 -0
  13. package/dist/lib/parse-mtl.d.ts.map +1 -0
  14. package/dist/lib/parse-mtl.js +86 -0
  15. package/dist/lib/parse-mtl.js.map +1 -0
  16. package/dist/lib/parse-obj-meshes.d.ts +5 -0
  17. package/dist/lib/parse-obj-meshes.d.ts.map +1 -0
  18. package/dist/lib/parse-obj-meshes.js +458 -0
  19. package/dist/lib/parse-obj-meshes.js.map +1 -0
  20. package/dist/lib/parse-obj.d.ts +14 -0
  21. package/dist/lib/parse-obj.d.ts.map +1 -0
  22. package/dist/lib/parse-obj.js +71 -437
  23. package/dist/lib/parse-obj.js.map +1 -1
  24. package/dist/mtl-loader.d.ts +24 -0
  25. package/dist/mtl-loader.d.ts.map +1 -0
  26. package/dist/mtl-loader.js +16 -0
  27. package/dist/mtl-loader.js.map +1 -0
  28. package/dist/obj-loader.d.ts +24 -0
  29. package/dist/obj-loader.d.ts.map +1 -0
  30. package/dist/obj-loader.js +1 -1
  31. package/dist/obj-loader.js.map +1 -1
  32. package/dist/obj-worker.js +100 -10
  33. package/dist/workers/obj-worker.d.ts +2 -0
  34. package/dist/workers/obj-worker.d.ts.map +1 -0
  35. package/dist/workers/obj-worker.js +3 -3
  36. package/dist/workers/obj-worker.js.map +1 -0
  37. package/package.json +7 -7
  38. package/src/index.ts +21 -3
  39. package/src/lib/parse-mtl.ts +246 -0
  40. package/src/lib/parse-obj-meshes.ts +525 -0
  41. package/src/lib/parse-obj.ts +66 -508
  42. package/src/mtl-loader.ts +31 -0
  43. package/src/obj-loader.ts +6 -2
  44. package/src/workers/{obj-worker.js → obj-worker.ts} +0 -0
  45. package/dist/lib/load-obj.js +0 -92
  46. package/dist/lib/load-obj.js.map +0 -1
  47. package/src/lib/load-obj.ts +0 -83
@@ -0,0 +1,24 @@
1
+ import type { Loader, LoaderOptions } from '@loaders.gl/loader-utils';
2
+ export declare type OBJLoaderOptions = LoaderOptions & {
3
+ obj?: {};
4
+ };
5
+ /**
6
+ * Worker loader for the OBJ geometry format
7
+ */
8
+ export declare const OBJLoader: {
9
+ name: string;
10
+ id: string;
11
+ module: string;
12
+ version: any;
13
+ worker: boolean;
14
+ extensions: string[];
15
+ mimeTypes: string[];
16
+ testText: typeof testOBJFile;
17
+ options: {
18
+ obj: {};
19
+ };
20
+ };
21
+ declare function testOBJFile(text: string): boolean;
22
+ export declare const _typecheckOBJLoader: Loader;
23
+ export {};
24
+ //# sourceMappingURL=obj-loader.d.ts.map
@@ -0,0 +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;AAMpE,oBAAY,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,EAAE,CAAC;CACV,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;CAYrB,CAAC;AAEF,iBAAS,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG1C;AAED,eAAO,MAAM,mBAAmB,EAAE,MAAkB,CAAC"}
@@ -1,4 +1,4 @@
1
- const VERSION = typeof "4.0.0-alpha.4" !== 'undefined' ? "4.0.0-alpha.4" : 'latest';
1
+ const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : 'latest';
2
2
  export const OBJLoader = {
3
3
  name: 'OBJ',
4
4
  id: 'obj',
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/obj-loader.ts"],"names":["VERSION","OBJLoader","name","id","module","version","worker","extensions","mimeTypes","testText","testOBJFile","options","obj","text","_typecheckOBJLoader"],"mappings":"AAIA,MAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAKA,OAAO,MAAMC,SAAS,GAAG;AACvBC,EAAAA,IAAI,EAAE,KADiB;AAEvBC,EAAAA,EAAE,EAAE,KAFmB;AAGvBC,EAAAA,MAAM,EAAE,KAHe;AAIvBC,EAAAA,OAAO,EAAEL,OAJc;AAKvBM,EAAAA,MAAM,EAAE,IALe;AAMvBC,EAAAA,UAAU,EAAE,CAAC,KAAD,CANW;AAOvBC,EAAAA,SAAS,EAAE,CAAC,YAAD,CAPY;AAQvBC,EAAAA,QAAQ,EAAEC,WARa;AASvBC,EAAAA,OAAO,EAAE;AACPC,IAAAA,GAAG,EAAE;AADE;AATc,CAAlB;;AAcP,SAASF,WAAT,CAAqBG,IAArB,EAA2B;AAEzB,SAAOA,IAAI,CAAC,CAAD,CAAJ,KAAY,GAAnB;AACD;;AAED,OAAO,MAAMC,mBAA2B,GAAGb,SAApC","sourcesContent":["import type {Loader} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Worker loader for the OBJ geometry format\n */\nexport const OBJLoader = {\n name: 'OBJ',\n id: 'obj',\n module: 'obj',\n version: VERSION,\n worker: true,\n extensions: ['obj'],\n mimeTypes: ['text/plain'],\n testText: testOBJFile,\n options: {\n obj: {}\n }\n};\n\nfunction testOBJFile(text) {\n // TODO - There could be comment line first\n return text[0] === 'v';\n}\n\nexport const _typecheckOBJLoader: Loader = OBJLoader;\n"],"file":"obj-loader.js"}
1
+ {"version":3,"sources":["../src/obj-loader.ts"],"names":["VERSION","OBJLoader","name","id","module","version","worker","extensions","mimeTypes","testText","testOBJFile","options","obj","text","_typecheckOBJLoader"],"mappings":"AAIA,MAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AASA,OAAO,MAAMC,SAAS,GAAG;AACvBC,EAAAA,IAAI,EAAE,KADiB;AAEvBC,EAAAA,EAAE,EAAE,KAFmB;AAGvBC,EAAAA,MAAM,EAAE,KAHe;AAIvBC,EAAAA,OAAO,EAAEL,OAJc;AAKvBM,EAAAA,MAAM,EAAE,IALe;AAMvBC,EAAAA,UAAU,EAAE,CAAC,KAAD,CANW;AAOvBC,EAAAA,SAAS,EAAE,CAAC,YAAD,CAPY;AAQvBC,EAAAA,QAAQ,EAAEC,WARa;AASvBC,EAAAA,OAAO,EAAE;AACPC,IAAAA,GAAG,EAAE;AADE;AATc,CAAlB;;AAcP,SAASF,WAAT,CAAqBG,IAArB,EAA4C;AAE1C,SAAOA,IAAI,CAAC,CAAD,CAAJ,KAAY,GAAnB;AACD;;AAED,OAAO,MAAMC,mBAA2B,GAAGb,SAApC","sourcesContent":["import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type OBJLoaderOptions = LoaderOptions & {\n obj?: {};\n};\n\n/**\n * Worker loader for the OBJ geometry format\n */\nexport const OBJLoader = {\n name: 'OBJ',\n id: 'obj',\n module: 'obj',\n version: VERSION,\n worker: true,\n extensions: ['obj'],\n mimeTypes: ['text/plain'],\n testText: testOBJFile,\n options: {\n obj: {}\n }\n};\n\nfunction testOBJFile(text: string): boolean {\n // TODO - There could be comment line first\n return text[0] === 'v';\n}\n\nexport const _typecheckOBJLoader: Loader = OBJLoader;\n"],"file":"obj-loader.js"}
@@ -648,7 +648,7 @@
648
648
  }
649
649
  }
650
650
 
651
- // src/lib/parse-obj.ts
651
+ // src/lib/parse-obj-meshes.ts
652
652
  var OBJECT_RE = /^[og]\s*(.+)?/;
653
653
  var MATERIAL_RE = /^mtllib /;
654
654
  var MATERIAL_USE_RE = /^usemtl /;
@@ -863,7 +863,7 @@
863
863
  }
864
864
  }
865
865
  };
866
- var parse_obj_default = (text) => {
866
+ function parseOBJMeshes(text) {
867
867
  const state = new ParserState();
868
868
  if (text.indexOf("\r\n") !== -1) {
869
869
  text = text.replace(/\r\n/g, "\n");
@@ -1012,7 +1012,7 @@
1012
1012
  meshes.push(mesh);
1013
1013
  }
1014
1014
  return { meshes, materials };
1015
- };
1015
+ }
1016
1016
 
1017
1017
  // src/lib/get-obj-schema.ts
1018
1018
  function getOBJSchema(attributes, metadata = {}) {
@@ -1043,9 +1043,9 @@
1043
1043
  return isSingleValue ? new Field(attributeName, type, false, metadataMap) : new Field(attributeName, new FixedSizeList(attribute.size, new Field("value", type)), false, metadataMap);
1044
1044
  }
1045
1045
 
1046
- // src/lib/load-obj.ts
1047
- function loadOBJ(text, options) {
1048
- const { meshes } = parse_obj_default(text);
1046
+ // src/lib/parse-obj.ts
1047
+ function parseOBJ(text, options) {
1048
+ const { meshes } = parseOBJMeshes(text);
1049
1049
  const vertexCount = meshes.reduce((s, mesh) => s + mesh.header.vertexCount, 0);
1050
1050
  const attributes = mergeAttributes(meshes, vertexCount);
1051
1051
  const header = {
@@ -1103,8 +1103,77 @@
1103
1103
  return attributes;
1104
1104
  }
1105
1105
 
1106
+ // src/lib/parse-mtl.ts
1107
+ var DELIMITER_PATTERN = /\s+/;
1108
+ function parseMTL(text, options) {
1109
+ const materials = [];
1110
+ let currentMaterial = { name: "placeholder" };
1111
+ const lines = text.split("\n");
1112
+ for (let line of lines) {
1113
+ line = line.trim();
1114
+ if (line.length === 0 || line.charAt(0) === "#") {
1115
+ continue;
1116
+ }
1117
+ const pos = line.indexOf(" ");
1118
+ let key = pos >= 0 ? line.substring(0, pos) : line;
1119
+ key = key.toLowerCase();
1120
+ let value = pos >= 0 ? line.substring(pos + 1) : "";
1121
+ value = value.trim();
1122
+ switch (key) {
1123
+ case "newmtl":
1124
+ currentMaterial = { name: value };
1125
+ materials.push(currentMaterial);
1126
+ break;
1127
+ case "ka":
1128
+ currentMaterial.ambientColor = parseColor(value);
1129
+ break;
1130
+ case "kd":
1131
+ currentMaterial.diffuseColor = parseColor(value);
1132
+ break;
1133
+ case "map_kd":
1134
+ currentMaterial.diffuseTextureUrl = value;
1135
+ break;
1136
+ case "ks":
1137
+ currentMaterial.specularColor = parseColor(value);
1138
+ break;
1139
+ case "map_ks":
1140
+ currentMaterial.specularTextureUrl = value;
1141
+ break;
1142
+ case "ke":
1143
+ currentMaterial.emissiveColor = parseColor(value);
1144
+ break;
1145
+ case "map_ke":
1146
+ currentMaterial.emissiveTextureUrl = value;
1147
+ break;
1148
+ case "ns":
1149
+ currentMaterial.shininess = parseFloat(value);
1150
+ break;
1151
+ case "map_ns":
1152
+ break;
1153
+ case "ni":
1154
+ currentMaterial.refraction = parseFloat(value);
1155
+ break;
1156
+ case "illum":
1157
+ currentMaterial.illumination = parseFloat(value);
1158
+ break;
1159
+ default:
1160
+ break;
1161
+ }
1162
+ }
1163
+ return materials;
1164
+ }
1165
+ function parseColor(value, options) {
1166
+ const rgb = value.split(DELIMITER_PATTERN, 3);
1167
+ const color = [
1168
+ parseFloat(rgb[0]),
1169
+ parseFloat(rgb[1]),
1170
+ parseFloat(rgb[2])
1171
+ ];
1172
+ return color;
1173
+ }
1174
+
1106
1175
  // src/obj-loader.ts
1107
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1176
+ var VERSION = true ? "4.0.0-alpha.5" : "latest";
1108
1177
  var OBJLoader = {
1109
1178
  name: "OBJ",
1110
1179
  id: "obj",
@@ -1122,13 +1191,34 @@
1122
1191
  return text[0] === "v";
1123
1192
  }
1124
1193
 
1194
+ // src/mtl-loader.ts
1195
+ var VERSION2 = true ? "4.0.0-alpha.5" : "latest";
1196
+ var MTLLoader = {
1197
+ name: "MTL",
1198
+ id: "mtl",
1199
+ module: "mtl",
1200
+ version: VERSION2,
1201
+ worker: true,
1202
+ extensions: ["mtl"],
1203
+ mimeTypes: ["text/plain"],
1204
+ testText: (text) => text.includes("newmtl"),
1205
+ options: {
1206
+ mtl: {}
1207
+ }
1208
+ };
1209
+
1125
1210
  // src/index.ts
1126
1211
  var OBJLoader2 = {
1127
1212
  ...OBJLoader,
1128
- parse: async (arrayBuffer, options) => loadOBJ(new TextDecoder().decode(arrayBuffer), options),
1129
- parseTextSync: loadOBJ
1213
+ parse: async (arrayBuffer, options) => parseOBJ(new TextDecoder().decode(arrayBuffer), options),
1214
+ parseTextSync: (text, options) => parseOBJ(text, options)
1215
+ };
1216
+ var MTLLoader2 = {
1217
+ ...MTLLoader,
1218
+ parse: async (arrayBuffer, options) => parseMTL(new TextDecoder().decode(arrayBuffer), options?.mtl),
1219
+ parseTextSync: (text, options) => parseMTL(text, options?.mtl)
1130
1220
  };
1131
1221
 
1132
- // src/workers/obj-worker.js
1222
+ // src/workers/obj-worker.ts
1133
1223
  createLoaderWorker(OBJLoader2);
1134
1224
  })();
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=obj-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"obj-worker.d.ts","sourceRoot":"","sources":["../../src/workers/obj-worker.ts"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
- import {createLoaderWorker} from '@loaders.gl/loader-utils';
2
- import {OBJLoader} from '../index';
3
-
1
+ import { createLoaderWorker } from '@loaders.gl/loader-utils';
2
+ import { OBJLoader } from '../index';
4
3
  createLoaderWorker(OBJLoader);
4
+ //# sourceMappingURL=obj-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/workers/obj-worker.ts"],"names":["createLoaderWorker","OBJLoader"],"mappings":"AAAA,SAAQA,kBAAR,QAAiC,0BAAjC;AACA,SAAQC,SAAR,QAAwB,UAAxB;AAEAD,kBAAkB,CAACC,SAAD,CAAlB","sourcesContent":["import {createLoaderWorker} from '@loaders.gl/loader-utils';\nimport {OBJLoader} from '../index';\n\ncreateLoaderWorker(OBJLoader);\n"],"file":"obj-worker.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/obj",
3
- "version": "4.0.0-alpha.4",
3
+ "version": "4.0.0-alpha.5",
4
4
  "description": "Framework-independent loader for the OBJ format",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -18,7 +18,7 @@
18
18
  "point cloud",
19
19
  "OBJ"
20
20
  ],
21
- "types": "src/index.ts",
21
+ "types": "dist/index.d.ts",
22
22
  "main": "dist/index.js",
23
23
  "module": "dist/index.js",
24
24
  "sideEffects": false,
@@ -29,13 +29,13 @@
29
29
  ],
30
30
  "scripts": {
31
31
  "pre-build": "npm run build-worker && npm run build-bundle",
32
- "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js",
33
- "build-worker": "esbuild src/workers/obj-worker.js --bundle --outfile=dist/obj-worker.js"
32
+ "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js",
33
+ "build-worker": "esbuild src/workers/obj-worker.ts --bundle --outfile=dist/obj-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
34
34
  },
35
35
  "dependencies": {
36
36
  "@babel/runtime": "^7.3.1",
37
- "@loaders.gl/loader-utils": "4.0.0-alpha.4",
38
- "@loaders.gl/schema": "4.0.0-alpha.4"
37
+ "@loaders.gl/loader-utils": "4.0.0-alpha.5",
38
+ "@loaders.gl/schema": "4.0.0-alpha.5"
39
39
  },
40
- "gitHead": "53026061b3c8871f7e96d3a5826125cc6613bddc"
40
+ "gitHead": "7a71a54bdf1ddf985cc3af3db90b82e7fa97d025"
41
41
  }
package/src/index.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import type {LoaderWithParser} from '@loaders.gl/loader-utils';
2
- import loadOBJ from './lib/load-obj';
2
+ import {parseOBJ} from './lib/parse-obj';
3
+ import {parseMTL} from './lib/parse-mtl';
4
+ import type {OBJLoaderOptions} from './obj-loader';
3
5
  import {OBJLoader as OBJWorkerLoader} from './obj-loader';
6
+ import type {MTLLoaderOptions} from './mtl-loader';
7
+ import {MTLLoader as MTLWorkerLoader} from './mtl-loader';
4
8
 
5
9
  // OBJLoader
6
10
 
@@ -11,8 +15,22 @@ export {OBJWorkerLoader};
11
15
  */
12
16
  export const OBJLoader = {
13
17
  ...OBJWorkerLoader,
14
- parse: async (arrayBuffer, options) => loadOBJ(new TextDecoder().decode(arrayBuffer), options),
15
- parseTextSync: loadOBJ
18
+ parse: async (arrayBuffer: ArrayBuffer, options?: OBJLoaderOptions) =>
19
+ parseOBJ(new TextDecoder().decode(arrayBuffer), options),
20
+ parseTextSync: (text: string, options?: OBJLoaderOptions) => parseOBJ(text, options)
21
+ };
22
+
23
+ // MTLLoader
24
+
25
+ /**
26
+ * Loader for the MTL material format
27
+ */
28
+ export const MTLLoader = {
29
+ ...MTLWorkerLoader,
30
+ parse: async (arrayBuffer: ArrayBuffer, options?: MTLLoaderOptions) =>
31
+ parseMTL(new TextDecoder().decode(arrayBuffer), options?.mtl),
32
+ parseTextSync: (text: string, options?: MTLLoaderOptions) => parseMTL(text, options?.mtl)
16
33
  };
17
34
 
18
35
  export const _typecheckOBJLoader: LoaderWithParser = OBJLoader;
36
+ export const _typecheckMTLLoader: LoaderWithParser = MTLLoader;
@@ -0,0 +1,246 @@
1
+ // loaders.gl, MIT license
2
+ // Forked from THREE.js under MIT license
3
+ // https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/MTLLoader.js
4
+
5
+ // import type {DiffuseMaterial} from '@loaders.gl/schema';
6
+
7
+ export type MTLMaterial = {
8
+ name: string;
9
+ ambientColor?: [number, number, number];
10
+ diffuseColor?: [number, number, number];
11
+ specularColor?: [number, number, number];
12
+ emissiveColor?: [number, number, number];
13
+ // specular?: number;
14
+ shininess?: number;
15
+ refraction?: number;
16
+ illumination?: number;
17
+ diffuseTextureUrl?: string;
18
+ emissiveTextureUrl?: string;
19
+ specularTextureUrl?: string;
20
+ };
21
+
22
+ const DELIMITER_PATTERN = /\s+/;
23
+
24
+ /**
25
+ * Set of options on how to construct materials
26
+ * @param normalizeRGB: RGBs need to be normalized to 0-1 from 0-255 (Default: false, assumed to be already normalized)
27
+ * @param ignoreZeroRGBs: Ignore values of RGBs (Ka,Kd,Ks) that are all 0's Default: false
28
+ * @param baseUrl - Url relative to which textures are loaded
29
+ */
30
+ export type ParseMTLOptions = {
31
+ normalizeRGB?: boolean;
32
+ ignoreZeroRGBs?: boolean;
33
+ baseUrl?: string;
34
+ };
35
+
36
+ /**
37
+ * Parses a MTL file.
38
+ * Parses a Wavefront .mtl file specifying materials
39
+ * http://paulbourke.net/dataformats/mtl/
40
+ * https://www.loc.gov/preservation/digital/formats/fdd/fdd000508.shtml
41
+ *
42
+ * @param text - Content of MTL file
43
+ */
44
+ // eslint-disable-next-line complexity
45
+ export function parseMTL(text: string, options?: ParseMTLOptions): MTLMaterial[] {
46
+ // const materialsInfo: Record<string, MTLMaterial> = {};
47
+ const materials: MTLMaterial[] = [];
48
+
49
+ let currentMaterial: MTLMaterial = {name: 'placeholder'};
50
+
51
+ const lines = text.split('\n');
52
+ for (let line of lines) {
53
+ line = line.trim();
54
+
55
+ if (line.length === 0 || line.charAt(0) === '#') {
56
+ // Blank line or comment ignore
57
+ continue; // eslint-disable-line no-continue
58
+ }
59
+
60
+ const pos = line.indexOf(' ');
61
+
62
+ let key = pos >= 0 ? line.substring(0, pos) : line;
63
+ key = key.toLowerCase();
64
+
65
+ let value = pos >= 0 ? line.substring(pos + 1) : '';
66
+ value = value.trim();
67
+
68
+ switch (key) {
69
+ case 'newmtl':
70
+ // New material
71
+ currentMaterial = {name: value};
72
+ // insert into map
73
+ materials.push(currentMaterial);
74
+ break;
75
+
76
+ case 'ka': // Ka
77
+ currentMaterial.ambientColor = parseColor(value);
78
+ break;
79
+
80
+ case 'kd':
81
+ // Kd: Diffuse color (color under white light) using RGB values
82
+ currentMaterial.diffuseColor = parseColor(value);
83
+ break;
84
+ case 'map_kd':
85
+ // Diffuse texture map
86
+ currentMaterial.diffuseTextureUrl = value;
87
+ // setMapForType('map', value);
88
+ break;
89
+
90
+ case 'ks':
91
+ // Specular color (color when light is reflected from shiny surface) using RGB values
92
+ currentMaterial.specularColor = parseColor(value);
93
+ break;
94
+ case 'map_ks':
95
+ // Specular map
96
+ currentMaterial.specularTextureUrl = value;
97
+ // setMapForType('specularMap', value);
98
+ break;
99
+
100
+ case 'ke':
101
+ // Emissive using RGB values
102
+ currentMaterial.emissiveColor = parseColor(value);
103
+ break;
104
+ case 'map_ke':
105
+ // Emissive map
106
+ currentMaterial.emissiveTextureUrl = value;
107
+ // setMapForType('emissiveMap', value);
108
+ break;
109
+
110
+ case 'ns':
111
+ // Ns is material specular exponent (defines the focus of the specular highlight)
112
+ // A high exponent results in a tight, concentrated highlight. Ns values normally range from 0 to 1000.
113
+ currentMaterial.shininess = parseFloat(value);
114
+ break;
115
+ case 'map_ns':
116
+ // Ns is material specular exponent
117
+ // TODO?
118
+ // currentMaterial.shininessMap = parseFloat(value);
119
+ break;
120
+ case 'ni':
121
+ currentMaterial.refraction = parseFloat(value);
122
+ break;
123
+ case 'illum':
124
+ currentMaterial.illumination = parseFloat(value);
125
+ break;
126
+
127
+ default:
128
+ // log unknown message?
129
+ break;
130
+
131
+ /*
132
+ case 'norm':
133
+ setMapForType('normalMap', value);
134
+ break;
135
+
136
+ case 'map_bump':
137
+ case 'bump':
138
+ // Bump texture map
139
+ setMapForType('bumpMap', value);
140
+ break;
141
+
142
+ case 'd':
143
+ n = parseFloat(value);
144
+ if (n < 1) {
145
+ params.opacity = n;
146
+ params.transparent = true;
147
+ }
148
+ break;
149
+
150
+ case 'map_d':
151
+ // Alpha map
152
+ setMapForType('alphaMap', value);
153
+ params.transparent = true;
154
+ break;
155
+
156
+ case 'tr':
157
+ n = parseFloat(value);
158
+ if (this.options && this.options.invertTrProperty) n = 1 - n;
159
+ if (n > 0) {
160
+ params.opacity = 1 - n;
161
+ params.transparent = true;
162
+ }
163
+ */
164
+ }
165
+ }
166
+
167
+ return materials;
168
+ }
169
+
170
+ function parseColor(value: string, options?: ParseMTLOptions): [number, number, number] {
171
+ const rgb = value.split(DELIMITER_PATTERN, 3);
172
+ const color: [number, number, number] = [
173
+ parseFloat(rgb[0]),
174
+ parseFloat(rgb[1]),
175
+ parseFloat(rgb[2])
176
+ ];
177
+ // TODO auto detect big values?
178
+ // if (this.options && this.options.normalizeRGB) {
179
+ // value = [ value[ 0 ] / 255, value[ 1 ] / 255, value[ 2 ] / 255 ];
180
+ // }
181
+
182
+ // if (this.options && this.options.ignoreZeroRGBs) {
183
+ // if (value[ 0 ] === 0 && value[ 1 ] === 0 && value[ 2 ] === 0) {
184
+ // // ignore
185
+ // save = false;
186
+ // }
187
+ // }
188
+ return color;
189
+ }
190
+
191
+ /* TODO parse url options
192
+ function parseTexture(value, matParams) {
193
+ const texParams = {
194
+ scale: new Vector2(1, 1),
195
+ offset: new Vector2(0, 0)
196
+ };
197
+
198
+ const items = value.split(/\s+/);
199
+ let pos;
200
+
201
+ pos = items.indexOf('-bm');
202
+ if (pos >= 0) {
203
+ matParams.bumpScale = parseFloat(items[ pos + 1 ]);
204
+ items.splice(pos, 2);
205
+ }
206
+
207
+ pos = items.indexOf('-s');
208
+ if (pos >= 0) {
209
+ texParams.scale.set(parseFloat(items[ pos + 1 ]), parseFloat(items[ pos + 2 ]));
210
+ items.splice(pos, 4); // we expect 3 parameters here!
211
+
212
+ }
213
+
214
+ pos = items.indexOf('-o');
215
+
216
+ if (pos >= 0) {
217
+ texParams.offset.set(parseFloat(items[ pos + 1 ]), parseFloat(items[ pos + 2 ]));
218
+ items.splice(pos, 4); // we expect 3 parameters here!
219
+ }
220
+
221
+ texParams.url = items.join(' ').trim();
222
+ return texParams;
223
+ }
224
+
225
+ *function resolveURL(baseUrl, url) {
226
+ * baseUrl?: string;
227
+ // Absolute URL
228
+ if (/^https?:\/\//i.test(url)) return url;
229
+ return baseUrl + url;
230
+ }
231
+
232
+ function setMapForType(mapType, value) {
233
+ if (params[ mapType ]) return; // Keep the first encountered texture
234
+
235
+ const texParams = scope.getTextureParams(value, params);
236
+ const map = scope.loadTexture(resolveURL(scope.baseUrl, texParams.url));
237
+
238
+ map.repeat.copy(texParams.scale);
239
+ map.offset.copy(texParams.offset);
240
+
241
+ map.wrapS = scope.wrap;
242
+ map.wrapT = scope.wrap;
243
+
244
+ params[ mapType ] = map;
245
+ }
246
+ */