@margoengine/loaders 0.0.0-stage → 0.1.0
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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +1198 -3
- package/dist/3dm.d.ts +161 -0
- package/dist/3dm.js +289 -0
- package/dist/3ds.d.ts +124 -0
- package/dist/3ds.js +392 -0
- package/dist/acclaim.d.ts +90 -0
- package/dist/acclaim.js +312 -0
- package/dist/amf.d.ts +45 -0
- package/dist/amf.js +256 -0
- package/dist/babylon.d.ts +197 -0
- package/dist/babylon.js +701 -0
- package/dist/common.d.ts +7 -0
- package/dist/common.js +6 -0
- package/dist/dae-animation.d.ts +66 -0
- package/dist/dae-animation.js +266 -0
- package/dist/dae-common.d.ts +95 -0
- package/dist/dae-common.js +226 -0
- package/dist/dae-controllers.d.ts +57 -0
- package/dist/dae-controllers.js +164 -0
- package/dist/dae-pose.d.ts +131 -0
- package/dist/dae-pose.js +381 -0
- package/dist/dae-scene.d.ts +203 -0
- package/dist/dae-scene.js +279 -0
- package/dist/dae.d.ts +161 -0
- package/dist/dae.js +633 -0
- package/dist/detect.d.ts +20 -0
- package/dist/detect.js +72 -0
- package/dist/dxf.d.ts +81 -0
- package/dist/dxf.js +774 -0
- package/dist/engine.d.ts +36 -0
- package/dist/engine.js +117 -0
- package/dist/font-opentype.d.ts +14 -0
- package/dist/font-opentype.js +33 -0
- package/dist/font-woff.d.ts +23 -0
- package/dist/font-woff.js +293 -0
- package/dist/font.d.ts +41 -0
- package/dist/font.js +26 -0
- package/dist/gcode.d.ts +55 -0
- package/dist/gcode.js +278 -0
- package/dist/geo-model.d.ts +84 -0
- package/dist/geo-model.js +220 -0
- package/dist/geo-mvt.d.ts +15 -0
- package/dist/geo-mvt.js +302 -0
- package/dist/geo-shp.d.ts +15 -0
- package/dist/geo-shp.js +234 -0
- package/dist/geo-xml.d.ts +6 -0
- package/dist/geo-xml.js +165 -0
- package/dist/geo.d.ts +8 -0
- package/dist/geo.js +59 -0
- package/dist/geometry.d.ts +60 -0
- package/dist/geometry.js +273 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +28 -0
- package/dist/kmz.d.ts +78 -0
- package/dist/kmz.js +173 -0
- package/dist/las.d.ts +92 -0
- package/dist/las.js +110 -0
- package/dist/ldraw.d.ts +118 -0
- package/dist/ldraw.js +474 -0
- package/dist/load.d.ts +72 -0
- package/dist/load.js +205 -0
- package/dist/lottie.d.ts +154 -0
- package/dist/lottie.js +893 -0
- package/dist/lwo.d.ts +81 -0
- package/dist/lwo.js +454 -0
- package/dist/lzf.d.ts +13 -0
- package/dist/lzf.js +56 -0
- package/dist/materialx.d.ts +120 -0
- package/dist/materialx.js +563 -0
- package/dist/md2.d.ts +52 -0
- package/dist/md2.js +112 -0
- package/dist/mmcif.d.ts +14 -0
- package/dist/mmcif.js +246 -0
- package/dist/mmd.d.ts +244 -0
- package/dist/mmd.js +958 -0
- package/dist/mocap.d.ts +71 -0
- package/dist/mocap.js +178 -0
- package/dist/molecule-common.d.ts +4 -0
- package/dist/molecule-common.js +54 -0
- package/dist/mtl.d.ts +120 -0
- package/dist/mtl.js +469 -0
- package/dist/normals.d.ts +7 -0
- package/dist/normals.js +31 -0
- package/dist/nrrd.d.ts +63 -0
- package/dist/nrrd.js +743 -0
- package/dist/nurbs.d.ts +118 -0
- package/dist/nurbs.js +265 -0
- package/dist/obj.d.ts +143 -0
- package/dist/obj.js +456 -0
- package/dist/off.d.ts +10 -0
- package/dist/off.js +155 -0
- package/dist/outline-font.d.ts +87 -0
- package/dist/outline-font.js +110 -0
- package/dist/outline.d.ts +20 -0
- package/dist/outline.js +215 -0
- package/dist/pcd.d.ts +34 -0
- package/dist/pcd.js +258 -0
- package/dist/pdb.d.ts +67 -0
- package/dist/pdb.js +126 -0
- package/dist/ply.d.ts +35 -0
- package/dist/ply.js +392 -0
- package/dist/polygon.d.ts +9 -0
- package/dist/polygon.js +49 -0
- package/dist/prwm.d.ts +24 -0
- package/dist/prwm.js +114 -0
- package/dist/render.d.ts +27 -0
- package/dist/render.js +153 -0
- package/dist/sfnt-cff.d.ts +37 -0
- package/dist/sfnt-cff.js +749 -0
- package/dist/sfnt-layout.d.ts +24 -0
- package/dist/sfnt-layout.js +266 -0
- package/dist/sfnt-reader.d.ts +28 -0
- package/dist/sfnt-reader.js +87 -0
- package/dist/sfnt-variation.d.ts +40 -0
- package/dist/sfnt-variation.js +318 -0
- package/dist/shared/asset-url.js +82 -0
- package/dist/shared/crc32.d.ts +2 -0
- package/dist/shared/crc32.js +47 -0
- package/dist/shared/errors.js +36 -0
- package/dist/shared/inflate.js +284 -0
- package/dist/shared/normals.js +26 -0
- package/dist/shared/scene-scope.js +56 -0
- package/dist/shared/trailing-data.js +42 -0
- package/dist/stl.d.ts +64 -0
- package/dist/stl.js +309 -0
- package/dist/svg.d.ts +90 -0
- package/dist/svg.js +1007 -0
- package/dist/tds.d.ts +2 -0
- package/dist/tds.js +2 -0
- package/dist/textures.d.ts +42 -0
- package/dist/textures.js +53 -0
- package/dist/threemf-lattice.d.ts +139 -0
- package/dist/threemf-lattice.js +514 -0
- package/dist/threemf-materials.d.ts +75 -0
- package/dist/threemf-materials.js +314 -0
- package/dist/threemf-mesh.d.ts +60 -0
- package/dist/threemf-mesh.js +201 -0
- package/dist/threemf.d.ts +101 -0
- package/dist/threemf.js +415 -0
- package/dist/tilt.d.ts +62 -0
- package/dist/tilt.js +186 -0
- package/dist/tmx.d.ts +151 -0
- package/dist/tmx.js +394 -0
- package/dist/ttf.d.ts +78 -0
- package/dist/ttf.js +568 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.js +35 -0
- package/dist/usd.d.ts +2 -0
- package/dist/usd.js +2 -0
- package/dist/usd.worker.d.ts +1 -0
- package/dist/usdz.d.ts +50 -0
- package/dist/usdz.js +646 -0
- package/dist/util.d.ts +75 -0
- package/dist/util.js +241 -0
- package/dist/vdb.d.ts +111 -0
- package/dist/vdb.js +663 -0
- package/dist/vrml.d.ts +53 -0
- package/dist/vrml.js +532 -0
- package/dist/vtk-cells.d.ts +29 -0
- package/dist/vtk-cells.js +211 -0
- package/dist/vtk-legacy.d.ts +57 -0
- package/dist/vtk-legacy.js +439 -0
- package/dist/vtk-reader.d.ts +19 -0
- package/dist/vtk-reader.js +134 -0
- package/dist/vtk-xml.d.ts +96 -0
- package/dist/vtk-xml.js +578 -0
- package/dist/vtk.d.ts +13 -0
- package/dist/vtk.js +234 -0
- package/dist/woff-glyf.d.ts +17 -0
- package/dist/woff-glyf.js +215 -0
- package/dist/worker.d.ts +10 -0
- package/dist/worker.js +93 -0
- package/dist/workers/usd.js +3 -0
- package/dist/xfile.d.ts +99 -0
- package/dist/xfile.js +706 -0
- package/dist/xml.d.ts +107 -0
- package/dist/xml.js +843 -0
- package/dist/xyz.d.ts +16 -0
- package/dist/xyz.js +110 -0
- package/dist/zip.d.ts +38 -0
- package/dist/zip.js +150 -0
- package/package.json +246 -6
package/dist/obj.js
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import { LoaderError } from './types.js';
|
|
2
|
+
import { CornerWelder, floats, limits, normalizeColors, resolvePath, throwIfAborted, toText, uints, } from './util.js';
|
|
3
|
+
const F = 'OBJ';
|
|
4
|
+
const NONE = 0xffffffff;
|
|
5
|
+
/** @internal Defaults of OBJMaterialLimits (loadOBJ reads them too). */
|
|
6
|
+
export const DEFAULT_MAX_MATERIAL_LIBRARIES = 16;
|
|
7
|
+
/** @internal */
|
|
8
|
+
export const DEFAULT_MAX_MATERIAL_BYTES = 64 * 1024 * 1024;
|
|
9
|
+
const words = (text) => (text ? text.split(/\s+/) : []);
|
|
10
|
+
const NUMBER = /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;
|
|
11
|
+
function number(token, format, line) {
|
|
12
|
+
const value = Number(token);
|
|
13
|
+
if (token === undefined || token === '' || Number.isNaN(value))
|
|
14
|
+
throw new LoaderError(format, 'syntax', `expected a number on line ${line}, got "${String(token).slice(0, 32)}"`);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
/** Calls `visit` for every non-empty statement, after removing comments and joining `\` line continuations. */
|
|
18
|
+
function eachStatement(text, visit) {
|
|
19
|
+
let line = 0, start = 0, pending = '', pendingLine = 0;
|
|
20
|
+
while (start <= text.length) {
|
|
21
|
+
let end = text.indexOf('\n', start);
|
|
22
|
+
if (end < 0)
|
|
23
|
+
end = text.length;
|
|
24
|
+
line++;
|
|
25
|
+
let raw = text.slice(start, end);
|
|
26
|
+
start = end + 1;
|
|
27
|
+
const hash = raw.indexOf('#');
|
|
28
|
+
if (hash >= 0)
|
|
29
|
+
raw = raw.slice(0, hash);
|
|
30
|
+
raw = raw.trimEnd();
|
|
31
|
+
if (raw.endsWith('\\')) {
|
|
32
|
+
if (!pending)
|
|
33
|
+
pendingLine = line;
|
|
34
|
+
pending += `${raw.slice(0, -1)} `;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const statement = (pending + raw).trim(), at = pending ? pendingLine : line;
|
|
38
|
+
pending = '';
|
|
39
|
+
if (!statement)
|
|
40
|
+
continue;
|
|
41
|
+
const space = statement.search(/\s/);
|
|
42
|
+
if (space < 0)
|
|
43
|
+
visit(statement, '', at);
|
|
44
|
+
else
|
|
45
|
+
visit(statement.slice(0, space), statement.slice(space + 1).trim(), at);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const MAPS = {
|
|
49
|
+
map_kd: 'map_Kd',
|
|
50
|
+
map_ka: 'map_Ka',
|
|
51
|
+
map_ks: 'map_Ks',
|
|
52
|
+
map_ke: 'map_Ke',
|
|
53
|
+
map_ns: 'map_Ns',
|
|
54
|
+
map_d: 'map_d',
|
|
55
|
+
map_bump: 'bump',
|
|
56
|
+
bump: 'bump',
|
|
57
|
+
disp: 'disp',
|
|
58
|
+
decal: 'decal',
|
|
59
|
+
refl: 'refl',
|
|
60
|
+
};
|
|
61
|
+
/** Parses a map statement's options and file name; null when it uses an option outside the MTL specification. */
|
|
62
|
+
function parseMap(tokens, line, from) {
|
|
63
|
+
const options = {}, last = tokens.length - 1;
|
|
64
|
+
let i = 0;
|
|
65
|
+
const value = () => {
|
|
66
|
+
if (i >= last)
|
|
67
|
+
throw new LoaderError('MTL', 'syntax', `map option ${tokens[i - 1]} on line ${line} has no value`);
|
|
68
|
+
return tokens[i++];
|
|
69
|
+
};
|
|
70
|
+
while (i <= last && tokens[i][0] === '-') {
|
|
71
|
+
const name = tokens[i++].slice(1);
|
|
72
|
+
switch (name) {
|
|
73
|
+
case 'o':
|
|
74
|
+
case 's':
|
|
75
|
+
case 't': {
|
|
76
|
+
const fill = name === 's' ? 1 : 0, vector = [fill, fill, fill];
|
|
77
|
+
for (let k = 0; k < 3 && i < last && NUMBER.test(tokens[i]); k++)
|
|
78
|
+
vector[k] = Number(tokens[i++]);
|
|
79
|
+
options[name] = vector;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case 'mm':
|
|
83
|
+
options.mm = [number(value(), 'MTL', line), number(value(), 'MTL', line)];
|
|
84
|
+
break;
|
|
85
|
+
case 'bm':
|
|
86
|
+
case 'boost':
|
|
87
|
+
case 'texres':
|
|
88
|
+
options[name] = number(value(), 'MTL', line);
|
|
89
|
+
break;
|
|
90
|
+
case 'clamp':
|
|
91
|
+
case 'blendu':
|
|
92
|
+
case 'blendv':
|
|
93
|
+
case 'cc': {
|
|
94
|
+
const flag = value();
|
|
95
|
+
if (flag !== 'on' && flag !== 'off')
|
|
96
|
+
throw new LoaderError('MTL', 'syntax', `map option -${name} on line ${line} must be on or off`);
|
|
97
|
+
options[name] = flag === 'on';
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case 'imfchan':
|
|
101
|
+
case 'type':
|
|
102
|
+
options[name] = value();
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const file = tokens.slice(i).join(' ');
|
|
109
|
+
if (!file)
|
|
110
|
+
throw new LoaderError('MTL', 'syntax', `texture map on line ${line} has no file name`);
|
|
111
|
+
return { file, path: resolvePath(from, file), options };
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Parses a Wavefront MTL library: `newmtl`, `Ka`, `Kd`, `Ks`, `Ke`, `Ns`, `d`, `Tr`, `illum` and every texture map
|
|
115
|
+
* with its options. Statements it does not interpret are kept in each material's `extras`.
|
|
116
|
+
*/
|
|
117
|
+
export function parseMTL(input, options = {}) {
|
|
118
|
+
const from = options.path ?? '', materials = [];
|
|
119
|
+
let material;
|
|
120
|
+
eachStatement(toText(input, 'MTL'), (keyword, rest, line) => {
|
|
121
|
+
const key = keyword.toLowerCase(), tokens = words(rest);
|
|
122
|
+
if (key === 'newmtl') {
|
|
123
|
+
if (!rest)
|
|
124
|
+
throw new LoaderError('MTL', 'syntax', `newmtl on line ${line} has no name`);
|
|
125
|
+
materials.push((material = { name: rest, maps: Object.create(null), extras: [] }));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (!material)
|
|
129
|
+
throw new LoaderError('MTL', 'syntax', `${keyword} on line ${line} comes before the first newmtl`);
|
|
130
|
+
switch (key) {
|
|
131
|
+
case 'ka':
|
|
132
|
+
case 'kd':
|
|
133
|
+
case 'ks':
|
|
134
|
+
case 'ke':
|
|
135
|
+
if (NUMBER.test(tokens[0] ?? '')) {
|
|
136
|
+
const r = number(tokens[0], 'MTL', line);
|
|
137
|
+
material[key === 'ka' ? 'Ka' : key === 'kd' ? 'Kd' : key === 'ks' ? 'Ks' : 'Ke'] = [
|
|
138
|
+
r,
|
|
139
|
+
tokens.length > 1 ? number(tokens[1], 'MTL', line) : r,
|
|
140
|
+
tokens.length > 2 ? number(tokens[2], 'MTL', line) : r,
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
else
|
|
144
|
+
material.extras.push({ keyword, value: rest, line });
|
|
145
|
+
break;
|
|
146
|
+
case 'ns':
|
|
147
|
+
case 'd':
|
|
148
|
+
case 'tr':
|
|
149
|
+
case 'illum':
|
|
150
|
+
// `d -halo 0.5`: the factor is the last value.
|
|
151
|
+
material[key === 'ns' ? 'Ns' : key === 'tr' ? 'Tr' : key === 'd' ? 'd' : 'illum'] = number(tokens[tokens.length - 1], 'MTL', line);
|
|
152
|
+
break;
|
|
153
|
+
default: {
|
|
154
|
+
const name = Object.hasOwn(MAPS, key) ? MAPS[key] : key.startsWith('map_') ? keyword : undefined, map = name ? parseMap(tokens, line, from) : null;
|
|
155
|
+
if (name && map)
|
|
156
|
+
material.maps[name] = map;
|
|
157
|
+
else
|
|
158
|
+
material.extras.push({ keyword, value: rest, line });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return materials;
|
|
163
|
+
}
|
|
164
|
+
function cornerIndex(token, count, what, line) {
|
|
165
|
+
const value = Number(token);
|
|
166
|
+
if (!Number.isSafeInteger(value) || value === 0)
|
|
167
|
+
throw new LoaderError(F, 'syntax', `${what} index "${token.slice(0, 16)}" on line ${line} is not a non-zero integer`);
|
|
168
|
+
const index = value < 0 ? count + value : value - 1;
|
|
169
|
+
if (index < 0 || index >= count)
|
|
170
|
+
throw new LoaderError(F, 'range', `${what} index ${value} on line ${line} is outside the ${count} defined so far`);
|
|
171
|
+
return index;
|
|
172
|
+
}
|
|
173
|
+
function readOBJ(text, limit) {
|
|
174
|
+
const positions = floats(), colors = floats(), uvs = floats(), normals = floats(), cornerV = uints(), cornerT = uints(), cornerN = uints(), faceSizes = uints(), smoothing = uints(), pointV = uints(), lineV = uints(), lineT = uints();
|
|
175
|
+
const groups = [], extras = [], libraries = [];
|
|
176
|
+
let anyColor = false, object, groupNames = [], material, smooth = 0, triangles = 0;
|
|
177
|
+
eachStatement(text, (keyword, rest, line) => {
|
|
178
|
+
switch (keyword) {
|
|
179
|
+
case 'v': {
|
|
180
|
+
const t = words(rest);
|
|
181
|
+
if (t.length !== 3 && t.length !== 4 && t.length !== 6 && t.length !== 7)
|
|
182
|
+
throw new LoaderError(F, 'syntax', `v on line ${line} has ${t.length} values; expected x y z [w] or x y z r g b`);
|
|
183
|
+
if (positions.length / 3 >= limit.maxVertices)
|
|
184
|
+
throw new LoaderError(F, 'limit', `vertex count exceeds the limit of ${limit.maxVertices}`);
|
|
185
|
+
positions.push3(number(t[0], F, line), number(t[1], F, line), number(t[2], F, line));
|
|
186
|
+
if (t.length >= 6) {
|
|
187
|
+
anyColor = true;
|
|
188
|
+
colors.push3(number(t[3], F, line), number(t[4], F, line), number(t[5], F, line));
|
|
189
|
+
}
|
|
190
|
+
else
|
|
191
|
+
colors.push3(1, 1, 1);
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case 'vt': {
|
|
195
|
+
const t = words(rest);
|
|
196
|
+
if (t.length < 1 || t.length > 3)
|
|
197
|
+
throw new LoaderError(F, 'syntax', `vt on line ${line} has ${t.length} values; expected u [v [w]]`);
|
|
198
|
+
uvs.push(number(t[0], F, line));
|
|
199
|
+
uvs.push(t.length > 1 ? number(t[1], F, line) : 0);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
case 'vn': {
|
|
203
|
+
const t = words(rest);
|
|
204
|
+
if (t.length !== 3)
|
|
205
|
+
throw new LoaderError(F, 'syntax', `vn on line ${line} has ${t.length} values; expected 3`);
|
|
206
|
+
normals.push3(number(t[0], F, line), number(t[1], F, line), number(t[2], F, line));
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case 'f': {
|
|
210
|
+
const t = words(rest);
|
|
211
|
+
if (t.length < 3)
|
|
212
|
+
throw new LoaderError(F, 'syntax', `face on line ${line} has ${t.length} corners; a face needs at least 3`);
|
|
213
|
+
if (triangles + t.length - 2 > limit.maxTriangles)
|
|
214
|
+
throw new LoaderError(F, 'limit', `triangle count exceeds the limit of ${limit.maxTriangles}`);
|
|
215
|
+
const last = groups[groups.length - 1];
|
|
216
|
+
if (!last ||
|
|
217
|
+
last.object !== object ||
|
|
218
|
+
last.material !== material ||
|
|
219
|
+
last.groupNames.join(' ') !== groupNames.join(' ')) {
|
|
220
|
+
const group = { start: triangles * 3, count: 0, groupNames };
|
|
221
|
+
const name = groupNames.length ? groupNames.join(' ') : object;
|
|
222
|
+
if (name !== undefined)
|
|
223
|
+
group.name = name;
|
|
224
|
+
if (object !== undefined)
|
|
225
|
+
group.object = object;
|
|
226
|
+
if (material !== undefined)
|
|
227
|
+
group.material = material;
|
|
228
|
+
groups.push(group);
|
|
229
|
+
}
|
|
230
|
+
for (const corner of t) {
|
|
231
|
+
const parts = corner.split('/');
|
|
232
|
+
if (parts.length > 3 || !parts[0])
|
|
233
|
+
throw new LoaderError(F, 'syntax', `face corner "${corner.slice(0, 32)}" on line ${line} is not v, v/vt, v//vn or v/vt/vn`);
|
|
234
|
+
cornerV.push(cornerIndex(parts[0], positions.length / 3, 'v', line));
|
|
235
|
+
cornerT.push(parts[1] ? cornerIndex(parts[1], uvs.length / 2, 'vt', line) : NONE);
|
|
236
|
+
cornerN.push(parts[2] ? cornerIndex(parts[2], normals.length / 3, 'vn', line) : NONE);
|
|
237
|
+
}
|
|
238
|
+
faceSizes.push(t.length);
|
|
239
|
+
smoothing.push(smooth);
|
|
240
|
+
triangles += t.length - 2;
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
case 'p':
|
|
244
|
+
case 'l': {
|
|
245
|
+
// Wavefront OBJ: `p v1 v2 ...` (vertex references) and `l v1/vt1 v2/vt2 ...` (a polyline of two or more).
|
|
246
|
+
const t = words(rest);
|
|
247
|
+
if (keyword === 'l' ? t.length < 2 : !t.length)
|
|
248
|
+
throw new LoaderError(F, 'syntax', `${keyword} on line ${line} has ${t.length} vertices; ${keyword === 'l' ? 'a line needs at least 2' : 'a point needs 1'}`);
|
|
249
|
+
const refs = t.map((corner) => {
|
|
250
|
+
const parts = corner.split('/');
|
|
251
|
+
if (!parts[0] || parts.length > (keyword === 'l' ? 2 : 1))
|
|
252
|
+
throw new LoaderError(F, 'syntax', `${keyword} vertex "${corner.slice(0, 32)}" on line ${line} is not ${keyword === 'l' ? 'v or v/vt' : 'v'}`);
|
|
253
|
+
return [
|
|
254
|
+
cornerIndex(parts[0], positions.length / 3, 'v', line),
|
|
255
|
+
parts[1] ? cornerIndex(parts[1], uvs.length / 2, 'vt', line) : NONE,
|
|
256
|
+
];
|
|
257
|
+
});
|
|
258
|
+
if (pointV.length + lineV.length + refs.length * 2 > limit.maxVertices)
|
|
259
|
+
throw new LoaderError(F, 'limit', `point and line vertices exceed the limit of ${limit.maxVertices}`);
|
|
260
|
+
if (keyword === 'p')
|
|
261
|
+
for (const [v] of refs)
|
|
262
|
+
pointV.push(v);
|
|
263
|
+
else
|
|
264
|
+
for (let k = 1; k < refs.length; k++) {
|
|
265
|
+
lineV.push(refs[k - 1][0]);
|
|
266
|
+
lineT.push(refs[k - 1][1]);
|
|
267
|
+
lineV.push(refs[k][0]);
|
|
268
|
+
lineT.push(refs[k][1]);
|
|
269
|
+
}
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case 'o':
|
|
273
|
+
object = rest || undefined;
|
|
274
|
+
break;
|
|
275
|
+
case 'g':
|
|
276
|
+
groupNames = words(rest);
|
|
277
|
+
break;
|
|
278
|
+
case 'usemtl':
|
|
279
|
+
material = rest || undefined;
|
|
280
|
+
break;
|
|
281
|
+
case 's': {
|
|
282
|
+
const value = rest === 'off' ? 0 : Number(rest);
|
|
283
|
+
if (!Number.isSafeInteger(value) || value < 0 || value >= NONE)
|
|
284
|
+
throw new LoaderError(F, 'syntax', `s on line ${line} must be off or a group number, got "${rest.slice(0, 16)}"`);
|
|
285
|
+
smooth = value;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
case 'mtllib': {
|
|
289
|
+
// Several names separated by spaces, unless that would split one name with spaces (as Blender writes it).
|
|
290
|
+
const names = words(rest);
|
|
291
|
+
for (const name of names.every((n) => /\.mtl$/i.test(n)) ? names : [rest])
|
|
292
|
+
if (name && !libraries.includes(name))
|
|
293
|
+
libraries.push(name);
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
default:
|
|
297
|
+
extras.push({ keyword, value: rest, line });
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
if (anyColor)
|
|
301
|
+
normalizeColors(colors.array.subarray(0, colors.length));
|
|
302
|
+
const result = {
|
|
303
|
+
groups,
|
|
304
|
+
faceSizes: faceSizes.result(),
|
|
305
|
+
smoothingGroups: smoothing.result(),
|
|
306
|
+
materialLibraries: libraries,
|
|
307
|
+
materials: [],
|
|
308
|
+
images: [],
|
|
309
|
+
extras,
|
|
310
|
+
warnings: [],
|
|
311
|
+
};
|
|
312
|
+
if (!triangles)
|
|
313
|
+
// Every `v` is kept, so `p` and `l` index them directly (a line's vt needs corners, which only faces make).
|
|
314
|
+
return {
|
|
315
|
+
...result,
|
|
316
|
+
kind: 'points',
|
|
317
|
+
positions: positions.result(),
|
|
318
|
+
positionIndices: Uint32Array.from({ length: positions.length / 3 }, (_, i) => i),
|
|
319
|
+
pointIndices: pointV.result(),
|
|
320
|
+
lineIndices: lineV.result(),
|
|
321
|
+
...(anyColor ? { colors: colors.result() } : {}),
|
|
322
|
+
};
|
|
323
|
+
const welder = new CornerWelder(positions.length / 3), corners = cornerV.length, vertexOf = new Uint32Array(corners);
|
|
324
|
+
let hasUV = false, hasNormal = false;
|
|
325
|
+
for (let i = 0; i < corners; i++) {
|
|
326
|
+
const t = cornerT.array[i], n = cornerN.array[i];
|
|
327
|
+
if (t !== NONE)
|
|
328
|
+
hasUV = true;
|
|
329
|
+
if (n !== NONE)
|
|
330
|
+
hasNormal = true;
|
|
331
|
+
vertexOf[i] = welder.weld(cornerV.array[i], t, n, NONE);
|
|
332
|
+
}
|
|
333
|
+
// Point and line vertices weld like face corners, without a normal.
|
|
334
|
+
const pointOut = new Uint32Array(pointV.length), lineOut = new Uint32Array(lineV.length);
|
|
335
|
+
for (let i = 0; i < pointOut.length; i++)
|
|
336
|
+
pointOut[i] = welder.weld(pointV.array[i], NONE, NONE, NONE);
|
|
337
|
+
for (let i = 0; i < lineOut.length; i++) {
|
|
338
|
+
if (lineT.array[i] !== NONE)
|
|
339
|
+
hasUV = true;
|
|
340
|
+
lineOut[i] = welder.weld(lineV.array[i], lineT.array[i], NONE, NONE);
|
|
341
|
+
}
|
|
342
|
+
const count = welder.count;
|
|
343
|
+
if (count > limit.maxVertices)
|
|
344
|
+
throw new LoaderError(F, 'limit', `${count} distinct corners exceed the vertex limit of ${limit.maxVertices}`);
|
|
345
|
+
const keys = welder.keys.array, outPositions = new Float32Array(count * 3), outColors = anyColor ? new Float32Array(count * 3) : undefined, outUVs = hasUV ? new Float32Array(count * 2) : undefined, outNormals = hasNormal ? new Float32Array(count * 3) : undefined, positionIndices = new Uint32Array(count);
|
|
346
|
+
for (let v = 0; v < count; v++) {
|
|
347
|
+
const p = keys[v * 4], t = keys[v * 4 + 1], n = keys[v * 4 + 2];
|
|
348
|
+
positionIndices[v] = p;
|
|
349
|
+
for (let a = 0; a < 3; a++) {
|
|
350
|
+
outPositions[v * 3 + a] = positions.array[p * 3 + a];
|
|
351
|
+
if (outColors)
|
|
352
|
+
outColors[v * 3 + a] = colors.array[p * 3 + a];
|
|
353
|
+
if (outNormals && n !== NONE)
|
|
354
|
+
outNormals[v * 3 + a] = normals.array[n * 3 + a];
|
|
355
|
+
}
|
|
356
|
+
if (outUVs && t !== NONE) {
|
|
357
|
+
outUVs[v * 2] = uvs.array[t * 2];
|
|
358
|
+
outUVs[v * 2 + 1] = 1 - uvs.array[t * 2 + 1];
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const indices = new Uint32Array(triangles * 3), sizes = result.faceSizes;
|
|
362
|
+
for (let f = 0, c = 0, o = 0; f < sizes.length; c += sizes[f++])
|
|
363
|
+
for (let k = 2; k < sizes[f]; k++) {
|
|
364
|
+
indices[o++] = vertexOf[c];
|
|
365
|
+
indices[o++] = vertexOf[c + k - 1];
|
|
366
|
+
indices[o++] = vertexOf[c + k];
|
|
367
|
+
}
|
|
368
|
+
for (let g = 0; g < groups.length; g++)
|
|
369
|
+
groups[g].count = (g + 1 < groups.length ? groups[g + 1].start : indices.length) - groups[g].start;
|
|
370
|
+
const loaded = {
|
|
371
|
+
...result,
|
|
372
|
+
kind: 'mesh',
|
|
373
|
+
positions: outPositions,
|
|
374
|
+
indices,
|
|
375
|
+
positionIndices,
|
|
376
|
+
pointIndices: pointOut,
|
|
377
|
+
lineIndices: lineOut,
|
|
378
|
+
};
|
|
379
|
+
if (outNormals)
|
|
380
|
+
loaded.normals = outNormals;
|
|
381
|
+
if (outColors)
|
|
382
|
+
loaded.colors = outColors;
|
|
383
|
+
if (outUVs)
|
|
384
|
+
loaded.uvs = outUVs;
|
|
385
|
+
return loaded;
|
|
386
|
+
}
|
|
387
|
+
/** A whole-number option, or its default; anything else throws a RangeError naming the option. */
|
|
388
|
+
function wholeOption(value, fallback, name) {
|
|
389
|
+
if (value === undefined)
|
|
390
|
+
return fallback;
|
|
391
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
392
|
+
throw new RangeError(`OBJ ${name} is ${value}; pass a non-negative integer`);
|
|
393
|
+
return value;
|
|
394
|
+
}
|
|
395
|
+
async function readMaterials(loaded, resolve, options) {
|
|
396
|
+
const signal = options.signal, maxLibraries = wholeOption(options.maxMaterialLibraries, DEFAULT_MAX_MATERIAL_LIBRARIES, 'maxMaterialLibraries'), maxBytes = wholeOption(options.maxMaterialBytes, DEFAULT_MAX_MATERIAL_BYTES, 'maxMaterialBytes');
|
|
397
|
+
if (loaded.materialLibraries.length > maxLibraries)
|
|
398
|
+
throw new LoaderError(F, 'limit', `${loaded.materialLibraries.length} mtllib files exceed maxMaterialLibraries ${maxLibraries}; raise maxMaterialLibraries to read them`);
|
|
399
|
+
const byName = new Map();
|
|
400
|
+
let bytes = 0;
|
|
401
|
+
for (const library of loaded.materialLibraries) {
|
|
402
|
+
let content;
|
|
403
|
+
try {
|
|
404
|
+
content = await resolve(library);
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
throwIfAborted(signal, F);
|
|
408
|
+
// A refused URL or a spent budget is the resolver saying no, not a missing file: it stops the parse.
|
|
409
|
+
if (error instanceof LoaderError && error.code === 'url')
|
|
410
|
+
throw error;
|
|
411
|
+
if (error instanceof LoaderError && error.code === 'limit')
|
|
412
|
+
throw new LoaderError(F, 'limit', `mtllib "${library}" is over its budget (${error.message}); raise maxMaterialBytes or maxBytes to read it`);
|
|
413
|
+
loaded.warnings.push(`mtllib "${library}" could not be read (${error?.message ?? error})`);
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
throwIfAborted(signal, F);
|
|
417
|
+
bytes += content.length;
|
|
418
|
+
if (bytes > maxBytes)
|
|
419
|
+
throw new LoaderError(F, 'limit', `mtllib files hold more than maxMaterialBytes ${maxBytes} bytes; raise maxMaterialBytes to read them`);
|
|
420
|
+
for (const material of parseMTL(content, { path: library }))
|
|
421
|
+
if (!byName.has(material.name))
|
|
422
|
+
byName.set(material.name, material);
|
|
423
|
+
}
|
|
424
|
+
loaded.materials = [...byName.values()];
|
|
425
|
+
loaded.images = [...new Set(loaded.materials.flatMap((m) => Object.values(m.maps).map((map) => map.path)))];
|
|
426
|
+
const missing = new Set();
|
|
427
|
+
for (const group of loaded.groups) {
|
|
428
|
+
if (group.material === undefined)
|
|
429
|
+
continue;
|
|
430
|
+
const material = byName.get(group.material);
|
|
431
|
+
if (material?.Kd)
|
|
432
|
+
group.color = [...material.Kd, material.d ?? 1];
|
|
433
|
+
else if (!material && !missing.has(group.material)) {
|
|
434
|
+
missing.add(group.material);
|
|
435
|
+
loaded.warnings.push(`usemtl "${group.material}" names no material in the MTL libraries`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Parses a Wavefront OBJ: `v` (with optional `w`, or `r g b` vertex colors after xyz), `vt`, `vn`, faces of any size
|
|
441
|
+
* with `v`, `v/vt`, `v//vn`, `v/vt/vn` and negative (relative) indices, `p` points and `l` polylines (into `pointIndices`
|
|
442
|
+
* and `lineIndices`), `o`, `g`, `s`, `usemtl` and `mtllib`, with
|
|
443
|
+
* `\` line continuations, comments and CRLF. With `resolve` it also reads every MTL library (within
|
|
444
|
+
* `maxMaterialLibraries` and `maxMaterialBytes`) and colors each group with its material's `Kd`. Malformed input
|
|
445
|
+
* throws a `LoaderError` naming the line. A file without faces is a
|
|
446
|
+
* point cloud of its `v` lines.
|
|
447
|
+
*/
|
|
448
|
+
export async function parseOBJ(input, options = {}) {
|
|
449
|
+
throwIfAborted(options.signal, F);
|
|
450
|
+
if (options.resolve !== undefined && typeof options.resolve !== 'function')
|
|
451
|
+
throw new TypeError('OBJ resolve option is not a function; pass (path) => Promise<Uint8Array | string>');
|
|
452
|
+
const loaded = readOBJ(toText(input, F), limits(options, F));
|
|
453
|
+
if (options.resolve && loaded.materialLibraries.length)
|
|
454
|
+
await readMaterials(loaded, options.resolve, options);
|
|
455
|
+
return loaded;
|
|
456
|
+
}
|
package/dist/off.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type LoadedGeometry, type ParseLimits } from './types.js';
|
|
2
|
+
import { type BinaryInput } from './util.js';
|
|
3
|
+
/** Options of parseOFF: the shared size limits (ParseLimits). */
|
|
4
|
+
export interface OFFOptions extends ParseLimits {
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Parses ASCII or big-endian binary OFF with optional ST/C/N vertex attributes.
|
|
8
|
+
* Polygons are fan-triangulated; groups preserve each source face's color or colormap index.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseOFF(input: BinaryInput, options?: OFFOptions): LoadedGeometry;
|
package/dist/off.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { LoaderError } from './types.js';
|
|
2
|
+
import { checkCount, latin1, limits, normalizeColors, parseNumber, splitFields, TextScanner, toBytes, triangulate, uints, } from './util.js';
|
|
3
|
+
const F = 'OFF';
|
|
4
|
+
/**
|
|
5
|
+
* Parses ASCII or big-endian binary OFF with optional ST/C/N vertex attributes.
|
|
6
|
+
* Polygons are fan-triangulated; groups preserve each source face's color or colormap index.
|
|
7
|
+
*/
|
|
8
|
+
export function parseOFF(input, options = {}) {
|
|
9
|
+
const bytes = toBytes(input, F), limit = limits(options, F);
|
|
10
|
+
const scanner = new TextScanner(latin1(bytes), F);
|
|
11
|
+
let lineNumber = 0;
|
|
12
|
+
const next = () => {
|
|
13
|
+
for (;;) {
|
|
14
|
+
const line = scanner.line();
|
|
15
|
+
if (line === null)
|
|
16
|
+
return null;
|
|
17
|
+
lineNumber++;
|
|
18
|
+
const hash = line.indexOf('#'), fields = splitFields(hash >= 0 ? line.slice(0, hash) : line);
|
|
19
|
+
if (fields.length)
|
|
20
|
+
return fields;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
let fields = next();
|
|
24
|
+
const keyword = fields?.[0] ?? '';
|
|
25
|
+
const match = /^(ST)?(C)?(N)?(4)?(n)?OFF$/.exec(keyword);
|
|
26
|
+
if (!fields || !match)
|
|
27
|
+
throw new LoaderError(F, 'header', `missing OFF keyword (found "${keyword.slice(0, 16)}")`);
|
|
28
|
+
if (match[4] || match[5])
|
|
29
|
+
throw new LoaderError(F, 'unsupported', `${keyword} (non-3D vertices) is not supported`);
|
|
30
|
+
const binary = fields[1] === 'BINARY';
|
|
31
|
+
let offset = scanner.pos;
|
|
32
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
33
|
+
const word = (integer = false) => {
|
|
34
|
+
if (offset + 4 > bytes.length)
|
|
35
|
+
throw new LoaderError(F, 'truncated', 'binary OFF ends inside a value');
|
|
36
|
+
const value = integer ? view.getInt32(offset, false) : view.getFloat32(offset, false);
|
|
37
|
+
offset += 4;
|
|
38
|
+
if (!Number.isFinite(value))
|
|
39
|
+
throw new LoaderError(F, 'range', 'binary OFF values must be finite');
|
|
40
|
+
return value;
|
|
41
|
+
};
|
|
42
|
+
const hasUV = !!match[1], hasColor = !!match[2], hasNormal = !!match[3];
|
|
43
|
+
fields = binary ? [word(true), word(true), word(true)].map(String) : fields.length > 1 ? fields.slice(1) : next();
|
|
44
|
+
if (!fields || fields.length < 2)
|
|
45
|
+
throw new LoaderError(F, 'header', 'missing vertex and face counts');
|
|
46
|
+
const vertexCount = checkCount(Number(fields[0]), limit.maxVertices, F, 'vertex');
|
|
47
|
+
const faceCount = checkCount(Number(fields[1]), limit.maxTriangles, F, 'face');
|
|
48
|
+
const minimum = 3 + (hasNormal ? 3 : 0) + (hasColor ? 3 : 0) + (hasUV ? 2 : 0);
|
|
49
|
+
// Budget before allocation: every value takes a digit and a separator, so a short file cannot claim millions.
|
|
50
|
+
const required = binary
|
|
51
|
+
? vertexCount * (minimum + (hasColor ? 1 : 0)) * 4 + faceCount * 8
|
|
52
|
+
: vertexCount * minimum * 2 + faceCount * 2 - 1;
|
|
53
|
+
if (required > bytes.length - (binary ? offset : scanner.pos))
|
|
54
|
+
throw new LoaderError(F, 'truncated', 'file is too short for the declared vertex and face counts');
|
|
55
|
+
const positions = new Float32Array(vertexCount * 3);
|
|
56
|
+
const normals = hasNormal ? new Float32Array(vertexCount * 3) : undefined;
|
|
57
|
+
const colors = hasColor ? new Float32Array(vertexCount * 3) : undefined;
|
|
58
|
+
const uvs = hasUV ? new Float32Array(vertexCount * 2) : undefined;
|
|
59
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
60
|
+
const line = binary ? Array.from({ length: minimum + (hasColor ? 1 : 0) }, () => String(word())) : next();
|
|
61
|
+
if (!line)
|
|
62
|
+
throw new LoaderError(F, 'truncated', `file ends after ${i} of ${vertexCount} vertices`);
|
|
63
|
+
if (line.length < minimum)
|
|
64
|
+
throw new LoaderError(F, 'syntax', `vertex ${i} on line ${lineNumber} has ${line.length} values, expected at least ${minimum}`);
|
|
65
|
+
const where = `on line ${lineNumber}`;
|
|
66
|
+
let k = 0;
|
|
67
|
+
for (let a = 0; a < 3; a++)
|
|
68
|
+
positions[i * 3 + a] = parseNumber(line[k++], F, where);
|
|
69
|
+
if (normals)
|
|
70
|
+
for (let a = 0; a < 3; a++)
|
|
71
|
+
normals[i * 3 + a] = parseNumber(line[k++], F, where);
|
|
72
|
+
if (colors) {
|
|
73
|
+
// Colors take 3 or 4 values (RGB or RGBA); texture coordinates are always the last two.
|
|
74
|
+
const colorValues = hasUV ? line.length - k - 2 : line.length - k;
|
|
75
|
+
if (colorValues < 3)
|
|
76
|
+
throw new LoaderError(F, 'syntax', `vertex ${i} on line ${lineNumber} is missing color values`);
|
|
77
|
+
for (let a = 0; a < 3; a++)
|
|
78
|
+
colors[i * 3 + a] = parseNumber(line[k + a], F, where);
|
|
79
|
+
k += Math.min(colorValues, 4);
|
|
80
|
+
}
|
|
81
|
+
if (uvs) {
|
|
82
|
+
uvs[i * 2] = parseNumber(line[line.length - 2], F, where);
|
|
83
|
+
uvs[i * 2 + 1] = parseNumber(line[line.length - 1], F, where);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (colors)
|
|
87
|
+
normalizeColors(colors);
|
|
88
|
+
const indices = uints(faceCount * 3);
|
|
89
|
+
const groups = [];
|
|
90
|
+
let face = [];
|
|
91
|
+
const at = (corner) => Number(face[corner + 1]);
|
|
92
|
+
for (let i = 0; i < faceCount; i++) {
|
|
93
|
+
let line;
|
|
94
|
+
if (binary) {
|
|
95
|
+
const corners = word(true);
|
|
96
|
+
checkCount(corners, 65536, F, 'face corner');
|
|
97
|
+
if ((corners + 1) * 4 > bytes.length - offset)
|
|
98
|
+
throw new LoaderError(F, 'truncated', 'binary OFF ends inside a face');
|
|
99
|
+
line = [String(corners), ...Array.from({ length: corners }, () => String(word(true)))];
|
|
100
|
+
const components = word(true);
|
|
101
|
+
if (![0, 1, 3, 4].includes(components))
|
|
102
|
+
throw new LoaderError(F, 'syntax', 'OFF face needs 0, 1, 3 or 4 color components');
|
|
103
|
+
for (let c = 0; c < components; c++)
|
|
104
|
+
line.push(String(word()));
|
|
105
|
+
}
|
|
106
|
+
else
|
|
107
|
+
line = next();
|
|
108
|
+
if (!line)
|
|
109
|
+
throw new LoaderError(F, 'truncated', `file ends after ${i} of ${faceCount} faces`);
|
|
110
|
+
const count = Number(line[0]);
|
|
111
|
+
if (!Number.isSafeInteger(count) || count < 0 || line.length < count + 1)
|
|
112
|
+
throw new LoaderError(F, 'syntax', `face ${i} on line ${lineNumber} is malformed`);
|
|
113
|
+
face = line;
|
|
114
|
+
const start = indices.length;
|
|
115
|
+
triangulate(indices, count, at, vertexCount, F, limit.maxTriangles);
|
|
116
|
+
const values = line.slice(count + 1).map((v) => parseNumber(v, F, `in face ${i}`));
|
|
117
|
+
if (![0, 1, 3, 4].includes(values.length) || values.some((v) => !Number.isFinite(v) || v < 0))
|
|
118
|
+
throw new LoaderError(F, 'syntax', `invalid color in face ${i}`);
|
|
119
|
+
const group = { start, count: indices.length - start };
|
|
120
|
+
if (values.length === 1) {
|
|
121
|
+
if (!Number.isSafeInteger(values[0]))
|
|
122
|
+
throw new LoaderError(F, 'range', 'OFF colormap index must be an integer');
|
|
123
|
+
group.properties = { colorIndex: values[0] };
|
|
124
|
+
}
|
|
125
|
+
else if (values.length) {
|
|
126
|
+
const scale = !binary && values.some((v) => v > 1) ? 255 : 1;
|
|
127
|
+
if (values.some((v) => v > scale))
|
|
128
|
+
throw new LoaderError(F, 'range', `face ${i} color is out of range`);
|
|
129
|
+
group.color = [
|
|
130
|
+
values[0] / scale,
|
|
131
|
+
values[1] / scale,
|
|
132
|
+
values[2] / scale,
|
|
133
|
+
values.length === 4 ? values[3] / scale : 1,
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
groups.push(group);
|
|
137
|
+
}
|
|
138
|
+
const result = { kind: indices.length ? 'mesh' : 'points', positions };
|
|
139
|
+
if (normals)
|
|
140
|
+
result.normals = normals;
|
|
141
|
+
if (colors)
|
|
142
|
+
result.colors = colors;
|
|
143
|
+
if (uvs)
|
|
144
|
+
result.uvs = uvs;
|
|
145
|
+
if (indices.length)
|
|
146
|
+
result.indices = indices.result();
|
|
147
|
+
if (groups.length) {
|
|
148
|
+
if (groups.some((g) => g.color))
|
|
149
|
+
for (const group of groups)
|
|
150
|
+
if (!group.color && !group.properties)
|
|
151
|
+
group.color = [0.666, 0.666, 0.666, 0.666];
|
|
152
|
+
result.groups = groups;
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|