@margoengine/loaders 0.0.0-stage → 1.0.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 +1665 -2
- 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/crease.d.ts +7 -0
- package/dist/crease.js +67 -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-kinematics.d.ts +65 -0
- package/dist/dae-kinematics.js +461 -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 +166 -0
- package/dist/dae.js +644 -0
- package/dist/detect.d.ts +20 -0
- package/dist/detect.js +72 -0
- package/dist/dxf-hatch.d.ts +8 -0
- package/dist/dxf-hatch.js +346 -0
- package/dist/dxf-leaders.d.ts +59 -0
- package/dist/dxf-leaders.js +258 -0
- package/dist/dxf.d.ts +122 -0
- package/dist/dxf.js +985 -0
- package/dist/engine.d.ts +41 -0
- package/dist/engine.js +120 -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 +92 -0
- package/dist/gcode.js +369 -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 +125 -0
- package/dist/mtl.js +550 -0
- package/dist/normals.d.ts +7 -0
- package/dist/normals.js +31 -0
- package/dist/nrrd.d.ts +70 -0
- package/dist/nrrd.js +785 -0
- package/dist/nurbs.d.ts +118 -0
- package/dist/nurbs.js +265 -0
- package/dist/obj.d.ts +145 -0
- package/dist/obj.js +462 -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 +32 -0
- package/dist/render.js +181 -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 +45 -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-beam-reader.d.ts +19 -0
- package/dist/threemf-beam-reader.js +165 -0
- package/dist/threemf-beams.d.ts +52 -0
- package/dist/threemf-beams.js +268 -0
- package/dist/threemf-boolean-read.d.ts +10 -0
- package/dist/threemf-boolean-read.js +113 -0
- package/dist/threemf-boolean.d.ts +59 -0
- package/dist/threemf-boolean.js +20 -0
- package/dist/threemf-csg.d.ts +14 -0
- package/dist/threemf-csg.js +193 -0
- package/dist/threemf-displacement-read.d.ts +8 -0
- package/dist/threemf-displacement-read.js +213 -0
- package/dist/threemf-displacement.d.ts +71 -0
- package/dist/threemf-displacement.js +18 -0
- package/dist/threemf-evaluate.d.ts +36 -0
- package/dist/threemf-evaluate.js +86 -0
- package/dist/threemf-functions.d.ts +33 -0
- package/dist/threemf-functions.js +359 -0
- package/dist/threemf-lattice-mesh.d.ts +9 -0
- package/dist/threemf-lattice-mesh.js +115 -0
- package/dist/threemf-lattice.d.ts +139 -0
- package/dist/threemf-lattice.js +379 -0
- package/dist/threemf-levelset.d.ts +23 -0
- package/dist/threemf-levelset.js +105 -0
- package/dist/threemf-materials.d.ts +162 -0
- package/dist/threemf-materials.js +497 -0
- package/dist/threemf-mesh.d.ts +75 -0
- package/dist/threemf-mesh.js +422 -0
- package/dist/threemf-secure.d.ts +50 -0
- package/dist/threemf-secure.js +153 -0
- package/dist/threemf-tessellate.d.ts +37 -0
- package/dist/threemf-tessellate.js +277 -0
- package/dist/threemf-volume-colour.d.ts +25 -0
- package/dist/threemf-volume-colour.js +233 -0
- package/dist/threemf-volume-sample.d.ts +8 -0
- package/dist/threemf-volume-sample.js +65 -0
- package/dist/threemf-volumetric-read.d.ts +15 -0
- package/dist/threemf-volumetric-read.js +539 -0
- package/dist/threemf-volumetric.d.ts +177 -0
- package/dist/threemf-volumetric.js +28 -0
- package/dist/threemf.d.ts +170 -0
- package/dist/threemf.js +609 -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 +108 -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 +289 -4
package/dist/nurbs.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { type LoadedGeometry, type ParseLimits } from './types.js';
|
|
2
|
+
/** A NURBS curve as plain data. `knots` may leave out the two end knots, as Rhino files do. */
|
|
3
|
+
export interface NurbsCurve {
|
|
4
|
+
degree: number;
|
|
5
|
+
/** Non-decreasing, `points + degree + 1` long, or `points + degree - 1` without the end knots. */
|
|
6
|
+
knots: ArrayLike<number>;
|
|
7
|
+
/** xyz per control point. */
|
|
8
|
+
points: ArrayLike<number>;
|
|
9
|
+
/** One positive weight per control point. Default all 1, a plain B-spline. */
|
|
10
|
+
weights?: ArrayLike<number>;
|
|
11
|
+
}
|
|
12
|
+
/** A NURBS surface as plain data: control points row by row, v fastest. */
|
|
13
|
+
export interface NurbsSurface {
|
|
14
|
+
degreeU: number;
|
|
15
|
+
degreeV: number;
|
|
16
|
+
knotsU: ArrayLike<number>;
|
|
17
|
+
knotsV: ArrayLike<number>;
|
|
18
|
+
/** Control points along u. */
|
|
19
|
+
countU: number;
|
|
20
|
+
/** Control points along v. */
|
|
21
|
+
countV: number;
|
|
22
|
+
/** xyz per control point; point (i, j) starts at `(i * countV + j) * 3`. */
|
|
23
|
+
points: ArrayLike<number>;
|
|
24
|
+
/** One positive weight per control point. Default all 1. */
|
|
25
|
+
weights?: ArrayLike<number>;
|
|
26
|
+
}
|
|
27
|
+
/** Options of {@link tessellateNurbsCurve}. */
|
|
28
|
+
export interface NurbsCurveOptions {
|
|
29
|
+
/** Most distance between the curve and a chord. Default 0.1% of the control polygon's size. */
|
|
30
|
+
tolerance?: number;
|
|
31
|
+
/** Most points returned. Default 100,000. */
|
|
32
|
+
maxPoints?: number;
|
|
33
|
+
}
|
|
34
|
+
/** Options of {@link tessellateNurbsSurface}. */
|
|
35
|
+
export interface NurbsSurfaceOptions extends ParseLimits {
|
|
36
|
+
/** Quads across each knot span along u. Default 4 times `degreeU`. */
|
|
37
|
+
segmentsU?: number;
|
|
38
|
+
/** Quads across each knot span along v. Default 4 times `degreeV`. */
|
|
39
|
+
segmentsV?: number;
|
|
40
|
+
}
|
|
41
|
+
/** A surface point with its unit normal, zero at a pole where the surface has none. */
|
|
42
|
+
export interface NurbsSurfacePoint {
|
|
43
|
+
position: [number, number, number];
|
|
44
|
+
normal: [number, number, number];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The point of a NURBS curve at parameter `t`.
|
|
48
|
+
*
|
|
49
|
+
* @param curve The degree, knots, control points and weights.
|
|
50
|
+
* @param t A parameter inside the curve's domain.
|
|
51
|
+
* @returns The point, `[x, y, z]`.
|
|
52
|
+
* @throws LoaderError with code `range` for a malformed curve or a parameter outside the domain.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { evaluateNurbsCurve } from '@margoengine/loaders/nurbs';
|
|
57
|
+
*
|
|
58
|
+
* const line = { degree: 1, knots: [0, 0, 1, 1], points: [0, 0, 0, 2, 0, 0] };
|
|
59
|
+
* console.log(evaluateNurbsCurve(line, 0.5));
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function evaluateNurbsCurve(curve: NurbsCurve, t: number): [number, number, number];
|
|
63
|
+
/**
|
|
64
|
+
* Turns a NURBS curve into a polyline that stays within `tolerance` of it: each knot span is split until the curve at
|
|
65
|
+
* quarter points of a piece is close to its chord, so straight runs stay cheap and tight bends get more points.
|
|
66
|
+
*
|
|
67
|
+
* @param curve The degree, knots, control points and weights.
|
|
68
|
+
* @param options The chord tolerance and the point limit.
|
|
69
|
+
* @returns xyz per point in order: `mode: 'strip'` of `@margoengine/lines`.
|
|
70
|
+
* @throws LoaderError with code `range` for a malformed curve or `limit` past `maxPoints`.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { tessellateNurbsCurve } from '@margoengine/loaders/nurbs';
|
|
75
|
+
*
|
|
76
|
+
* const arc = { degree: 2, knots: [0, 0, 0, 1, 1, 1], points: [1, 0, 0, 1, 1, 0, 0, 1, 0], weights: [1, Math.SQRT1_2, 1] };
|
|
77
|
+
* console.log(tessellateNurbsCurve(arc, { tolerance: 0.001 }).length / 3);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function tessellateNurbsCurve(curve: NurbsCurve, options?: NurbsCurveOptions): Float32Array;
|
|
81
|
+
/**
|
|
82
|
+
* The point and unit normal of a NURBS surface at (u, v). The normal is zero where the surface has none, as at a pole.
|
|
83
|
+
*
|
|
84
|
+
* @param surface The degrees, knots, control grid and weights.
|
|
85
|
+
* @param u A parameter inside the u domain.
|
|
86
|
+
* @param v A parameter inside the v domain.
|
|
87
|
+
* @returns The position and normal.
|
|
88
|
+
* @throws LoaderError with code `range` for a malformed surface or a parameter outside the domain.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { evaluateNurbsSurface } from '@margoengine/loaders/nurbs';
|
|
93
|
+
*
|
|
94
|
+
* const patch = { degreeU: 1, degreeV: 1, knotsU: [0, 0, 1, 1], knotsV: [0, 0, 1, 1], countU: 2, countV: 2,
|
|
95
|
+
* points: [0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0] };
|
|
96
|
+
* console.log(evaluateNurbsSurface(patch, 0.5, 0.5));
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function evaluateNurbsSurface(surface: NurbsSurface, u: number, v: number): NurbsSurfacePoint;
|
|
100
|
+
/**
|
|
101
|
+
* Turns a NURBS surface into a triangle grid with exact normals. Grid lines fall on every distinct knot, so creases stay
|
|
102
|
+
* sharp in position. `uvs` run 0 to 1 across the domain. Trim curves are not applied: this is the whole surface.
|
|
103
|
+
*
|
|
104
|
+
* @param surface The degrees, knots, control grid and weights.
|
|
105
|
+
* @param options Quads per knot span and the shared size limits.
|
|
106
|
+
* @returns A mesh with positions, normals, uvs and indices.
|
|
107
|
+
* @throws LoaderError with code `range` for a malformed surface or `limit` past the size limits.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { tessellateNurbsSurface } from '@margoengine/loaders/nurbs';
|
|
112
|
+
*
|
|
113
|
+
* const patch = { degreeU: 1, degreeV: 1, knotsU: [0, 0, 1, 1], knotsV: [0, 0, 1, 1], countU: 2, countV: 2,
|
|
114
|
+
* points: [0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0] };
|
|
115
|
+
* console.log(tessellateNurbsSurface(patch, { segmentsU: 2, segmentsV: 2 }).indices?.length);
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function tessellateNurbsSurface(surface: NurbsSurface, options?: NurbsSurfaceOptions): LoadedGeometry;
|
package/dist/nurbs.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// NURBS held as plain data, the numbers a CAD file hands over: this entry checks them, fills in end knots a file leaves
|
|
2
|
+
// out and tessellates. The maths is the one evaluator of @margoengine/geometry/nurbs.
|
|
3
|
+
import { NurbsCurve as CurveEvaluator, NurbsSurface as SurfaceEvaluator } from '@margoengine/geometry/nurbs';
|
|
4
|
+
import { computeVertexNormals } from './normals.js';
|
|
5
|
+
import { LoaderError } from './types.js';
|
|
6
|
+
import { limits } from './util.js';
|
|
7
|
+
const F = 'NURBS';
|
|
8
|
+
/** Checks a knot vector and gives it its end knots when the file left them out. */
|
|
9
|
+
function knotVector(source, count, degree, name) {
|
|
10
|
+
if (!Number.isSafeInteger(degree) || degree < 1)
|
|
11
|
+
throw new LoaderError(F, 'range', `${name} degree must be 1 or more`);
|
|
12
|
+
if (count <= degree)
|
|
13
|
+
throw new LoaderError(F, 'range', `${name} needs more than ${degree} control points, got ${count}`);
|
|
14
|
+
let knots = Float64Array.from(source);
|
|
15
|
+
if (knots.length === count + degree - 1) {
|
|
16
|
+
const full = new Float64Array(knots.length + 2);
|
|
17
|
+
full.set(knots, 1);
|
|
18
|
+
full[0] = knots[0];
|
|
19
|
+
full[full.length - 1] = knots[knots.length - 1];
|
|
20
|
+
knots = full;
|
|
21
|
+
}
|
|
22
|
+
if (knots.length !== count + degree + 1)
|
|
23
|
+
throw new LoaderError(F, 'range', `${name} has ${knots.length} knots, expected ${count + degree + 1}`);
|
|
24
|
+
for (let i = 0; i < knots.length; i++)
|
|
25
|
+
if (!Number.isFinite(knots[i]) || (i && knots[i] < knots[i - 1]))
|
|
26
|
+
throw new LoaderError(F, 'range', `${name} knots must be finite and non-decreasing`);
|
|
27
|
+
if (!(knots[degree] < knots[count]))
|
|
28
|
+
throw new LoaderError(F, 'range', `${name} has an empty domain`);
|
|
29
|
+
return knots;
|
|
30
|
+
}
|
|
31
|
+
/** Checks the control points and weights and gives them the evaluator's shape. */
|
|
32
|
+
function controlPoints(points, weights, count) {
|
|
33
|
+
if (points.length !== count * 3)
|
|
34
|
+
throw new LoaderError(F, 'range', `${points.length} coordinates for ${count} control points`);
|
|
35
|
+
if (weights && weights.length !== count)
|
|
36
|
+
throw new LoaderError(F, 'range', `${weights.length} weights for ${count} control points`);
|
|
37
|
+
const net = [], out = [];
|
|
38
|
+
for (let i = 0; i < count; i++) {
|
|
39
|
+
const w = weights ? weights[i] : 1;
|
|
40
|
+
if (!(w > 0) || !Number.isFinite(w))
|
|
41
|
+
throw new LoaderError(F, 'range', `weight ${i} must be positive`);
|
|
42
|
+
const point = [points[i * 3], points[i * 3 + 1], points[i * 3 + 2]];
|
|
43
|
+
if (!point.every(Number.isFinite))
|
|
44
|
+
throw new LoaderError(F, 'range', `control point ${i} is not finite`);
|
|
45
|
+
net.push(point);
|
|
46
|
+
out.push(w);
|
|
47
|
+
}
|
|
48
|
+
return { net, weights: out };
|
|
49
|
+
}
|
|
50
|
+
function parameter(t, knots, degree, count) {
|
|
51
|
+
if (!Number.isFinite(t) || t < knots[degree] || t > knots[count])
|
|
52
|
+
throw new LoaderError(F, 'range', `parameter ${t} is outside ${knots[degree]}..${knots[count]}`);
|
|
53
|
+
return t;
|
|
54
|
+
}
|
|
55
|
+
function prepareCurve(curve) {
|
|
56
|
+
const count = Math.floor(curve.points.length / 3), knots = knotVector(curve.knots, count, curve.degree, 'the curve'), { net, weights } = controlPoints(curve.points, curve.weights, count);
|
|
57
|
+
return {
|
|
58
|
+
degree: curve.degree,
|
|
59
|
+
count,
|
|
60
|
+
knots,
|
|
61
|
+
evaluator: new CurveEvaluator({ points: net, degree: curve.degree, knots, weights }),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const curvePoint = ({ evaluator }, t) => evaluator.evaluate(t);
|
|
65
|
+
/**
|
|
66
|
+
* The point of a NURBS curve at parameter `t`.
|
|
67
|
+
*
|
|
68
|
+
* @param curve The degree, knots, control points and weights.
|
|
69
|
+
* @param t A parameter inside the curve's domain.
|
|
70
|
+
* @returns The point, `[x, y, z]`.
|
|
71
|
+
* @throws LoaderError with code `range` for a malformed curve or a parameter outside the domain.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { evaluateNurbsCurve } from '@margoengine/loaders/nurbs';
|
|
76
|
+
*
|
|
77
|
+
* const line = { degree: 1, knots: [0, 0, 1, 1], points: [0, 0, 0, 2, 0, 0] };
|
|
78
|
+
* console.log(evaluateNurbsCurve(line, 0.5));
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export function evaluateNurbsCurve(curve, t) {
|
|
82
|
+
const prepared = prepareCurve(curve);
|
|
83
|
+
return curvePoint(prepared, parameter(t, prepared.knots, prepared.degree, prepared.count));
|
|
84
|
+
}
|
|
85
|
+
function distanceToChord(p, a, b) {
|
|
86
|
+
const d = [b[0] - a[0], b[1] - a[1], b[2] - a[2]], e = [p[0] - a[0], p[1] - a[1], p[2] - a[2]], length = d[0] * d[0] + d[1] * d[1] + d[2] * d[2], s = length > 0 ? Math.min(1, Math.max(0, (e[0] * d[0] + e[1] * d[1] + e[2] * d[2]) / length)) : 0;
|
|
87
|
+
return Math.hypot(e[0] - s * d[0], e[1] - s * d[1], e[2] - s * d[2]);
|
|
88
|
+
}
|
|
89
|
+
/** The distinct knots inside the domain, each span cut `pieces` times when asked. */
|
|
90
|
+
function breaks(knots, degree, count, pieces = 1) {
|
|
91
|
+
const out = [];
|
|
92
|
+
for (let i = degree; i < count; i++) {
|
|
93
|
+
if (knots[i] === knots[i + 1])
|
|
94
|
+
continue;
|
|
95
|
+
for (let k = 0; k < pieces; k++)
|
|
96
|
+
out.push(knots[i] + ((knots[i + 1] - knots[i]) * k) / pieces);
|
|
97
|
+
}
|
|
98
|
+
out.push(knots[count]);
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Turns a NURBS curve into a polyline that stays within `tolerance` of it: each knot span is split until the curve at
|
|
103
|
+
* quarter points of a piece is close to its chord, so straight runs stay cheap and tight bends get more points.
|
|
104
|
+
*
|
|
105
|
+
* @param curve The degree, knots, control points and weights.
|
|
106
|
+
* @param options The chord tolerance and the point limit.
|
|
107
|
+
* @returns xyz per point in order: `mode: 'strip'` of `@margoengine/lines`.
|
|
108
|
+
* @throws LoaderError with code `range` for a malformed curve or `limit` past `maxPoints`.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { tessellateNurbsCurve } from '@margoengine/loaders/nurbs';
|
|
113
|
+
*
|
|
114
|
+
* const arc = { degree: 2, knots: [0, 0, 0, 1, 1, 1], points: [1, 0, 0, 1, 1, 0, 0, 1, 0], weights: [1, Math.SQRT1_2, 1] };
|
|
115
|
+
* console.log(tessellateNurbsCurve(arc, { tolerance: 0.001 }).length / 3);
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export function tessellateNurbsCurve(curve, options = {}) {
|
|
119
|
+
const prepared = prepareCurve(curve), { points } = curve, maxPoints = options.maxPoints ?? 100_000;
|
|
120
|
+
let tolerance = options.tolerance;
|
|
121
|
+
if (tolerance === undefined) {
|
|
122
|
+
const low = [Infinity, Infinity, Infinity], high = [-Infinity, -Infinity, -Infinity];
|
|
123
|
+
for (let i = 0; i < points.length; i++) {
|
|
124
|
+
low[i % 3] = Math.min(low[i % 3], points[i]);
|
|
125
|
+
high[i % 3] = Math.max(high[i % 3], points[i]);
|
|
126
|
+
}
|
|
127
|
+
tolerance = Math.hypot(high[0] - low[0], high[1] - low[1], high[2] - low[2]) * 0.001 || 1e-6;
|
|
128
|
+
}
|
|
129
|
+
if (!(tolerance > 0) || !Number.isFinite(tolerance))
|
|
130
|
+
throw new LoaderError(F, 'range', 'tolerance must be positive');
|
|
131
|
+
if (!Number.isSafeInteger(maxPoints) || maxPoints < 2)
|
|
132
|
+
throw new LoaderError(F, 'range', 'maxPoints must be an integer of 2 or more');
|
|
133
|
+
const out = [], stops = breaks(prepared.knots, prepared.degree, prepared.count), add = (p) => {
|
|
134
|
+
if (out.length / 3 >= maxPoints)
|
|
135
|
+
throw new LoaderError(F, 'limit', `the curve needs more than ${maxPoints} points at this tolerance`);
|
|
136
|
+
out.push(p[0], p[1], p[2]);
|
|
137
|
+
};
|
|
138
|
+
const split = (t0, p0, t1, p1, depth) => {
|
|
139
|
+
const middle = (t0 + t1) / 2, pm = curvePoint(prepared, middle), quarter = curvePoint(prepared, (t0 + middle) / 2), threeQuarter = curvePoint(prepared, (middle + t1) / 2), far = Math.max(distanceToChord(pm, p0, p1), distanceToChord(quarter, p0, p1), distanceToChord(threeQuarter, p0, p1));
|
|
140
|
+
if (far > tolerance && depth < 24) {
|
|
141
|
+
split(t0, p0, middle, pm, depth + 1);
|
|
142
|
+
split(middle, pm, t1, p1, depth + 1);
|
|
143
|
+
}
|
|
144
|
+
else
|
|
145
|
+
add(p1);
|
|
146
|
+
};
|
|
147
|
+
let previous = curvePoint(prepared, stops[0]);
|
|
148
|
+
add(previous);
|
|
149
|
+
for (let i = 1; i < stops.length; i++) {
|
|
150
|
+
const next = curvePoint(prepared, stops[i]);
|
|
151
|
+
split(stops[i - 1], previous, stops[i], next, 0);
|
|
152
|
+
previous = next;
|
|
153
|
+
}
|
|
154
|
+
return Float32Array.from(out);
|
|
155
|
+
}
|
|
156
|
+
function prepareSurface(surface) {
|
|
157
|
+
const { degreeU, degreeV, countU, countV } = surface;
|
|
158
|
+
if (!Number.isSafeInteger(countU) || !Number.isSafeInteger(countV))
|
|
159
|
+
throw new LoaderError(F, 'range', 'countU and countV must be integers');
|
|
160
|
+
const knotsU = knotVector(surface.knotsU, countU, degreeU, 'the surface along u'), knotsV = knotVector(surface.knotsV, countV, degreeV, 'the surface along v'), { net, weights } = controlPoints(surface.points, surface.weights, countU * countV), rows = (list) => Array.from({ length: countU }, (_, i) => list.slice(i * countV, (i + 1) * countV));
|
|
161
|
+
return {
|
|
162
|
+
degreeU,
|
|
163
|
+
degreeV,
|
|
164
|
+
countU,
|
|
165
|
+
countV,
|
|
166
|
+
knotsU,
|
|
167
|
+
knotsV,
|
|
168
|
+
evaluator: new SurfaceEvaluator({ points: rows(net), degreeU, degreeV, knotsU, knotsV, weights: rows(weights) }),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** Writes the point and unit normal at (u, v) into `position` and `normal`. */
|
|
172
|
+
function surfacePoint(s, u, v, position, normal) {
|
|
173
|
+
const { point, du: su, dv: sv } = s.evaluator.derivatives(u, v);
|
|
174
|
+
position[0] = point[0];
|
|
175
|
+
position[1] = point[1];
|
|
176
|
+
position[2] = point[2];
|
|
177
|
+
const x = su[1] * sv[2] - su[2] * sv[1], y = su[2] * sv[0] - su[0] * sv[2], z = su[0] * sv[1] - su[1] * sv[0], length = Math.hypot(x, y, z), scale = Math.hypot(...su) * Math.hypot(...sv);
|
|
178
|
+
// Against the two tangents' own size: at a pole one tangent vanishes and this cross product is rounding noise.
|
|
179
|
+
if (length > 1e-12 * scale && length > 0) {
|
|
180
|
+
normal[0] = x / length;
|
|
181
|
+
normal[1] = y / length;
|
|
182
|
+
normal[2] = z / length;
|
|
183
|
+
}
|
|
184
|
+
else
|
|
185
|
+
normal[0] = normal[1] = normal[2] = 0;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The point and unit normal of a NURBS surface at (u, v). The normal is zero where the surface has none, as at a pole.
|
|
189
|
+
*
|
|
190
|
+
* @param surface The degrees, knots, control grid and weights.
|
|
191
|
+
* @param u A parameter inside the u domain.
|
|
192
|
+
* @param v A parameter inside the v domain.
|
|
193
|
+
* @returns The position and normal.
|
|
194
|
+
* @throws LoaderError with code `range` for a malformed surface or a parameter outside the domain.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* import { evaluateNurbsSurface } from '@margoengine/loaders/nurbs';
|
|
199
|
+
*
|
|
200
|
+
* const patch = { degreeU: 1, degreeV: 1, knotsU: [0, 0, 1, 1], knotsV: [0, 0, 1, 1], countU: 2, countV: 2,
|
|
201
|
+
* points: [0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0] };
|
|
202
|
+
* console.log(evaluateNurbsSurface(patch, 0.5, 0.5));
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
export function evaluateNurbsSurface(surface, u, v) {
|
|
206
|
+
const s = prepareSurface(surface), position = [0, 0, 0], normal = [0, 0, 0];
|
|
207
|
+
surfacePoint(s, parameter(u, s.knotsU, s.degreeU, s.countU), parameter(v, s.knotsV, s.degreeV, s.countV), position, normal);
|
|
208
|
+
return { position, normal };
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Turns a NURBS surface into a triangle grid with exact normals. Grid lines fall on every distinct knot, so creases stay
|
|
212
|
+
* sharp in position. `uvs` run 0 to 1 across the domain. Trim curves are not applied: this is the whole surface.
|
|
213
|
+
*
|
|
214
|
+
* @param surface The degrees, knots, control grid and weights.
|
|
215
|
+
* @param options Quads per knot span and the shared size limits.
|
|
216
|
+
* @returns A mesh with positions, normals, uvs and indices.
|
|
217
|
+
* @throws LoaderError with code `range` for a malformed surface or `limit` past the size limits.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* import { tessellateNurbsSurface } from '@margoengine/loaders/nurbs';
|
|
222
|
+
*
|
|
223
|
+
* const patch = { degreeU: 1, degreeV: 1, knotsU: [0, 0, 1, 1], knotsV: [0, 0, 1, 1], countU: 2, countV: 2,
|
|
224
|
+
* points: [0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0] };
|
|
225
|
+
* console.log(tessellateNurbsSurface(patch, { segmentsU: 2, segmentsV: 2 }).indices?.length);
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export function tessellateNurbsSurface(surface, options = {}) {
|
|
229
|
+
const s = prepareSurface(surface), { maxVertices, maxTriangles } = limits(options, F), segmentsU = options.segmentsU ?? 4 * s.degreeU, segmentsV = options.segmentsV ?? 4 * s.degreeV;
|
|
230
|
+
if (!Number.isSafeInteger(segmentsU) || segmentsU < 1 || !Number.isSafeInteger(segmentsV) || segmentsV < 1)
|
|
231
|
+
throw new LoaderError(F, 'range', 'segmentsU and segmentsV must be positive integers');
|
|
232
|
+
const us = breaks(s.knotsU, s.degreeU, s.countU, segmentsU), vs = breaks(s.knotsV, s.degreeV, s.countV, segmentsV), columns = vs.length, rows = us.length, vertices = rows * columns, triangles = (rows - 1) * (columns - 1) * 2;
|
|
233
|
+
if (vertices > maxVertices)
|
|
234
|
+
throw new LoaderError(F, 'limit', `${vertices} vertices exceed the limit of ${maxVertices}`);
|
|
235
|
+
if (triangles > maxTriangles)
|
|
236
|
+
throw new LoaderError(F, 'limit', `${triangles} triangles exceed the limit of ${maxTriangles}`);
|
|
237
|
+
const positions = new Float32Array(vertices * 3), normals = new Float32Array(vertices * 3), uvs = new Float32Array(vertices * 2), indices = new Uint32Array(triangles * 3), position = [0, 0, 0], normal = [0, 0, 0], u0 = us[0], uSize = us[rows - 1] - u0, v0 = vs[0], vSize = vs[columns - 1] - v0;
|
|
238
|
+
let poles = false;
|
|
239
|
+
for (let i = 0; i < rows; i++)
|
|
240
|
+
for (let j = 0; j < columns; j++) {
|
|
241
|
+
const at = i * columns + j;
|
|
242
|
+
surfacePoint(s, us[i], vs[j], position, normal);
|
|
243
|
+
positions.set(position, at * 3);
|
|
244
|
+
normals.set(normal, at * 3);
|
|
245
|
+
if (!normal[0] && !normal[1] && !normal[2])
|
|
246
|
+
poles = true;
|
|
247
|
+
uvs[at * 2] = (us[i] - u0) / uSize;
|
|
248
|
+
uvs[at * 2 + 1] = (vs[j] - v0) / vSize;
|
|
249
|
+
}
|
|
250
|
+
let t = 0;
|
|
251
|
+
for (let i = 0; i + 1 < rows; i++)
|
|
252
|
+
for (let j = 0; j + 1 < columns; j++) {
|
|
253
|
+
const a = i * columns + j, b = a + columns;
|
|
254
|
+
indices.set([a, b, b + 1, a, b + 1, a + 1], t);
|
|
255
|
+
t += 6;
|
|
256
|
+
}
|
|
257
|
+
if (poles) {
|
|
258
|
+
// A pole has no normal of its own: it takes the one the triangles around it agree on.
|
|
259
|
+
const smooth = computeVertexNormals(positions, indices);
|
|
260
|
+
for (let v = 0; v < vertices; v++)
|
|
261
|
+
if (!normals[v * 3] && !normals[v * 3 + 1] && !normals[v * 3 + 2])
|
|
262
|
+
normals.set(smooth.subarray(v * 3, v * 3 + 3), v * 3);
|
|
263
|
+
}
|
|
264
|
+
return { kind: 'mesh', positions, normals, uvs, indices };
|
|
265
|
+
}
|
package/dist/obj.d.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { type AssetResolver, type LoadedGeometry, type LoadedGroup, type ParseLimits } from './types.js';
|
|
2
|
+
import { type BinaryInput } from './util.js';
|
|
3
|
+
/** A statement kept as written: its keyword, the rest of the line and its 1-based line number. */
|
|
4
|
+
export interface OBJStatement {
|
|
5
|
+
keyword: string;
|
|
6
|
+
value: string;
|
|
7
|
+
line: number;
|
|
8
|
+
}
|
|
9
|
+
/** Options of a texture map statement (`map_Kd -o 0.5 0 -clamp on tex.png`), named as in the MTL specification. */
|
|
10
|
+
export interface MTLMapOptions {
|
|
11
|
+
/** `-o u v w` texture offset; missing components are 0. */
|
|
12
|
+
o?: [number, number, number];
|
|
13
|
+
/** `-s u v w` texture scale; missing components are 1. */
|
|
14
|
+
s?: [number, number, number];
|
|
15
|
+
/** `-t u v w` turbulence; missing components are 0. */
|
|
16
|
+
t?: [number, number, number];
|
|
17
|
+
clamp?: boolean;
|
|
18
|
+
blendu?: boolean;
|
|
19
|
+
blendv?: boolean;
|
|
20
|
+
/** `-cc` color correction. */
|
|
21
|
+
cc?: boolean;
|
|
22
|
+
/** `-bm` bump multiplier. */
|
|
23
|
+
bm?: number;
|
|
24
|
+
boost?: number;
|
|
25
|
+
texres?: number;
|
|
26
|
+
/** `-mm base gain`. */
|
|
27
|
+
mm?: [number, number];
|
|
28
|
+
imfchan?: string;
|
|
29
|
+
type?: string;
|
|
30
|
+
}
|
|
31
|
+
/** One texture map of an MTL material. */
|
|
32
|
+
export interface MTLMap {
|
|
33
|
+
/** File name as written, after the options. */
|
|
34
|
+
file: string;
|
|
35
|
+
/** `file` resolved against the MTL file's folder: the path to give the resolver (relative to the OBJ). */
|
|
36
|
+
path: string;
|
|
37
|
+
options: MTLMapOptions;
|
|
38
|
+
}
|
|
39
|
+
/** One `newmtl` block. Colors are as written (sRGB by convention). */
|
|
40
|
+
export interface MTLMaterial {
|
|
41
|
+
name: string;
|
|
42
|
+
Ka?: [number, number, number];
|
|
43
|
+
Kd?: [number, number, number];
|
|
44
|
+
Ks?: [number, number, number];
|
|
45
|
+
Ke?: [number, number, number];
|
|
46
|
+
Ns?: number;
|
|
47
|
+
/** Opacity, 1 = opaque. */
|
|
48
|
+
d?: number;
|
|
49
|
+
/** Transparency as written (usually 1 - d). */
|
|
50
|
+
Tr?: number;
|
|
51
|
+
illum?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Texture maps by statement, in a null-prototype object: `map_Kd`, `map_Ka`, `map_Ks`, `map_Ke`, `map_Ns`, `map_d`,
|
|
54
|
+
* `bump` (also written `map_Bump`), `disp`, `decal`, `refl`, and any other `map_*` as written. A cube reflection's
|
|
55
|
+
* `refl -type cube_top` (and `cube_bottom`, `_front`, `_back`, `_left`, `_right`) statements are each kept as
|
|
56
|
+
* `refl_cube_top` and so on, beside `refl`, which holds the last `refl` statement.
|
|
57
|
+
*/
|
|
58
|
+
maps: Record<string, MTLMap>;
|
|
59
|
+
/** Statements this reader does not interpret (`Ni`, `Tf`, `Pr`, spectral colors, unknown map options, ...). */
|
|
60
|
+
extras: OBJStatement[];
|
|
61
|
+
}
|
|
62
|
+
/** A run of faces with the same object, groups and material. */
|
|
63
|
+
export interface OBJGroup extends LoadedGroup {
|
|
64
|
+
/** Name from the last `o` statement. */
|
|
65
|
+
object?: string;
|
|
66
|
+
/** Names from the last `g` statement (one `g` may list several). */
|
|
67
|
+
groupNames: string[];
|
|
68
|
+
/** Material from the last `usemtl` statement. */
|
|
69
|
+
material?: string;
|
|
70
|
+
}
|
|
71
|
+
/** The budget for an OBJ's material libraries, shared by every `mtllib` file it names. */
|
|
72
|
+
export interface OBJMaterialLimits {
|
|
73
|
+
/** Most `mtllib` files read; more throws a `LoaderError` with code `'limit'` before any is read. Default 16. */
|
|
74
|
+
maxMaterialLibraries?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Most bytes all `mtllib` files may hold together (a string counts its length); more throws a `LoaderError` with
|
|
77
|
+
* code `'limit'`. Default 64 MiB.
|
|
78
|
+
*/
|
|
79
|
+
maxMaterialBytes?: number;
|
|
80
|
+
}
|
|
81
|
+
/** @internal Defaults of OBJMaterialLimits (loadOBJ reads them too). */
|
|
82
|
+
export declare const DEFAULT_MAX_MATERIAL_LIBRARIES = 16;
|
|
83
|
+
/** @internal */
|
|
84
|
+
export declare const DEFAULT_MAX_MATERIAL_BYTES: number;
|
|
85
|
+
/** Options of `parseOBJ`. */
|
|
86
|
+
export interface OBJParseOptions extends ParseLimits, OBJMaterialLimits {
|
|
87
|
+
/**
|
|
88
|
+
* Reads each `mtllib` file, given its path relative to the OBJ folder. Without it `materials` stays empty. A file
|
|
89
|
+
* it cannot read is a warning; a `LoaderError` with code `'url'` (a refused URL) or `'limit'` stops the parse.
|
|
90
|
+
*/
|
|
91
|
+
resolve?: AssetResolver;
|
|
92
|
+
signal?: AbortSignal;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A parsed OBJ. Every distinct (v, vt, vn) corner is one vertex, so UV and normal seams are kept; `colors` come from
|
|
96
|
+
* the `v` lines. `uvs` use Margo's convention, v = 1 - vt v (OBJ puts v = 0 at the bottom of the image, Margo and
|
|
97
|
+
* glTF at the top). Faces are fan-triangulated in file order: face f with n = `faceSizes[f]` corners c0..cn-1 gives
|
|
98
|
+
* the triangles (c0, ck, ck+1), so the original polygons can be rebuilt from `indices` and `faceSizes`.
|
|
99
|
+
*/
|
|
100
|
+
export interface LoadedOBJ extends LoadedGeometry {
|
|
101
|
+
groups: OBJGroup[];
|
|
102
|
+
/** Corner count of each face, in file order. */
|
|
103
|
+
faceSizes: Uint32Array;
|
|
104
|
+
/** `s` smoothing group of each face; 0 is off. */
|
|
105
|
+
smoothingGroups: Uint32Array;
|
|
106
|
+
/** For each vertex, the 0-based `v` it came from: corners that share a position share this even across seams. */
|
|
107
|
+
positionIndices: Uint32Array;
|
|
108
|
+
/** `mtllib` file names in order, without duplicates. */
|
|
109
|
+
materialLibraries: string[];
|
|
110
|
+
/** Materials of those libraries (first definition of a name wins); empty without `resolve`. */
|
|
111
|
+
materials: MTLMaterial[];
|
|
112
|
+
/** Texture paths `materials` use, relative to the OBJ folder and without duplicates: give each to the resolver. */
|
|
113
|
+
images: string[];
|
|
114
|
+
/**
|
|
115
|
+
* `p` point elements: one vertex index each, in file order, into `positions` (with faces, the corner welded from
|
|
116
|
+
* that `v`; without faces, the `v` itself).
|
|
117
|
+
*/
|
|
118
|
+
pointIndices: Uint32Array;
|
|
119
|
+
/** `l` line elements as segments, two vertex indices each, a polyline of n vertices giving n - 1 segments. */
|
|
120
|
+
lineIndices: Uint32Array;
|
|
121
|
+
/** Statements this reader does not interpret (`vp`, curves, surfaces, ...), in order. */
|
|
122
|
+
extras: OBJStatement[];
|
|
123
|
+
/** Problems that did not stop the import, such as an MTL file the resolver could not read. */
|
|
124
|
+
warnings: string[];
|
|
125
|
+
}
|
|
126
|
+
/** Options of `parseMTL`. */
|
|
127
|
+
export interface MTLParseOptions {
|
|
128
|
+
/** The MTL file's path relative to the OBJ folder; texture paths resolve against its folder. Default `''`. */
|
|
129
|
+
path?: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Parses a Wavefront MTL library: `newmtl`, `Ka`, `Kd`, `Ks`, `Ke`, `Ns`, `d`, `Tr`, `illum` and every texture map
|
|
133
|
+
* with its options. Statements it does not interpret are kept in each material's `extras`.
|
|
134
|
+
*/
|
|
135
|
+
export declare function parseMTL(input: BinaryInput | string, options?: MTLParseOptions): MTLMaterial[];
|
|
136
|
+
/**
|
|
137
|
+
* Parses a Wavefront OBJ: `v` (with optional `w`, or `r g b` vertex colors after xyz), `vt`, `vn`, faces of any size
|
|
138
|
+
* with `v`, `v/vt`, `v//vn`, `v/vt/vn` and negative (relative) indices, `p` points and `l` polylines (into `pointIndices`
|
|
139
|
+
* and `lineIndices`), `o`, `g`, `s`, `usemtl` and `mtllib`, with
|
|
140
|
+
* `\` line continuations, comments and CRLF. With `resolve` it also reads every MTL library (within
|
|
141
|
+
* `maxMaterialLibraries` and `maxMaterialBytes`) and colors each group with its material's `Kd`. Malformed input
|
|
142
|
+
* throws a `LoaderError` naming the line. A file without faces is a
|
|
143
|
+
* point cloud of its `v` lines.
|
|
144
|
+
*/
|
|
145
|
+
export declare function parseOBJ(input: BinaryInput | string, options?: OBJParseOptions): Promise<LoadedOBJ>;
|