@loaders.gl/obj 3.4.13 → 3.4.15
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/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +13 -53
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/get-obj-schema.js +11 -11
- package/dist/es5/lib/get-obj-schema.js.map +1 -1
- package/dist/es5/lib/parse-mtl.js +57 -69
- package/dist/es5/lib/parse-mtl.js.map +1 -1
- package/dist/es5/lib/parse-obj-meshes.js +263 -358
- package/dist/es5/lib/parse-obj-meshes.js.map +1 -1
- package/dist/es5/lib/parse-obj.js +37 -49
- package/dist/es5/lib/parse-obj.js.map +1 -1
- package/dist/es5/mtl-loader.js +4 -6
- package/dist/es5/mtl-loader.js.map +1 -1
- package/dist/es5/obj-loader.js +3 -3
- package/dist/es5/obj-loader.js.map +1 -1
- package/dist/esm/mtl-loader.js +1 -1
- package/dist/esm/obj-loader.js +1 -1
- package/dist/obj-worker.js +2 -2
- package/package.json +4 -4
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.parseOBJMeshes = parseOBJMeshes;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
name = _ref$name === void 0 ? '' : _ref$name,
|
|
21
|
-
mtllib = _ref.mtllib,
|
|
22
|
-
smooth = _ref.smooth,
|
|
23
|
-
groupStart = _ref.groupStart;
|
|
24
|
-
(0, _classCallCheck2.default)(this, MeshMaterial);
|
|
7
|
+
const OBJECT_RE = /^[og]\s*(.+)?/;
|
|
8
|
+
const MATERIAL_RE = /^mtllib /;
|
|
9
|
+
const MATERIAL_USE_RE = /^usemtl /;
|
|
10
|
+
class MeshMaterial {
|
|
11
|
+
constructor(_ref) {
|
|
12
|
+
let {
|
|
13
|
+
index,
|
|
14
|
+
name = '',
|
|
15
|
+
mtllib,
|
|
16
|
+
smooth,
|
|
17
|
+
groupStart
|
|
18
|
+
} = _ref;
|
|
25
19
|
this.index = index;
|
|
26
20
|
this.name = name;
|
|
27
21
|
this.mtllib = mtllib;
|
|
@@ -31,25 +25,20 @@ var MeshMaterial = function () {
|
|
|
31
25
|
this.groupCount = -1;
|
|
32
26
|
this.inherited = false;
|
|
33
27
|
}
|
|
34
|
-
(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}();
|
|
49
|
-
var MeshObject = function () {
|
|
50
|
-
function MeshObject() {
|
|
51
|
-
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
52
|
-
(0, _classCallCheck2.default)(this, MeshObject);
|
|
28
|
+
clone() {
|
|
29
|
+
let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 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
|
+
class MeshObject {
|
|
40
|
+
constructor() {
|
|
41
|
+
let name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
53
42
|
this.name = name;
|
|
54
43
|
this.geometry = {
|
|
55
44
|
vertices: [],
|
|
@@ -61,61 +50,52 @@ var MeshObject = function () {
|
|
|
61
50
|
this.smooth = true;
|
|
62
51
|
this.fromDeclaration = null;
|
|
63
52
|
}
|
|
64
|
-
(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (previous && (previous.inherited || previous.groupCount <= 0)) {
|
|
69
|
-
this.materials.splice(previous.index, 1);
|
|
70
|
-
}
|
|
71
|
-
var material = new MeshMaterial({
|
|
72
|
-
index: this.materials.length,
|
|
73
|
-
name: name,
|
|
74
|
-
mtllib: Array.isArray(libraries) && libraries.length > 0 ? libraries[libraries.length - 1] : '',
|
|
75
|
-
smooth: previous !== undefined ? previous.smooth : this.smooth,
|
|
76
|
-
groupStart: previous !== undefined ? previous.groupEnd : 0
|
|
77
|
-
});
|
|
78
|
-
this.materials.push(material);
|
|
79
|
-
return material;
|
|
53
|
+
startMaterial(name, libraries) {
|
|
54
|
+
const previous = this._finalize(false);
|
|
55
|
+
if (previous && (previous.inherited || previous.groupCount <= 0)) {
|
|
56
|
+
this.materials.splice(previous.index, 1);
|
|
80
57
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
58
|
+
const material = new MeshMaterial({
|
|
59
|
+
index: this.materials.length,
|
|
60
|
+
name,
|
|
61
|
+
mtllib: Array.isArray(libraries) && libraries.length > 0 ? libraries[libraries.length - 1] : '',
|
|
62
|
+
smooth: previous !== undefined ? previous.smooth : this.smooth,
|
|
63
|
+
groupStart: previous !== undefined ? previous.groupEnd : 0
|
|
64
|
+
});
|
|
65
|
+
this.materials.push(material);
|
|
66
|
+
return material;
|
|
67
|
+
}
|
|
68
|
+
currentMaterial() {
|
|
69
|
+
if (this.materials.length > 0) {
|
|
70
|
+
return this.materials[this.materials.length - 1];
|
|
88
71
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
_finalize(end) {
|
|
75
|
+
const lastMultiMaterial = this.currentMaterial();
|
|
76
|
+
if (lastMultiMaterial && lastMultiMaterial.groupEnd === -1) {
|
|
77
|
+
lastMultiMaterial.groupEnd = this.geometry.vertices.length / 3;
|
|
78
|
+
lastMultiMaterial.groupCount = lastMultiMaterial.groupEnd - lastMultiMaterial.groupStart;
|
|
79
|
+
lastMultiMaterial.inherited = false;
|
|
80
|
+
}
|
|
81
|
+
if (end && this.materials.length > 1) {
|
|
82
|
+
for (let mi = this.materials.length - 1; mi >= 0; mi--) {
|
|
83
|
+
if (this.materials[mi].groupCount <= 0) {
|
|
84
|
+
this.materials.splice(mi, 1);
|
|
103
85
|
}
|
|
104
86
|
}
|
|
105
|
-
if (end && this.materials.length === 0) {
|
|
106
|
-
this.materials.push({
|
|
107
|
-
name: '',
|
|
108
|
-
smooth: this.smooth
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
return lastMultiMaterial;
|
|
112
87
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
88
|
+
if (end && this.materials.length === 0) {
|
|
89
|
+
this.materials.push({
|
|
90
|
+
name: '',
|
|
91
|
+
smooth: this.smooth
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return lastMultiMaterial;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
class ParserState {
|
|
98
|
+
constructor() {
|
|
119
99
|
this.objects = [];
|
|
120
100
|
this.object = null;
|
|
121
101
|
this.vertices = [];
|
|
@@ -125,203 +105,144 @@ var ParserState = function () {
|
|
|
125
105
|
this.materialLibraries = [];
|
|
126
106
|
this.startObject('', false);
|
|
127
107
|
}
|
|
128
|
-
(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (this.object && !this.object.fromDeclaration) {
|
|
133
|
-
this.object.name = name;
|
|
134
|
-
this.object.fromDeclaration = fromDeclaration;
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
var previousMaterial = this.object && typeof this.object.currentMaterial === 'function' ? this.object.currentMaterial() : undefined;
|
|
138
|
-
if (this.object && typeof this.object._finalize === 'function') {
|
|
139
|
-
this.object._finalize(true);
|
|
140
|
-
}
|
|
141
|
-
this.object = new MeshObject(name);
|
|
108
|
+
startObject(name) {
|
|
109
|
+
let fromDeclaration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
110
|
+
if (this.object && !this.object.fromDeclaration) {
|
|
111
|
+
this.object.name = name;
|
|
142
112
|
this.object.fromDeclaration = fromDeclaration;
|
|
143
|
-
|
|
144
|
-
var declared = previousMaterial.clone(0);
|
|
145
|
-
declared.inherited = true;
|
|
146
|
-
this.object.materials.push(declared);
|
|
147
|
-
}
|
|
148
|
-
this.objects.push(this.object);
|
|
149
|
-
}
|
|
150
|
-
}, {
|
|
151
|
-
key: "finalize",
|
|
152
|
-
value: function finalize() {
|
|
153
|
-
if (this.object && typeof this.object._finalize === 'function') {
|
|
154
|
-
this.object._finalize(true);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}, {
|
|
158
|
-
key: "parseVertexIndex",
|
|
159
|
-
value: function parseVertexIndex(value, len) {
|
|
160
|
-
var index = parseInt(value);
|
|
161
|
-
return (index >= 0 ? index - 1 : index + len / 3) * 3;
|
|
113
|
+
return;
|
|
162
114
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
var index = parseInt(value);
|
|
167
|
-
return (index >= 0 ? index - 1 : index + len / 3) * 3;
|
|
115
|
+
const previousMaterial = this.object && typeof this.object.currentMaterial === 'function' ? this.object.currentMaterial() : undefined;
|
|
116
|
+
if (this.object && typeof this.object._finalize === 'function') {
|
|
117
|
+
this.object._finalize(true);
|
|
168
118
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
119
|
+
this.object = new MeshObject(name);
|
|
120
|
+
this.object.fromDeclaration = fromDeclaration;
|
|
121
|
+
if (previousMaterial && previousMaterial.name && typeof previousMaterial.clone === 'function') {
|
|
122
|
+
const declared = previousMaterial.clone(0);
|
|
123
|
+
declared.inherited = true;
|
|
124
|
+
this.object.materials.push(declared);
|
|
174
125
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
181
|
-
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
182
|
-
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
183
|
-
}
|
|
184
|
-
}, {
|
|
185
|
-
key: "addVertexPoint",
|
|
186
|
-
value: function addVertexPoint(a) {
|
|
187
|
-
var src = this.vertices;
|
|
188
|
-
var dst = this.object.geometry.vertices;
|
|
189
|
-
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
190
|
-
}
|
|
191
|
-
}, {
|
|
192
|
-
key: "addVertexLine",
|
|
193
|
-
value: function addVertexLine(a) {
|
|
194
|
-
var src = this.vertices;
|
|
195
|
-
var dst = this.object.geometry.vertices;
|
|
196
|
-
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
197
|
-
}
|
|
198
|
-
}, {
|
|
199
|
-
key: "addNormal",
|
|
200
|
-
value: function addNormal(a, b, c) {
|
|
201
|
-
var src = this.normals;
|
|
202
|
-
var dst = this.object.geometry.normals;
|
|
203
|
-
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
204
|
-
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
205
|
-
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
126
|
+
this.objects.push(this.object);
|
|
127
|
+
}
|
|
128
|
+
finalize() {
|
|
129
|
+
if (this.object && typeof this.object._finalize === 'function') {
|
|
130
|
+
this.object._finalize(true);
|
|
206
131
|
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
132
|
+
}
|
|
133
|
+
parseVertexIndex(value, len) {
|
|
134
|
+
const index = parseInt(value);
|
|
135
|
+
return (index >= 0 ? index - 1 : index + len / 3) * 3;
|
|
136
|
+
}
|
|
137
|
+
parseNormalIndex(value, len) {
|
|
138
|
+
const index = parseInt(value);
|
|
139
|
+
return (index >= 0 ? index - 1 : index + len / 3) * 3;
|
|
140
|
+
}
|
|
141
|
+
parseUVIndex(value, len) {
|
|
142
|
+
const index = parseInt(value);
|
|
143
|
+
return (index >= 0 ? index - 1 : index + len / 2) * 2;
|
|
144
|
+
}
|
|
145
|
+
addVertex(a, b, c) {
|
|
146
|
+
const src = this.vertices;
|
|
147
|
+
const dst = this.object.geometry.vertices;
|
|
148
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
149
|
+
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
150
|
+
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
151
|
+
}
|
|
152
|
+
addVertexPoint(a) {
|
|
153
|
+
const src = this.vertices;
|
|
154
|
+
const dst = this.object.geometry.vertices;
|
|
155
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
156
|
+
}
|
|
157
|
+
addVertexLine(a) {
|
|
158
|
+
const src = this.vertices;
|
|
159
|
+
const dst = this.object.geometry.vertices;
|
|
160
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
161
|
+
}
|
|
162
|
+
addNormal(a, b, c) {
|
|
163
|
+
const src = this.normals;
|
|
164
|
+
const dst = this.object.geometry.normals;
|
|
165
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
166
|
+
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
167
|
+
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
168
|
+
}
|
|
169
|
+
addColor(a, b, c) {
|
|
170
|
+
const src = this.colors;
|
|
171
|
+
const dst = this.object.geometry.colors;
|
|
172
|
+
dst.push(src[a + 0], src[a + 1], src[a + 2]);
|
|
173
|
+
dst.push(src[b + 0], src[b + 1], src[b + 2]);
|
|
174
|
+
dst.push(src[c + 0], src[c + 1], src[c + 2]);
|
|
175
|
+
}
|
|
176
|
+
addUV(a, b, c) {
|
|
177
|
+
const src = this.uvs;
|
|
178
|
+
const dst = this.object.geometry.uvs;
|
|
179
|
+
dst.push(src[a + 0], src[a + 1]);
|
|
180
|
+
dst.push(src[b + 0], src[b + 1]);
|
|
181
|
+
dst.push(src[c + 0], src[c + 1]);
|
|
182
|
+
}
|
|
183
|
+
addUVLine(a) {
|
|
184
|
+
const src = this.uvs;
|
|
185
|
+
const dst = this.object.geometry.uvs;
|
|
186
|
+
dst.push(src[a + 0], src[a + 1]);
|
|
187
|
+
}
|
|
188
|
+
addFace(a, b, c, ua, ub, uc, na, nb, nc) {
|
|
189
|
+
const vLen = this.vertices.length;
|
|
190
|
+
let ia = this.parseVertexIndex(a, vLen);
|
|
191
|
+
let ib = this.parseVertexIndex(b, vLen);
|
|
192
|
+
let ic = this.parseVertexIndex(c, vLen);
|
|
193
|
+
this.addVertex(ia, ib, ic);
|
|
194
|
+
if (ua !== undefined && ua !== '') {
|
|
195
|
+
const uvLen = this.uvs.length;
|
|
196
|
+
ia = this.parseUVIndex(ua, uvLen);
|
|
197
|
+
ib = this.parseUVIndex(ub, uvLen);
|
|
198
|
+
ic = this.parseUVIndex(uc, uvLen);
|
|
199
|
+
this.addUV(ia, ib, ic);
|
|
215
200
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
dst.push(src[b + 0], src[b + 1]);
|
|
223
|
-
dst.push(src[c + 0], src[c + 1]);
|
|
201
|
+
if (na !== undefined && na !== '') {
|
|
202
|
+
const nLen = this.normals.length;
|
|
203
|
+
ia = this.parseNormalIndex(na, nLen);
|
|
204
|
+
ib = na === nb ? ia : this.parseNormalIndex(nb, nLen);
|
|
205
|
+
ic = na === nc ? ia : this.parseNormalIndex(nc, nLen);
|
|
206
|
+
this.addNormal(ia, ib, ic);
|
|
224
207
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
value: function addUVLine(a) {
|
|
228
|
-
var src = this.uvs;
|
|
229
|
-
var dst = this.object.geometry.uvs;
|
|
230
|
-
dst.push(src[a + 0], src[a + 1]);
|
|
208
|
+
if (this.colors.length > 0) {
|
|
209
|
+
this.addColor(ia, ib, ic);
|
|
231
210
|
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
var ic = this.parseVertexIndex(c, vLen);
|
|
239
|
-
this.addVertex(ia, ib, ic);
|
|
240
|
-
if (ua !== undefined && ua !== '') {
|
|
241
|
-
var uvLen = this.uvs.length;
|
|
242
|
-
ia = this.parseUVIndex(ua, uvLen);
|
|
243
|
-
ib = this.parseUVIndex(ub, uvLen);
|
|
244
|
-
ic = this.parseUVIndex(uc, uvLen);
|
|
245
|
-
this.addUV(ia, ib, ic);
|
|
246
|
-
}
|
|
247
|
-
if (na !== undefined && na !== '') {
|
|
248
|
-
var nLen = this.normals.length;
|
|
249
|
-
ia = this.parseNormalIndex(na, nLen);
|
|
250
|
-
ib = na === nb ? ia : this.parseNormalIndex(nb, nLen);
|
|
251
|
-
ic = na === nc ? ia : this.parseNormalIndex(nc, nLen);
|
|
252
|
-
this.addNormal(ia, ib, ic);
|
|
253
|
-
}
|
|
254
|
-
if (this.colors.length > 0) {
|
|
255
|
-
this.addColor(ia, ib, ic);
|
|
256
|
-
}
|
|
211
|
+
}
|
|
212
|
+
addPointGeometry(vertices) {
|
|
213
|
+
this.object.geometry.type = 'Points';
|
|
214
|
+
const vLen = this.vertices.length;
|
|
215
|
+
for (const vertex of vertices) {
|
|
216
|
+
this.addVertexPoint(this.parseVertexIndex(vertex, vLen));
|
|
257
217
|
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
try {
|
|
266
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
267
|
-
var vertex = _step.value;
|
|
268
|
-
this.addVertexPoint(this.parseVertexIndex(vertex, vLen));
|
|
269
|
-
}
|
|
270
|
-
} catch (err) {
|
|
271
|
-
_iterator.e(err);
|
|
272
|
-
} finally {
|
|
273
|
-
_iterator.f();
|
|
274
|
-
}
|
|
218
|
+
}
|
|
219
|
+
addLineGeometry(vertices, uvs) {
|
|
220
|
+
this.object.geometry.type = 'Line';
|
|
221
|
+
const vLen = this.vertices.length;
|
|
222
|
+
const uvLen = this.uvs.length;
|
|
223
|
+
for (const vertex of vertices) {
|
|
224
|
+
this.addVertexLine(this.parseVertexIndex(vertex, vLen));
|
|
275
225
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
value: function addLineGeometry(vertices, uvs) {
|
|
279
|
-
this.object.geometry.type = 'Line';
|
|
280
|
-
var vLen = this.vertices.length;
|
|
281
|
-
var uvLen = this.uvs.length;
|
|
282
|
-
var _iterator2 = _createForOfIteratorHelper(vertices),
|
|
283
|
-
_step2;
|
|
284
|
-
try {
|
|
285
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
286
|
-
var vertex = _step2.value;
|
|
287
|
-
this.addVertexLine(this.parseVertexIndex(vertex, vLen));
|
|
288
|
-
}
|
|
289
|
-
} catch (err) {
|
|
290
|
-
_iterator2.e(err);
|
|
291
|
-
} finally {
|
|
292
|
-
_iterator2.f();
|
|
293
|
-
}
|
|
294
|
-
var _iterator3 = _createForOfIteratorHelper(uvs),
|
|
295
|
-
_step3;
|
|
296
|
-
try {
|
|
297
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
298
|
-
var uv = _step3.value;
|
|
299
|
-
this.addUVLine(this.parseUVIndex(uv, uvLen));
|
|
300
|
-
}
|
|
301
|
-
} catch (err) {
|
|
302
|
-
_iterator3.e(err);
|
|
303
|
-
} finally {
|
|
304
|
-
_iterator3.f();
|
|
305
|
-
}
|
|
226
|
+
for (const uv of uvs) {
|
|
227
|
+
this.addUVLine(this.parseUVIndex(uv, uvLen));
|
|
306
228
|
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
}();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
310
231
|
function parseOBJMeshes(text) {
|
|
311
|
-
|
|
232
|
+
const state = new ParserState();
|
|
312
233
|
if (text.indexOf('\r\n') !== -1) {
|
|
313
234
|
text = text.replace(/\r\n/g, '\n');
|
|
314
235
|
}
|
|
315
236
|
if (text.indexOf('\\\n') !== -1) {
|
|
316
237
|
text = text.replace(/\\\n/g, '');
|
|
317
238
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
for (
|
|
239
|
+
const lines = text.split('\n');
|
|
240
|
+
let line = '';
|
|
241
|
+
let lineFirstChar = '';
|
|
242
|
+
let lineLength = 0;
|
|
243
|
+
let result = [];
|
|
244
|
+
const trimLeft = typeof ''.trimLeft === 'function';
|
|
245
|
+
for (let i = 0, l = lines.length; i < l; i++) {
|
|
325
246
|
line = lines[i];
|
|
326
247
|
line = trimLeft ? line.trimLeft() : line.trim();
|
|
327
248
|
lineLength = line.length;
|
|
@@ -329,7 +250,7 @@ function parseOBJMeshes(text) {
|
|
|
329
250
|
lineFirstChar = line.charAt(0);
|
|
330
251
|
if (lineFirstChar === '#') continue;
|
|
331
252
|
if (lineFirstChar === 'v') {
|
|
332
|
-
|
|
253
|
+
const data = line.split(/\s+/);
|
|
333
254
|
switch (data[0]) {
|
|
334
255
|
case 'v':
|
|
335
256
|
state.vertices.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
|
|
@@ -346,43 +267,43 @@ function parseOBJMeshes(text) {
|
|
|
346
267
|
default:
|
|
347
268
|
}
|
|
348
269
|
} else if (lineFirstChar === 'f') {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
for (
|
|
353
|
-
|
|
270
|
+
const lineData = line.substr(1).trim();
|
|
271
|
+
const vertexData = lineData.split(/\s+/);
|
|
272
|
+
const faceVertices = [];
|
|
273
|
+
for (let j = 0, jl = vertexData.length; j < jl; j++) {
|
|
274
|
+
const vertex = vertexData[j];
|
|
354
275
|
if (vertex.length > 0) {
|
|
355
|
-
|
|
276
|
+
const vertexParts = vertex.split('/');
|
|
356
277
|
faceVertices.push(vertexParts);
|
|
357
278
|
}
|
|
358
279
|
}
|
|
359
|
-
|
|
360
|
-
for (
|
|
361
|
-
|
|
362
|
-
|
|
280
|
+
const v1 = faceVertices[0];
|
|
281
|
+
for (let j = 1, jl = faceVertices.length - 1; j < jl; j++) {
|
|
282
|
+
const v2 = faceVertices[j];
|
|
283
|
+
const v3 = faceVertices[j + 1];
|
|
363
284
|
state.addFace(v1[0], v2[0], v3[0], v1[1], v2[1], v3[1], v1[2], v2[2], v3[2]);
|
|
364
285
|
}
|
|
365
286
|
} else if (lineFirstChar === 'l') {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
287
|
+
const lineParts = line.substring(1).trim().split(' ');
|
|
288
|
+
let lineVertices;
|
|
289
|
+
const lineUVs = [];
|
|
369
290
|
if (line.indexOf('/') === -1) {
|
|
370
291
|
lineVertices = lineParts;
|
|
371
292
|
} else {
|
|
372
293
|
lineVertices = [];
|
|
373
|
-
for (
|
|
374
|
-
|
|
294
|
+
for (let li = 0, llen = lineParts.length; li < llen; li++) {
|
|
295
|
+
const parts = lineParts[li].split('/');
|
|
375
296
|
if (parts[0] !== '') lineVertices.push(parts[0]);
|
|
376
297
|
if (parts[1] !== '') lineUVs.push(parts[1]);
|
|
377
298
|
}
|
|
378
299
|
}
|
|
379
300
|
state.addLineGeometry(lineVertices, lineUVs);
|
|
380
301
|
} else if (lineFirstChar === 'p') {
|
|
381
|
-
|
|
382
|
-
|
|
302
|
+
const lineData = line.substr(1).trim();
|
|
303
|
+
const pointData = lineData.split(' ');
|
|
383
304
|
state.addPointGeometry(pointData);
|
|
384
305
|
} else if ((result = OBJECT_RE.exec(line)) !== null) {
|
|
385
|
-
|
|
306
|
+
const name = (' ' + result[0].substr(1).trim()).substr(1);
|
|
386
307
|
state.startObject(name);
|
|
387
308
|
} else if (MATERIAL_USE_RE.test(line)) {
|
|
388
309
|
state.object.startMaterial(line.substring(7).trim(), state.materialLibraries);
|
|
@@ -391,12 +312,12 @@ function parseOBJMeshes(text) {
|
|
|
391
312
|
} else if (lineFirstChar === 's') {
|
|
392
313
|
result = line.split(' ');
|
|
393
314
|
if (result.length > 1) {
|
|
394
|
-
|
|
315
|
+
const value = result[1].trim().toLowerCase();
|
|
395
316
|
state.object.smooth = value !== '0' && value !== 'off';
|
|
396
317
|
} else {
|
|
397
318
|
state.object.smooth = true;
|
|
398
319
|
}
|
|
399
|
-
|
|
320
|
+
const material = state.object.currentMaterial();
|
|
400
321
|
if (material) material.smooth = state.object.smooth;
|
|
401
322
|
} else {
|
|
402
323
|
if (line === '\0') continue;
|
|
@@ -404,83 +325,67 @@ function parseOBJMeshes(text) {
|
|
|
404
325
|
}
|
|
405
326
|
}
|
|
406
327
|
state.finalize();
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
328
|
+
const meshes = [];
|
|
329
|
+
const materials = [];
|
|
330
|
+
for (const object of state.objects) {
|
|
331
|
+
const {
|
|
332
|
+
geometry
|
|
333
|
+
} = object;
|
|
334
|
+
if (geometry.vertices.length === 0) continue;
|
|
335
|
+
const mesh = {
|
|
336
|
+
header: {
|
|
337
|
+
vertexCount: geometry.vertices.length / 3
|
|
338
|
+
},
|
|
339
|
+
attributes: {}
|
|
340
|
+
};
|
|
341
|
+
switch (geometry.type) {
|
|
342
|
+
case 'Points':
|
|
343
|
+
mesh.mode = 0;
|
|
344
|
+
break;
|
|
345
|
+
case 'Line':
|
|
346
|
+
mesh.mode = 1;
|
|
347
|
+
break;
|
|
348
|
+
default:
|
|
349
|
+
mesh.mode = 4;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
mesh.attributes.POSITION = {
|
|
353
|
+
value: new Float32Array(geometry.vertices),
|
|
354
|
+
size: 3
|
|
355
|
+
};
|
|
356
|
+
if (geometry.normals.length > 0) {
|
|
357
|
+
mesh.attributes.NORMAL = {
|
|
358
|
+
value: new Float32Array(geometry.normals),
|
|
359
|
+
size: 3
|
|
421
360
|
};
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
case 'Line':
|
|
427
|
-
mesh.mode = 1;
|
|
428
|
-
break;
|
|
429
|
-
default:
|
|
430
|
-
mesh.mode = 4;
|
|
431
|
-
break;
|
|
432
|
-
}
|
|
433
|
-
mesh.attributes.POSITION = {
|
|
434
|
-
value: new Float32Array(geometry.vertices),
|
|
361
|
+
}
|
|
362
|
+
if (geometry.colors.length > 0) {
|
|
363
|
+
mesh.attributes.COLOR_0 = {
|
|
364
|
+
value: new Float32Array(geometry.colors),
|
|
435
365
|
size: 3
|
|
436
366
|
};
|
|
437
|
-
if (geometry.normals.length > 0) {
|
|
438
|
-
mesh.attributes.NORMAL = {
|
|
439
|
-
value: new Float32Array(geometry.normals),
|
|
440
|
-
size: 3
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
if (geometry.colors.length > 0) {
|
|
444
|
-
mesh.attributes.COLOR_0 = {
|
|
445
|
-
value: new Float32Array(geometry.colors),
|
|
446
|
-
size: 3
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
if (geometry.uvs.length > 0) {
|
|
450
|
-
mesh.attributes.TEXCOORD_0 = {
|
|
451
|
-
value: new Float32Array(geometry.uvs),
|
|
452
|
-
size: 2
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
mesh.materials = [];
|
|
456
|
-
var _iterator5 = _createForOfIteratorHelper(object.materials),
|
|
457
|
-
_step5;
|
|
458
|
-
try {
|
|
459
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
460
|
-
var sourceMaterial = _step5.value;
|
|
461
|
-
var _material = {
|
|
462
|
-
name: sourceMaterial.name,
|
|
463
|
-
flatShading: !sourceMaterial.smooth
|
|
464
|
-
};
|
|
465
|
-
mesh.materials.push(_material);
|
|
466
|
-
materials.push(_material);
|
|
467
|
-
}
|
|
468
|
-
} catch (err) {
|
|
469
|
-
_iterator5.e(err);
|
|
470
|
-
} finally {
|
|
471
|
-
_iterator5.f();
|
|
472
|
-
}
|
|
473
|
-
mesh.name = object.name;
|
|
474
|
-
meshes.push(mesh);
|
|
475
367
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
368
|
+
if (geometry.uvs.length > 0) {
|
|
369
|
+
mesh.attributes.TEXCOORD_0 = {
|
|
370
|
+
value: new Float32Array(geometry.uvs),
|
|
371
|
+
size: 2
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
mesh.materials = [];
|
|
375
|
+
for (const sourceMaterial of object.materials) {
|
|
376
|
+
const _material = {
|
|
377
|
+
name: sourceMaterial.name,
|
|
378
|
+
flatShading: !sourceMaterial.smooth
|
|
379
|
+
};
|
|
380
|
+
mesh.materials.push(_material);
|
|
381
|
+
materials.push(_material);
|
|
382
|
+
}
|
|
383
|
+
mesh.name = object.name;
|
|
384
|
+
meshes.push(mesh);
|
|
480
385
|
}
|
|
481
386
|
return {
|
|
482
|
-
meshes
|
|
483
|
-
materials
|
|
387
|
+
meshes,
|
|
388
|
+
materials
|
|
484
389
|
};
|
|
485
390
|
}
|
|
486
391
|
//# sourceMappingURL=parse-obj-meshes.js.map
|