@loaders.gl/obj 3.1.0-alpha.2 → 3.1.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/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +1089 -5
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +27 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/get-obj-schema.js +45 -0
- package/dist/es5/lib/get-obj-schema.js.map +1 -0
- package/dist/es5/lib/load-obj.js +104 -0
- package/dist/es5/lib/load-obj.js.map +1 -0
- package/dist/es5/lib/obj-types.js +2 -0
- package/dist/{lib → es5/lib}/obj-types.js.map +0 -0
- package/dist/es5/lib/parse-obj.js +466 -0
- package/dist/es5/lib/parse-obj.js.map +1 -0
- package/dist/es5/obj-loader.js +29 -0
- package/dist/{obj-loader.js.map → es5/obj-loader.js.map} +1 -1
- package/dist/es5/workers/obj-worker.js +8 -0
- package/dist/es5/workers/obj-worker.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/get-obj-schema.js +37 -0
- package/dist/esm/lib/get-obj-schema.js.map +1 -0
- package/dist/esm/lib/load-obj.js +92 -0
- package/dist/esm/lib/load-obj.js.map +1 -0
- package/dist/esm/lib/obj-types.js +2 -0
- package/dist/esm/lib/obj-types.js.map +1 -0
- package/dist/esm/lib/parse-obj.js +458 -0
- package/dist/esm/lib/parse-obj.js.map +1 -0
- package/dist/esm/obj-loader.js +21 -0
- package/dist/esm/obj-loader.js.map +1 -0
- package/dist/esm/workers/obj-worker.js +4 -0
- package/dist/esm/workers/obj-worker.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -8
- package/dist/lib/get-obj-schema.d.ts +3 -0
- package/dist/lib/get-obj-schema.d.ts.map +1 -0
- package/dist/lib/get-obj-schema.js +29 -32
- package/dist/lib/load-obj.d.ts +14 -0
- package/dist/lib/load-obj.d.ts.map +1 -0
- package/dist/lib/load-obj.js +67 -86
- package/dist/lib/obj-types.d.ts +1 -0
- package/dist/lib/obj-types.d.ts.map +1 -0
- package/dist/lib/obj-types.js +1 -2
- package/dist/lib/parse-obj.d.ts +6 -0
- package/dist/lib/parse-obj.d.ts.map +1 -0
- package/dist/lib/parse-obj.js +407 -427
- package/dist/obj-loader.d.ts +21 -0
- package/dist/obj-loader.d.ts.map +1 -0
- package/dist/obj-loader.js +24 -18
- package/dist/obj-worker.js +1134 -2
- package/dist/workers/obj-worker.d.ts +2 -0
- package/dist/workers/obj-worker.d.ts.map +1 -0
- package/dist/workers/obj-worker.js +5 -4
- package/package.json +9 -9
- package/src/bundle.ts +2 -3
- package/src/workers/{obj-worker.js → obj-worker.ts} +0 -0
- package/dist/bundle.js.map +0 -1
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/get-obj-schema.js.map +0 -1
- package/dist/lib/load-obj.js.map +0 -1
- package/dist/lib/parse-obj.js.map +0 -1
- package/dist/obj-worker.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":";;AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "OBJWorkerLoader", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return _objLoader.OBJLoader;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
exports._typecheckOBJLoader = exports.OBJLoader = void 0;
|
|
15
|
+
|
|
16
|
+
var _loadObj = _interopRequireDefault(require("./lib/load-obj"));
|
|
17
|
+
|
|
18
|
+
var _objLoader = require("./obj-loader");
|
|
19
|
+
|
|
20
|
+
const OBJLoader = { ..._objLoader.OBJLoader,
|
|
21
|
+
parse: async (arrayBuffer, options) => (0, _loadObj.default)(new TextDecoder().decode(arrayBuffer), options),
|
|
22
|
+
parseTextSync: _loadObj.default
|
|
23
|
+
};
|
|
24
|
+
exports.OBJLoader = OBJLoader;
|
|
25
|
+
const _typecheckOBJLoader = OBJLoader;
|
|
26
|
+
exports._typecheckOBJLoader = _typecheckOBJLoader;
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["OBJLoader","OBJWorkerLoader","parse","arrayBuffer","options","TextDecoder","decode","parseTextSync","loadOBJ","_typecheckOBJLoader"],"mappings":";;;;;;;;;;;;;;;AACA;;AACA;;AASO,MAAMA,SAAS,GAAG,EACvB,GAAGC,oBADoB;AAEvBC,EAAAA,KAAK,EAAE,OAAOC,WAAP,EAAoBC,OAApB,KAAgC,sBAAQ,IAAIC,WAAJ,GAAkBC,MAAlB,CAAyBH,WAAzB,CAAR,EAA+CC,OAA/C,CAFhB;AAGvBG,EAAAA,aAAa,EAAEC;AAHQ,CAAlB;;AAMA,MAAMC,mBAAqC,GAAGT,SAA9C","sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport loadOBJ from './lib/load-obj';\nimport {OBJLoader as OBJWorkerLoader} from './obj-loader';\n\n// OBJLoader\n\nexport {OBJWorkerLoader};\n\n/**\n * Loader for the OBJ geometry format\n */\nexport const OBJLoader = {\n ...OBJWorkerLoader,\n parse: async (arrayBuffer, options) => loadOBJ(new TextDecoder().decode(arrayBuffer), options),\n parseTextSync: loadOBJ\n};\n\nexport const _typecheckOBJLoader: LoaderWithParser = OBJLoader;\n"],"file":"index.js"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getOBJSchema = getOBJSchema;
|
|
7
|
+
|
|
8
|
+
var _schema = require("@loaders.gl/schema");
|
|
9
|
+
|
|
10
|
+
function getOBJSchema(attributes, metadata = {}) {
|
|
11
|
+
let metadataMap;
|
|
12
|
+
|
|
13
|
+
for (const key in metadata) {
|
|
14
|
+
metadataMap = metadataMap || new Map();
|
|
15
|
+
|
|
16
|
+
if (key !== 'value') {
|
|
17
|
+
metadataMap.set(key, JSON.stringify(metadata[key]));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const fields = [];
|
|
22
|
+
|
|
23
|
+
for (const attributeName in attributes) {
|
|
24
|
+
const attribute = attributes[attributeName];
|
|
25
|
+
const field = getArrowFieldFromAttribute(attributeName, attribute);
|
|
26
|
+
fields.push(field);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return new _schema.Schema(fields, metadataMap);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getArrowFieldFromAttribute(attributeName, attribute) {
|
|
33
|
+
const metadataMap = new Map();
|
|
34
|
+
|
|
35
|
+
for (const key in attribute) {
|
|
36
|
+
if (key !== 'value') {
|
|
37
|
+
metadataMap.set(key, JSON.stringify(attribute[key]));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const type = (0, _schema.getArrowTypeFromTypedArray)(attribute.value);
|
|
42
|
+
const isSingleValue = !('size' in attribute) || attribute.size === 1;
|
|
43
|
+
return isSingleValue ? new _schema.Field(attributeName, type, false, metadataMap) : new _schema.Field(attributeName, new _schema.FixedSizeList(attribute.size, new _schema.Field('value', type)), false, metadataMap);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=get-obj-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/get-obj-schema.ts"],"names":["getOBJSchema","attributes","metadata","metadataMap","key","Map","set","JSON","stringify","fields","attributeName","attribute","field","getArrowFieldFromAttribute","push","Schema","type","value","isSingleValue","size","Field","FixedSizeList"],"mappings":";;;;;;;AAAA;;AAEO,SAASA,YAAT,CAAsBC,UAAtB,EAAkCC,QAAQ,GAAG,EAA7C,EAAiD;AACtD,MAAIC,WAAJ;;AACA,OAAK,MAAMC,GAAX,IAAkBF,QAAlB,EAA4B;AAC1BC,IAAAA,WAAW,GAAGA,WAAW,IAAI,IAAIE,GAAJ,EAA7B;;AACA,QAAID,GAAG,KAAK,OAAZ,EAAqB;AACnBD,MAAAA,WAAW,CAACG,GAAZ,CAAgBF,GAAhB,EAAqBG,IAAI,CAACC,SAAL,CAAeN,QAAQ,CAACE,GAAD,CAAvB,CAArB;AACD;AACF;;AAED,QAAMK,MAAe,GAAG,EAAxB;;AACA,OAAK,MAAMC,aAAX,IAA4BT,UAA5B,EAAwC;AACtC,UAAMU,SAAS,GAAGV,UAAU,CAACS,aAAD,CAA5B;AACA,UAAME,KAAK,GAAGC,0BAA0B,CAACH,aAAD,EAAgBC,SAAhB,CAAxC;AACAF,IAAAA,MAAM,CAACK,IAAP,CAAYF,KAAZ;AACD;;AACD,SAAO,IAAIG,cAAJ,CAAWN,MAAX,EAAmBN,WAAnB,CAAP;AACD;;AAED,SAASU,0BAAT,CAAoCH,aAApC,EAAmDC,SAAnD,EAA8D;AAC5D,QAAMR,WAAW,GAAG,IAAIE,GAAJ,EAApB;;AACA,OAAK,MAAMD,GAAX,IAAkBO,SAAlB,EAA6B;AAC3B,QAAIP,GAAG,KAAK,OAAZ,EAAqB;AACnBD,MAAAA,WAAW,CAACG,GAAZ,CAAgBF,GAAhB,EAAqBG,IAAI,CAACC,SAAL,CAAeG,SAAS,CAACP,GAAD,CAAxB,CAArB;AACD;AACF;;AAED,QAAMY,IAAI,GAAG,wCAA2BL,SAAS,CAACM,KAArC,CAAb;AACA,QAAMC,aAAa,GAAG,EAAE,UAAUP,SAAZ,KAA0BA,SAAS,CAACQ,IAAV,KAAmB,CAAnE;AACA,SAAOD,aAAa,GAChB,IAAIE,aAAJ,CAAUV,aAAV,EAAyBM,IAAzB,EAA+B,KAA/B,EAAsCb,WAAtC,CADgB,GAEhB,IAAIiB,aAAJ,CACAV,aADA,EAEA,IAAIW,qBAAJ,CAAkBV,SAAS,CAACQ,IAA5B,EAAkC,IAAIC,aAAJ,CAAU,OAAV,EAAmBJ,IAAnB,CAAlC,CAFA,EAGA,KAHA,EAIAb,WAJA,CAFJ;AAQD","sourcesContent":["import {Schema, Field, FixedSizeList, getArrowTypeFromTypedArray} from '@loaders.gl/schema';\n\nexport function getOBJSchema(attributes, metadata = {}) {\n let metadataMap;\n for (const key in metadata) {\n metadataMap = metadataMap || new Map();\n if (key !== 'value') {\n metadataMap.set(key, JSON.stringify(metadata[key]));\n }\n }\n\n const fields: Field[] = [];\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const field = getArrowFieldFromAttribute(attributeName, attribute);\n fields.push(field);\n }\n return new Schema(fields, metadataMap);\n}\n\nfunction getArrowFieldFromAttribute(attributeName, attribute) {\n const metadataMap = new Map();\n for (const key in attribute) {\n if (key !== 'value') {\n metadataMap.set(key, JSON.stringify(attribute[key]));\n }\n }\n\n const type = getArrowTypeFromTypedArray(attribute.value);\n const isSingleValue = !('size' in attribute) || attribute.size === 1;\n return isSingleValue\n ? new Field(attributeName, type, false, metadataMap)\n : new Field(\n attributeName,\n new FixedSizeList(attribute.size, new Field('value', type)),\n false,\n metadataMap\n );\n}\n"],"file":"get-obj-schema.js"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = loadOBJ;
|
|
9
|
+
|
|
10
|
+
var _schema = require("@loaders.gl/schema");
|
|
11
|
+
|
|
12
|
+
var _parseObj = _interopRequireDefault(require("./parse-obj"));
|
|
13
|
+
|
|
14
|
+
var _getObjSchema = require("./get-obj-schema");
|
|
15
|
+
|
|
16
|
+
function loadOBJ(text, options) {
|
|
17
|
+
const {
|
|
18
|
+
meshes
|
|
19
|
+
} = (0, _parseObj.default)(text);
|
|
20
|
+
const vertexCount = meshes.reduce((s, mesh) => s + mesh.header.vertexCount, 0);
|
|
21
|
+
const attributes = mergeAttributes(meshes, vertexCount);
|
|
22
|
+
const header = {
|
|
23
|
+
vertexCount,
|
|
24
|
+
boundingBox: (0, _schema.getMeshBoundingBox)(attributes)
|
|
25
|
+
};
|
|
26
|
+
const schema = (0, _getObjSchema.getOBJSchema)(attributes, {
|
|
27
|
+
mode: 4,
|
|
28
|
+
boundingBox: header.boundingBox
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
loaderData: {
|
|
32
|
+
header: {}
|
|
33
|
+
},
|
|
34
|
+
schema,
|
|
35
|
+
header,
|
|
36
|
+
mode: 4,
|
|
37
|
+
attributes
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function mergeAttributes(meshes, vertexCount) {
|
|
42
|
+
const positions = new Float32Array(vertexCount * 3);
|
|
43
|
+
let normals;
|
|
44
|
+
let colors;
|
|
45
|
+
let uvs;
|
|
46
|
+
let i = 0;
|
|
47
|
+
|
|
48
|
+
for (const mesh of meshes) {
|
|
49
|
+
const {
|
|
50
|
+
POSITION,
|
|
51
|
+
NORMAL,
|
|
52
|
+
COLOR_0,
|
|
53
|
+
TEXCOORD_0
|
|
54
|
+
} = mesh.attributes;
|
|
55
|
+
positions.set(POSITION.value, i * 3);
|
|
56
|
+
|
|
57
|
+
if (NORMAL) {
|
|
58
|
+
normals = normals || new Float32Array(vertexCount * 3);
|
|
59
|
+
normals.set(NORMAL.value, i * 3);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (COLOR_0) {
|
|
63
|
+
colors = colors || new Float32Array(vertexCount * 3);
|
|
64
|
+
colors.set(COLOR_0.value, i * 3);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (TEXCOORD_0) {
|
|
68
|
+
uvs = uvs || new Float32Array(vertexCount * 2);
|
|
69
|
+
uvs.set(TEXCOORD_0.value, i * 2);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
i += POSITION.value.length / 3;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const attributes = {};
|
|
76
|
+
attributes.POSITION = {
|
|
77
|
+
value: positions,
|
|
78
|
+
size: 3
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
if (normals) {
|
|
82
|
+
attributes.NORMAL = {
|
|
83
|
+
value: normals,
|
|
84
|
+
size: 3
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (colors) {
|
|
89
|
+
attributes.COLOR_0 = {
|
|
90
|
+
value: colors,
|
|
91
|
+
size: 3
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (uvs) {
|
|
96
|
+
attributes.TEXCOORD_0 = {
|
|
97
|
+
value: uvs,
|
|
98
|
+
size: 2
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return attributes;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=load-obj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/load-obj.ts"],"names":["loadOBJ","text","options","meshes","vertexCount","reduce","s","mesh","header","attributes","mergeAttributes","boundingBox","schema","mode","loaderData","positions","Float32Array","normals","colors","uvs","i","POSITION","NORMAL","COLOR_0","TEXCOORD_0","set","value","length","size"],"mappings":"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","sourcesContent":["import type {MeshAttributes} from '@loaders.gl/schema';\nimport {getMeshBoundingBox} from '@loaders.gl/schema';\nimport parseOBJ from './parse-obj';\nimport {getOBJSchema} from './get-obj-schema';\n\nexport default function loadOBJ(text, options) {\n const {meshes} = parseOBJ(text);\n\n // @ts-expect-error\n const vertexCount = meshes.reduce((s, mesh) => s + mesh.header.vertexCount, 0);\n // TODO - render objects separately\n const attributes = mergeAttributes(meshes, vertexCount);\n\n const header = {\n vertexCount,\n // @ts-ignore Need to export Attributes type\n boundingBox: getMeshBoundingBox(attributes)\n };\n\n const schema = getOBJSchema(attributes, {\n mode: 4,\n boundingBox: header.boundingBox\n });\n\n return {\n // Data return by this loader implementation\n loaderData: {\n header: {}\n },\n\n // Normalised data\n schema,\n header,\n mode: 4, // TRIANGLES\n\n attributes\n };\n}\n\n// eslint-disable-next-line max-statements\nfunction mergeAttributes(meshes, vertexCount) {\n const positions = new Float32Array(vertexCount * 3);\n let normals;\n let colors;\n let uvs;\n let i = 0;\n\n for (const mesh of meshes) {\n const {POSITION, NORMAL, COLOR_0, TEXCOORD_0} = mesh.attributes;\n\n positions.set(POSITION.value, i * 3);\n\n if (NORMAL) {\n normals = normals || new Float32Array(vertexCount * 3);\n normals.set(NORMAL.value, i * 3);\n }\n if (COLOR_0) {\n colors = colors || new Float32Array(vertexCount * 3);\n colors.set(COLOR_0.value, i * 3);\n }\n if (TEXCOORD_0) {\n uvs = uvs || new Float32Array(vertexCount * 2);\n uvs.set(TEXCOORD_0.value, i * 2);\n }\n\n i += POSITION.value.length / 3;\n }\n\n const attributes: MeshAttributes = {};\n attributes.POSITION = {value: positions, size: 3};\n\n if (normals) {\n attributes.NORMAL = {value: normals, size: 3};\n }\n if (colors) {\n attributes.COLOR_0 = {value: colors, size: 3};\n }\n if (uvs) {\n attributes.TEXCOORD_0 = {value: uvs, size: 2};\n }\n\n return attributes;\n}\n"],"file":"load-obj.js"}
|
|
File without changes
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
const OBJECT_RE = /^[og]\s*(.+)?/;
|
|
8
|
+
const MATERIAL_RE = /^mtllib /;
|
|
9
|
+
const MATERIAL_USE_RE = /^usemtl /;
|
|
10
|
+
|
|
11
|
+
class MeshMaterial {
|
|
12
|
+
constructor({
|
|
13
|
+
index,
|
|
14
|
+
name = '',
|
|
15
|
+
mtllib,
|
|
16
|
+
smooth,
|
|
17
|
+
groupStart
|
|
18
|
+
}) {
|
|
19
|
+
this.index = index;
|
|
20
|
+
this.name = name;
|
|
21
|
+
this.mtllib = mtllib;
|
|
22
|
+
this.smooth = smooth;
|
|
23
|
+
this.groupStart = groupStart;
|
|
24
|
+
this.groupEnd = -1;
|
|
25
|
+
this.groupCount = -1;
|
|
26
|
+
this.inherited = false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
clone(index = this.index) {
|
|
30
|
+
return new MeshMaterial({
|
|
31
|
+
index,
|
|
32
|
+
name: this.name,
|
|
33
|
+
mtllib: this.mtllib,
|
|
34
|
+
smooth: this.smooth,
|
|
35
|
+
groupStart: 0
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class MeshObject {
|
|
42
|
+
constructor(name = '') {
|
|
43
|
+
this.name = name;
|
|
44
|
+
this.geometry = {
|
|
45
|
+
vertices: [],
|
|
46
|
+
normals: [],
|
|
47
|
+
colors: [],
|
|
48
|
+
uvs: []
|
|
49
|
+
};
|
|
50
|
+
this.materials = [];
|
|
51
|
+
this.smooth = true;
|
|
52
|
+
this.fromDeclaration = null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
startMaterial(name, libraries) {
|
|
56
|
+
const previous = this._finalize(false);
|
|
57
|
+
|
|
58
|
+
if (previous && (previous.inherited || previous.groupCount <= 0)) {
|
|
59
|
+
this.materials.splice(previous.index, 1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const material = new MeshMaterial({
|
|
63
|
+
index: this.materials.length,
|
|
64
|
+
name,
|
|
65
|
+
mtllib: Array.isArray(libraries) && libraries.length > 0 ? libraries[libraries.length - 1] : '',
|
|
66
|
+
smooth: previous !== undefined ? previous.smooth : this.smooth,
|
|
67
|
+
groupStart: previous !== undefined ? previous.groupEnd : 0
|
|
68
|
+
});
|
|
69
|
+
this.materials.push(material);
|
|
70
|
+
return material;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
currentMaterial() {
|
|
74
|
+
if (this.materials.length > 0) {
|
|
75
|
+
return this.materials[this.materials.length - 1];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
_finalize(end) {
|
|
82
|
+
const lastMultiMaterial = this.currentMaterial();
|
|
83
|
+
|
|
84
|
+
if (lastMultiMaterial && lastMultiMaterial.groupEnd === -1) {
|
|
85
|
+
lastMultiMaterial.groupEnd = this.geometry.vertices.length / 3;
|
|
86
|
+
lastMultiMaterial.groupCount = lastMultiMaterial.groupEnd - lastMultiMaterial.groupStart;
|
|
87
|
+
lastMultiMaterial.inherited = false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (end && this.materials.length > 1) {
|
|
91
|
+
for (let mi = this.materials.length - 1; mi >= 0; mi--) {
|
|
92
|
+
if (this.materials[mi].groupCount <= 0) {
|
|
93
|
+
this.materials.splice(mi, 1);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (end && this.materials.length === 0) {
|
|
99
|
+
this.materials.push({
|
|
100
|
+
name: '',
|
|
101
|
+
smooth: this.smooth
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return lastMultiMaterial;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
class ParserState {
|
|
111
|
+
constructor() {
|
|
112
|
+
this.objects = [];
|
|
113
|
+
this.object = null;
|
|
114
|
+
this.vertices = [];
|
|
115
|
+
this.normals = [];
|
|
116
|
+
this.colors = [];
|
|
117
|
+
this.uvs = [];
|
|
118
|
+
this.materialLibraries = [];
|
|
119
|
+
this.startObject('', false);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
startObject(name, fromDeclaration = true) {
|
|
123
|
+
if (this.object && !this.object.fromDeclaration) {
|
|
124
|
+
this.object.name = name;
|
|
125
|
+
this.object.fromDeclaration = fromDeclaration;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const previousMaterial = this.object && typeof this.object.currentMaterial === 'function' ? this.object.currentMaterial() : undefined;
|
|
130
|
+
|
|
131
|
+
if (this.object && typeof this.object._finalize === 'function') {
|
|
132
|
+
this.object._finalize(true);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this.object = new MeshObject(name);
|
|
136
|
+
this.object.fromDeclaration = fromDeclaration;
|
|
137
|
+
|
|
138
|
+
if (previousMaterial && previousMaterial.name && typeof previousMaterial.clone === 'function') {
|
|
139
|
+
const declared = previousMaterial.clone(0);
|
|
140
|
+
declared.inherited = true;
|
|
141
|
+
this.object.materials.push(declared);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
this.objects.push(this.object);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
finalize() {
|
|
148
|
+
if (this.object && typeof this.object._finalize === 'function') {
|
|
149
|
+
this.object._finalize(true);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
parseVertexIndex(value, len) {
|
|
154
|
+
const index = parseInt(value);
|
|
155
|
+
return (index >= 0 ? index - 1 : index + len / 3) * 3;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
parseNormalIndex(value, len) {
|
|
159
|
+
const index = parseInt(value);
|
|
160
|
+
return (index >= 0 ? index - 1 : index + len / 3) * 3;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
parseUVIndex(value, len) {
|
|
164
|
+
const index = parseInt(value);
|
|
165
|
+
return (index >= 0 ? index - 1 : index + len / 2) * 2;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
addVertex(a, b, c) {
|
|
169
|
+
const src = this.vertices;
|
|
170
|
+
const dst = this.object.geometry.vertices;
|
|
171
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
172
|
+
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
173
|
+
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
addVertexPoint(a) {
|
|
177
|
+
const src = this.vertices;
|
|
178
|
+
const dst = this.object.geometry.vertices;
|
|
179
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
addVertexLine(a) {
|
|
183
|
+
const src = this.vertices;
|
|
184
|
+
const dst = this.object.geometry.vertices;
|
|
185
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
addNormal(a, b, c) {
|
|
189
|
+
const src = this.normals;
|
|
190
|
+
const dst = this.object.geometry.normals;
|
|
191
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
192
|
+
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
193
|
+
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
addColor(a, b, c) {
|
|
197
|
+
const src = this.colors;
|
|
198
|
+
const dst = this.object.geometry.colors;
|
|
199
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
200
|
+
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
201
|
+
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
addUV(a, b, c) {
|
|
205
|
+
const src = this.uvs;
|
|
206
|
+
const dst = this.object.geometry.uvs;
|
|
207
|
+
dst.push(src[a + 0], src[a + 1]);
|
|
208
|
+
dst.push(src[b + 0], src[b + 1]);
|
|
209
|
+
dst.push(src[c + 0], src[c + 1]);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
addUVLine(a) {
|
|
213
|
+
const src = this.uvs;
|
|
214
|
+
const dst = this.object.geometry.uvs;
|
|
215
|
+
dst.push(src[a + 0], src[a + 1]);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
addFace(a, b, c, ua, ub, uc, na, nb, nc) {
|
|
219
|
+
const vLen = this.vertices.length;
|
|
220
|
+
let ia = this.parseVertexIndex(a, vLen);
|
|
221
|
+
let ib = this.parseVertexIndex(b, vLen);
|
|
222
|
+
let ic = this.parseVertexIndex(c, vLen);
|
|
223
|
+
this.addVertex(ia, ib, ic);
|
|
224
|
+
|
|
225
|
+
if (ua !== undefined && ua !== '') {
|
|
226
|
+
const uvLen = this.uvs.length;
|
|
227
|
+
ia = this.parseUVIndex(ua, uvLen);
|
|
228
|
+
ib = this.parseUVIndex(ub, uvLen);
|
|
229
|
+
ic = this.parseUVIndex(uc, uvLen);
|
|
230
|
+
this.addUV(ia, ib, ic);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (na !== undefined && na !== '') {
|
|
234
|
+
const nLen = this.normals.length;
|
|
235
|
+
ia = this.parseNormalIndex(na, nLen);
|
|
236
|
+
ib = na === nb ? ia : this.parseNormalIndex(nb, nLen);
|
|
237
|
+
ic = na === nc ? ia : this.parseNormalIndex(nc, nLen);
|
|
238
|
+
this.addNormal(ia, ib, ic);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (this.colors.length > 0) {
|
|
242
|
+
this.addColor(ia, ib, ic);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
addPointGeometry(vertices) {
|
|
247
|
+
this.object.geometry.type = 'Points';
|
|
248
|
+
const vLen = this.vertices.length;
|
|
249
|
+
|
|
250
|
+
for (const vertex of vertices) {
|
|
251
|
+
this.addVertexPoint(this.parseVertexIndex(vertex, vLen));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
addLineGeometry(vertices, uvs) {
|
|
256
|
+
this.object.geometry.type = 'Line';
|
|
257
|
+
const vLen = this.vertices.length;
|
|
258
|
+
const uvLen = this.uvs.length;
|
|
259
|
+
|
|
260
|
+
for (const vertex of vertices) {
|
|
261
|
+
this.addVertexLine(this.parseVertexIndex(vertex, vLen));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
for (const uv of uvs) {
|
|
265
|
+
this.addUVLine(this.parseUVIndex(uv, uvLen));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
var _default = text => {
|
|
272
|
+
const state = new ParserState();
|
|
273
|
+
|
|
274
|
+
if (text.indexOf('\r\n') !== -1) {
|
|
275
|
+
text = text.replace(/\r\n/g, '\n');
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (text.indexOf('\\\n') !== -1) {
|
|
279
|
+
text = text.replace(/\\\n/g, '');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const lines = text.split('\n');
|
|
283
|
+
let line = '';
|
|
284
|
+
let lineFirstChar = '';
|
|
285
|
+
let lineLength = 0;
|
|
286
|
+
let result = [];
|
|
287
|
+
const trimLeft = typeof ''.trimLeft === 'function';
|
|
288
|
+
|
|
289
|
+
for (let i = 0, l = lines.length; i < l; i++) {
|
|
290
|
+
line = lines[i];
|
|
291
|
+
line = trimLeft ? line.trimLeft() : line.trim();
|
|
292
|
+
lineLength = line.length;
|
|
293
|
+
if (lineLength === 0) continue;
|
|
294
|
+
lineFirstChar = line.charAt(0);
|
|
295
|
+
if (lineFirstChar === '#') continue;
|
|
296
|
+
|
|
297
|
+
if (lineFirstChar === 'v') {
|
|
298
|
+
const data = line.split(/\s+/);
|
|
299
|
+
|
|
300
|
+
switch (data[0]) {
|
|
301
|
+
case 'v':
|
|
302
|
+
state.vertices.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
|
|
303
|
+
|
|
304
|
+
if (data.length === 8) {
|
|
305
|
+
state.colors.push(parseFloat(data[4]), parseFloat(data[5]), parseFloat(data[6]));
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
break;
|
|
309
|
+
|
|
310
|
+
case 'vn':
|
|
311
|
+
state.normals.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
|
|
312
|
+
break;
|
|
313
|
+
|
|
314
|
+
case 'vt':
|
|
315
|
+
state.uvs.push(parseFloat(data[1]), parseFloat(data[2]));
|
|
316
|
+
break;
|
|
317
|
+
|
|
318
|
+
default:
|
|
319
|
+
}
|
|
320
|
+
} else if (lineFirstChar === 'f') {
|
|
321
|
+
const lineData = line.substr(1).trim();
|
|
322
|
+
const vertexData = lineData.split(/\s+/);
|
|
323
|
+
const faceVertices = [];
|
|
324
|
+
|
|
325
|
+
for (let j = 0, jl = vertexData.length; j < jl; j++) {
|
|
326
|
+
const vertex = vertexData[j];
|
|
327
|
+
|
|
328
|
+
if (vertex.length > 0) {
|
|
329
|
+
const vertexParts = vertex.split('/');
|
|
330
|
+
faceVertices.push(vertexParts);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const v1 = faceVertices[0];
|
|
335
|
+
|
|
336
|
+
for (let j = 1, jl = faceVertices.length - 1; j < jl; j++) {
|
|
337
|
+
const v2 = faceVertices[j];
|
|
338
|
+
const v3 = faceVertices[j + 1];
|
|
339
|
+
state.addFace(v1[0], v2[0], v3[0], v1[1], v2[1], v3[1], v1[2], v2[2], v3[2]);
|
|
340
|
+
}
|
|
341
|
+
} else if (lineFirstChar === 'l') {
|
|
342
|
+
const lineParts = line.substring(1).trim().split(' ');
|
|
343
|
+
let lineVertices;
|
|
344
|
+
const lineUVs = [];
|
|
345
|
+
|
|
346
|
+
if (line.indexOf('/') === -1) {
|
|
347
|
+
lineVertices = lineParts;
|
|
348
|
+
} else {
|
|
349
|
+
lineVertices = [];
|
|
350
|
+
|
|
351
|
+
for (let li = 0, llen = lineParts.length; li < llen; li++) {
|
|
352
|
+
const parts = lineParts[li].split('/');
|
|
353
|
+
if (parts[0] !== '') lineVertices.push(parts[0]);
|
|
354
|
+
if (parts[1] !== '') lineUVs.push(parts[1]);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
state.addLineGeometry(lineVertices, lineUVs);
|
|
359
|
+
} else if (lineFirstChar === 'p') {
|
|
360
|
+
const lineData = line.substr(1).trim();
|
|
361
|
+
const pointData = lineData.split(' ');
|
|
362
|
+
state.addPointGeometry(pointData);
|
|
363
|
+
} else if ((result = OBJECT_RE.exec(line)) !== null) {
|
|
364
|
+
const name = (' ' + result[0].substr(1).trim()).substr(1);
|
|
365
|
+
state.startObject(name);
|
|
366
|
+
} else if (MATERIAL_USE_RE.test(line)) {
|
|
367
|
+
state.object.startMaterial(line.substring(7).trim(), state.materialLibraries);
|
|
368
|
+
} else if (MATERIAL_RE.test(line)) {
|
|
369
|
+
state.materialLibraries.push(line.substring(7).trim());
|
|
370
|
+
} else if (lineFirstChar === 's') {
|
|
371
|
+
result = line.split(' ');
|
|
372
|
+
|
|
373
|
+
if (result.length > 1) {
|
|
374
|
+
const value = result[1].trim().toLowerCase();
|
|
375
|
+
state.object.smooth = value !== '0' && value !== 'off';
|
|
376
|
+
} else {
|
|
377
|
+
state.object.smooth = true;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const material = state.object.currentMaterial();
|
|
381
|
+
if (material) material.smooth = state.object.smooth;
|
|
382
|
+
} else {
|
|
383
|
+
if (line === '\0') continue;
|
|
384
|
+
throw new Error("Unexpected line: \"".concat(line, "\""));
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
state.finalize();
|
|
389
|
+
const meshes = [];
|
|
390
|
+
const materials = [];
|
|
391
|
+
|
|
392
|
+
for (const object of state.objects) {
|
|
393
|
+
const {
|
|
394
|
+
geometry
|
|
395
|
+
} = object;
|
|
396
|
+
if (geometry.vertices.length === 0) continue;
|
|
397
|
+
const mesh = {
|
|
398
|
+
header: {
|
|
399
|
+
vertexCount: geometry.vertices.length / 3
|
|
400
|
+
},
|
|
401
|
+
attributes: {}
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
switch (geometry.type) {
|
|
405
|
+
case 'Points':
|
|
406
|
+
mesh.mode = 0;
|
|
407
|
+
break;
|
|
408
|
+
|
|
409
|
+
case 'Line':
|
|
410
|
+
mesh.mode = 1;
|
|
411
|
+
break;
|
|
412
|
+
|
|
413
|
+
default:
|
|
414
|
+
mesh.mode = 4;
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
mesh.attributes.POSITION = {
|
|
419
|
+
value: new Float32Array(geometry.vertices),
|
|
420
|
+
size: 3
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
if (geometry.normals.length > 0) {
|
|
424
|
+
mesh.attributes.NORMAL = {
|
|
425
|
+
value: new Float32Array(geometry.normals),
|
|
426
|
+
size: 3
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (geometry.colors.length > 0) {
|
|
431
|
+
mesh.attributes.COLOR_0 = {
|
|
432
|
+
value: new Float32Array(geometry.colors),
|
|
433
|
+
size: 3
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (geometry.uvs.length > 0) {
|
|
438
|
+
mesh.attributes.TEXCOORD_0 = {
|
|
439
|
+
value: new Float32Array(geometry.uvs),
|
|
440
|
+
size: 2
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
mesh.materials = [];
|
|
445
|
+
|
|
446
|
+
for (const sourceMaterial of object.materials) {
|
|
447
|
+
const _material = {
|
|
448
|
+
name: sourceMaterial.name,
|
|
449
|
+
flatShading: !sourceMaterial.smooth
|
|
450
|
+
};
|
|
451
|
+
mesh.materials.push(_material);
|
|
452
|
+
materials.push(_material);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
mesh.name = object.name;
|
|
456
|
+
meshes.push(mesh);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return {
|
|
460
|
+
meshes,
|
|
461
|
+
materials
|
|
462
|
+
};
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
exports.default = _default;
|
|
466
|
+
//# sourceMappingURL=parse-obj.js.map
|