@bitbybit-dev/base 1.5.0 → 1.6.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/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/bearings/ansi-bearings.constants.d.ts +2 -0
- package/lib/api/bearings/ansi-bearings.constants.js +26 -0
- package/lib/api/bearings/ansi-bearings.d.ts +4 -0
- package/lib/api/bearings/ansi-bearings.js +14 -0
- package/lib/api/bearings/bearing-types.d.ts +25 -0
- package/lib/api/bearings/bearing-types.js +1 -0
- package/lib/api/bearings/bearings.constants.d.ts +1 -0
- package/lib/api/bearings/bearings.constants.js +1 -0
- package/lib/api/bearings/iso-bearings.constants.d.ts +2 -0
- package/lib/api/bearings/iso-bearings.constants.js +30 -0
- package/lib/api/bearings/iso-bearings.d.ts +4 -0
- package/lib/api/bearings/iso-bearings.js +14 -0
- package/lib/api/color-space.d.ts +2 -0
- package/lib/api/color-space.js +5 -8
- package/lib/api/fasteners/ansi-fasteners.constants.d.ts +16 -0
- package/lib/api/fasteners/ansi-fasteners.constants.js +118 -0
- package/lib/api/fasteners/ansi-fasteners.d.ts +8 -0
- package/lib/api/fasteners/ansi-fasteners.js +64 -0
- package/lib/api/fasteners/fastener-types.d.ts +161 -0
- package/lib/api/fasteners/fastener-types.js +1 -0
- package/lib/api/fasteners/fasteners.constants.d.ts +5 -0
- package/lib/api/fasteners/fasteners.constants.js +5 -0
- package/lib/api/fasteners/fasteners.d.ts +2 -0
- package/lib/api/fasteners/fasteners.js +9 -0
- package/lib/api/fasteners/iso-fasteners.constants.d.ts +23 -0
- package/lib/api/fasteners/iso-fasteners.constants.js +110 -0
- package/lib/api/fasteners/iso-fasteners.d.ts +9 -0
- package/lib/api/fasteners/iso-fasteners.js +61 -0
- package/lib/api/gears/bevel-gears.d.ts +6 -0
- package/lib/api/gears/bevel-gears.js +69 -0
- package/lib/api/gears/gear-checks.d.ts +8 -0
- package/lib/api/gears/gear-checks.js +69 -0
- package/lib/api/gears/gear-pairs.d.ts +4 -0
- package/lib/api/gears/gear-pairs.js +140 -0
- package/lib/api/gears/gear-types.d.ts +425 -0
- package/lib/api/gears/gear-types.js +1 -0
- package/lib/api/gears/gears.constants.d.ts +19 -0
- package/lib/api/gears/gears.constants.js +19 -0
- package/lib/api/gears/gears.d.ts +10 -0
- package/lib/api/gears/gears.js +156 -0
- package/lib/api/gears/helical-gears.d.ts +5 -0
- package/lib/api/gears/helical-gears.js +33 -0
- package/lib/api/gears/involute-flank.d.ts +26 -0
- package/lib/api/gears/involute-flank.js +158 -0
- package/lib/api/gears/racks.d.ts +3 -0
- package/lib/api/gears/racks.js +64 -0
- package/lib/api/index.d.ts +10 -1
- package/lib/api/index.js +0 -1
- package/lib/api/inputs/base-inputs.d.ts +450 -3
- package/lib/api/inputs/base-inputs.js +12 -0
- package/lib/api/inputs/color-inputs.d.ts +14 -0
- package/lib/api/inputs/color-inputs.js +19 -0
- package/lib/api/inputs/engineering-inputs.d.ts +1539 -0
- package/lib/api/inputs/engineering-inputs.js +2181 -0
- package/lib/api/inputs/index.d.ts +2 -0
- package/lib/api/inputs/index.js +2 -0
- package/lib/api/inputs/io-inputs.d.ts +8 -1
- package/lib/api/inputs/io-inputs.js +4 -1
- package/lib/api/inputs/math-inputs.d.ts +61 -0
- package/lib/api/inputs/math-inputs.js +85 -0
- package/lib/api/inputs/mesh-inputs.d.ts +170 -0
- package/lib/api/inputs/mesh-inputs.js +206 -0
- package/lib/api/inputs/point-inputs.d.ts +4 -4
- package/lib/api/inputs/polyline-inputs.d.ts +144 -0
- package/lib/api/inputs/polyline-inputs.js +151 -0
- package/lib/api/inputs/recipes-inputs.d.ts +76 -0
- package/lib/api/inputs/recipes-inputs.js +74 -0
- package/lib/api/inputs/transforms-inputs.d.ts +34 -0
- package/lib/api/inputs/transforms-inputs.js +35 -0
- package/lib/api/keys/ansi-keys.constants.d.ts +3 -0
- package/lib/api/keys/ansi-keys.constants.js +16 -0
- package/lib/api/keys/ansi-keys.d.ts +3 -0
- package/lib/api/keys/ansi-keys.js +14 -0
- package/lib/api/keys/din-keys.constants.d.ts +3 -0
- package/lib/api/keys/din-keys.constants.js +14 -0
- package/lib/api/keys/din-keys.d.ts +3 -0
- package/lib/api/keys/din-keys.js +13 -0
- package/lib/api/keys/key-types.d.ts +17 -0
- package/lib/api/keys/key-types.js +1 -0
- package/lib/api/keys/keys.constants.d.ts +1 -0
- package/lib/api/keys/keys.constants.js +1 -0
- package/lib/api/knurls/ansi-knurls.constants.d.ts +4 -0
- package/lib/api/knurls/ansi-knurls.constants.js +8 -0
- package/lib/api/knurls/ansi-knurls.d.ts +3 -0
- package/lib/api/knurls/ansi-knurls.js +20 -0
- package/lib/api/knurls/din-knurls.constants.d.ts +2 -0
- package/lib/api/knurls/din-knurls.constants.js +2 -0
- package/lib/api/knurls/din-knurls.d.ts +3 -0
- package/lib/api/knurls/din-knurls.js +19 -0
- package/lib/api/knurls/knurl-types.d.ts +24 -0
- package/lib/api/knurls/knurl-types.js +1 -0
- package/lib/api/knurls/knurls.constants.d.ts +1 -0
- package/lib/api/knurls/knurls.constants.js +1 -0
- package/lib/api/knurls/knurls.d.ts +2 -0
- package/lib/api/knurls/knurls.js +9 -0
- package/lib/api/recipes/checks.d.ts +15 -0
- package/lib/api/recipes/checks.js +85 -0
- package/lib/api/recipes/limits.constants.d.ts +4 -0
- package/lib/api/recipes/limits.constants.js +4 -0
- package/lib/api/recipes/sources.d.ts +0 -13
- package/lib/api/recipes/sources.js +3 -15
- package/lib/api/recipes/surface-mesh.d.ts +0 -14
- package/lib/api/recipes/surface-mesh.js +8 -21
- package/lib/api/recipes/validate-brep.d.ts +2 -0
- package/lib/api/recipes/validate-brep.js +330 -0
- package/lib/api/recipes/validate.d.ts +0 -31
- package/lib/api/recipes/validate.js +7 -115
- package/lib/api/resolved-inputs/index.d.ts +80 -0
- package/lib/api/retaining-rings/ansi-retaining-rings.constants.d.ts +4 -0
- package/lib/api/retaining-rings/ansi-retaining-rings.constants.js +93 -0
- package/lib/api/retaining-rings/ansi-retaining-rings.d.ts +4 -0
- package/lib/api/retaining-rings/ansi-retaining-rings.js +20 -0
- package/lib/api/retaining-rings/din-retaining-rings.constants.d.ts +3 -0
- package/lib/api/retaining-rings/din-retaining-rings.constants.js +115 -0
- package/lib/api/retaining-rings/din-retaining-rings.d.ts +4 -0
- package/lib/api/retaining-rings/din-retaining-rings.js +20 -0
- package/lib/api/retaining-rings/retaining-ring-types.d.ts +30 -0
- package/lib/api/retaining-rings/retaining-ring-types.js +1 -0
- package/lib/api/retaining-rings/retaining-rings.constants.d.ts +1 -0
- package/lib/api/retaining-rings/retaining-rings.constants.js +1 -0
- package/lib/api/retaining-rings/retaining-rings.d.ts +2 -0
- package/lib/api/retaining-rings/retaining-rings.js +9 -0
- package/lib/api/services/base-bitbybit.d.ts +42 -0
- package/lib/api/services/base-bitbybit.js +43 -0
- package/lib/api/services/color.d.ts +35 -2
- package/lib/api/services/color.js +48 -12
- package/lib/api/services/engineering/engineering.d.ts +12 -0
- package/lib/api/services/engineering/engineering.js +13 -0
- package/lib/api/services/engineering/index.d.ts +2 -0
- package/lib/api/services/engineering/index.js +2 -0
- package/lib/api/services/engineering/mechanical/bearings-ansi.d.ts +40 -0
- package/lib/api/services/engineering/mechanical/bearings-ansi.js +47 -0
- package/lib/api/services/engineering/mechanical/bearings-iso.d.ts +39 -0
- package/lib/api/services/engineering/mechanical/bearings-iso.js +46 -0
- package/lib/api/services/engineering/mechanical/bearings.d.ts +14 -0
- package/lib/api/services/engineering/mechanical/bearings.js +15 -0
- package/lib/api/services/engineering/mechanical/fasteners-ansi.d.ts +109 -0
- package/lib/api/services/engineering/mechanical/fasteners-ansi.js +133 -0
- package/lib/api/services/engineering/mechanical/fasteners-iso.d.ts +123 -0
- package/lib/api/services/engineering/mechanical/fasteners-iso.js +151 -0
- package/lib/api/services/engineering/mechanical/fasteners.d.ts +13 -0
- package/lib/api/services/engineering/mechanical/fasteners.js +14 -0
- package/lib/api/services/engineering/mechanical/gears.d.ts +267 -0
- package/lib/api/services/engineering/mechanical/gears.js +318 -0
- package/lib/api/services/engineering/mechanical/index.d.ts +24 -0
- package/lib/api/services/engineering/mechanical/index.js +24 -0
- package/lib/api/services/engineering/mechanical/keys-ansi.d.ts +27 -0
- package/lib/api/services/engineering/mechanical/keys-ansi.js +32 -0
- package/lib/api/services/engineering/mechanical/keys-din.d.ts +26 -0
- package/lib/api/services/engineering/mechanical/keys-din.js +31 -0
- package/lib/api/services/engineering/mechanical/keys.d.ts +14 -0
- package/lib/api/services/engineering/mechanical/keys.js +15 -0
- package/lib/api/services/engineering/mechanical/knurls-ansi.d.ts +26 -0
- package/lib/api/services/engineering/mechanical/knurls-ansi.js +31 -0
- package/lib/api/services/engineering/mechanical/knurls-din.d.ts +26 -0
- package/lib/api/services/engineering/mechanical/knurls-din.js +31 -0
- package/lib/api/services/engineering/mechanical/knurls.d.ts +14 -0
- package/lib/api/services/engineering/mechanical/knurls.js +15 -0
- package/lib/api/services/engineering/mechanical/mechanical.d.ts +29 -0
- package/lib/api/services/engineering/mechanical/mechanical.js +30 -0
- package/lib/api/services/engineering/mechanical/retaining-rings-ansi.d.ts +43 -0
- package/lib/api/services/engineering/mechanical/retaining-rings-ansi.js +51 -0
- package/lib/api/services/engineering/mechanical/retaining-rings-din.d.ts +43 -0
- package/lib/api/services/engineering/mechanical/retaining-rings-din.js +51 -0
- package/lib/api/services/engineering/mechanical/retaining-rings.d.ts +13 -0
- package/lib/api/services/engineering/mechanical/retaining-rings.js +14 -0
- package/lib/api/services/engineering/mechanical/splines-ansi.d.ts +27 -0
- package/lib/api/services/engineering/mechanical/splines-ansi.js +32 -0
- package/lib/api/services/engineering/mechanical/splines-din.d.ts +26 -0
- package/lib/api/services/engineering/mechanical/splines-din.js +31 -0
- package/lib/api/services/engineering/mechanical/splines.d.ts +13 -0
- package/lib/api/services/engineering/mechanical/splines.js +14 -0
- package/lib/api/services/engineering/mechanical/springs.d.ts +27 -0
- package/lib/api/services/engineering/mechanical/springs.js +31 -0
- package/lib/api/services/engineering/mechanical/threads-ansi.d.ts +40 -0
- package/lib/api/services/engineering/mechanical/threads-ansi.js +48 -0
- package/lib/api/services/engineering/mechanical/threads-iso.d.ts +40 -0
- package/lib/api/services/engineering/mechanical/threads-iso.js +48 -0
- package/lib/api/services/engineering/mechanical/threads.d.ts +13 -0
- package/lib/api/services/engineering/mechanical/threads.js +14 -0
- package/lib/api/services/frame.js +3 -3
- package/lib/api/services/geometry-helper.js +8 -111
- package/lib/api/services/helpers/color/color-space.d.ts +2 -0
- package/lib/api/services/helpers/color/color-space.js +12 -0
- package/lib/api/services/helpers/{nurbs.d.ts → curves/nurbs.d.ts} +1 -1
- package/lib/api/services/helpers/{surface-triangulation.d.ts → curves/surface-triangulation.d.ts} +2 -2
- package/lib/api/services/helpers/{surface-triangulation.js → curves/surface-triangulation.js} +14 -8
- package/lib/api/services/helpers/{dxf → files/dxf}/dxf-generator.d.ts +2 -1
- package/lib/api/services/helpers/{dxf → files/dxf}/dxf-generator.js +19 -5
- package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +4 -0
- package/lib/api/services/helpers/files/dxf/dxf.constants.js +4 -0
- package/lib/api/services/helpers/{dxf → files/dxf}/dxf.d.ts +1 -1
- package/lib/api/services/helpers/{dxf → files/dxf}/dxf.js +2 -2
- package/lib/api/services/helpers/files/glb.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/glb.constants.js +11 -0
- package/lib/api/services/helpers/files/glb.d.ts +1 -0
- package/lib/api/services/helpers/files/glb.js +69 -0
- package/lib/api/services/helpers/files/gzip.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/gzip.constants.js +11 -0
- package/lib/api/services/helpers/files/gzip.d.ts +2 -0
- package/lib/api/services/helpers/files/gzip.js +50 -0
- package/lib/api/services/helpers/{inflate.constants.d.ts → files/inflate.constants.d.ts} +2 -0
- package/lib/api/services/helpers/{inflate.constants.js → files/inflate.constants.js} +2 -0
- package/lib/api/services/helpers/{inflate.d.ts → files/inflate.d.ts} +2 -2
- package/lib/api/services/helpers/{inflate.js → files/inflate.js} +16 -7
- package/lib/api/services/helpers/{zip.constants.d.ts → files/zip.constants.d.ts} +8 -0
- package/lib/api/services/helpers/{zip.constants.js → files/zip.constants.js} +8 -0
- package/lib/api/services/helpers/files/zip.d.ts +8 -0
- package/lib/api/services/helpers/files/zip.js +226 -0
- package/lib/api/services/helpers/geometry/arcs.d.ts +9 -0
- package/lib/api/services/helpers/{arcs.js → geometry/arcs.js} +7 -0
- package/lib/api/services/helpers/{frame-axes.d.ts → geometry/frame-axes.d.ts} +8 -5
- package/lib/api/services/helpers/{frame-axes.js → geometry/frame-axes.js} +21 -9
- package/lib/api/services/helpers/geometry/lengths.constants.d.ts +4 -0
- package/lib/api/services/helpers/geometry/lengths.constants.js +3 -0
- package/lib/api/services/helpers/geometry/lengths.d.ts +7 -0
- package/lib/api/services/helpers/geometry/lengths.js +20 -0
- package/lib/api/services/helpers/geometry/matrices.constants.d.ts +8 -0
- package/lib/api/services/helpers/geometry/matrices.constants.js +7 -0
- package/lib/api/services/helpers/geometry/matrices.d.ts +17 -0
- package/lib/api/services/helpers/{matrices.js → geometry/matrices.js} +28 -17
- package/lib/api/services/helpers/{paths.d.ts → geometry/paths.d.ts} +2 -1
- package/lib/api/services/helpers/{paths.js → geometry/paths.js} +36 -30
- package/lib/api/services/helpers/{polygons.d.ts → geometry/polygons.d.ts} +1 -1
- package/lib/api/services/helpers/geometry/polygons.js +111 -0
- package/lib/api/services/helpers/geometry/scalars.d.ts +9 -0
- package/lib/api/services/helpers/geometry/scalars.js +34 -0
- package/lib/api/services/helpers/{triangulation.js → geometry/triangulation.js} +11 -6
- package/lib/api/services/helpers/geometry/vector-grid.d.ts +12 -0
- package/lib/api/services/helpers/geometry/vector-grid.js +149 -0
- package/lib/api/services/helpers/{vectors.d.ts → geometry/vectors.d.ts} +8 -1
- package/lib/api/services/helpers/geometry/vectors.js +43 -0
- package/lib/api/services/helpers/helper-types.d.ts +77 -0
- package/lib/api/services/helpers/mesh/mesh-normals.d.ts +21 -0
- package/lib/api/services/helpers/{mesh-normals.js → mesh/mesh-normals.js} +54 -65
- package/lib/api/services/helpers/mesh/mesh-orientation.d.ts +24 -0
- package/lib/api/services/helpers/mesh/mesh-orientation.js +104 -0
- package/lib/api/services/helpers/{mesh-primitives.d.ts → mesh/mesh-primitives.d.ts} +1 -1
- package/lib/api/services/helpers/{mesh-primitives.js → mesh/mesh-primitives.js} +6 -5
- package/lib/api/services/helpers/mesh/mesh-proximity.constants.d.ts +7 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.constants.js +11 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.d.ts +11 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.js +382 -0
- package/lib/api/services/index.d.ts +3 -0
- package/lib/api/services/index.js +3 -0
- package/lib/api/services/io.d.ts +1 -1
- package/lib/api/services/io.js +1 -1
- package/lib/api/services/line.js +2 -3
- package/lib/api/services/math.d.ts +47 -0
- package/lib/api/services/math.js +77 -10
- package/lib/api/services/mesh.d.ts +174 -2
- package/lib/api/services/mesh.js +305 -7
- package/lib/api/services/point.js +4 -10
- package/lib/api/services/polyline-types.d.ts +6 -0
- package/lib/api/services/polyline-types.js +1 -0
- package/lib/api/services/polyline.d.ts +163 -1
- package/lib/api/services/polyline.js +270 -13
- package/lib/api/services/recipes.d.ts +80 -0
- package/lib/api/services/recipes.js +107 -0
- package/lib/api/services/transforms.d.ts +74 -2
- package/lib/api/services/transforms.js +100 -3
- package/lib/api/services/vector.d.ts +4 -3
- package/lib/api/services/vector.js +14 -14
- package/lib/api/splines/ansi-splines.constants.d.ts +9 -0
- package/lib/api/splines/ansi-splines.constants.js +9 -0
- package/lib/api/splines/ansi-splines.d.ts +3 -0
- package/lib/api/splines/ansi-splines.js +28 -0
- package/lib/api/splines/din-splines.constants.d.ts +12 -0
- package/lib/api/splines/din-splines.constants.js +12 -0
- package/lib/api/splines/din-splines.d.ts +3 -0
- package/lib/api/splines/din-splines.js +38 -0
- package/lib/api/splines/spline-types.d.ts +32 -0
- package/lib/api/splines/spline-types.js +1 -0
- package/lib/api/splines/splines.constants.d.ts +1 -0
- package/lib/api/splines/splines.constants.js +1 -0
- package/lib/api/springs/spring-types.d.ts +26 -0
- package/lib/api/springs/spring-types.js +1 -0
- package/lib/api/springs/springs.constants.d.ts +9 -0
- package/lib/api/springs/springs.constants.js +9 -0
- package/lib/api/springs/springs.d.ts +2 -0
- package/lib/api/springs/springs.js +50 -0
- package/lib/api/threads/ansi-threads.constants.d.ts +6 -0
- package/lib/api/threads/ansi-threads.constants.js +27 -0
- package/lib/api/threads/ansi-threads.d.ts +4 -0
- package/lib/api/threads/ansi-threads.js +50 -0
- package/lib/api/threads/iso-threads.constants.d.ts +5 -0
- package/lib/api/threads/iso-threads.constants.js +20 -0
- package/lib/api/threads/iso-threads.d.ts +4 -0
- package/lib/api/threads/iso-threads.js +32 -0
- package/lib/api/threads/thread-profile.constants.d.ts +3 -0
- package/lib/api/threads/thread-profile.constants.js +3 -0
- package/lib/api/threads/thread-types.d.ts +66 -0
- package/lib/api/threads/thread-types.js +1 -0
- package/package.json +1 -1
- package/lib/api/recipes/index.d.ts +0 -4
- package/lib/api/recipes/index.js +0 -3
- package/lib/api/services/helpers/arcs.d.ts +0 -6
- package/lib/api/services/helpers/matrices.constants.d.ts +0 -2
- package/lib/api/services/helpers/matrices.constants.js +0 -2
- package/lib/api/services/helpers/matrices.d.ts +0 -25
- package/lib/api/services/helpers/mesh-normals.d.ts +0 -11
- package/lib/api/services/helpers/polygons.js +0 -59
- package/lib/api/services/helpers/vectors.js +0 -17
- package/lib/api/services/helpers/zip.d.ts +0 -4
- package/lib/api/services/helpers/zip.js +0 -89
- /package/lib/api/services/helpers/{nurbs.js → curves/nurbs.js} +0 -0
- /package/lib/api/services/helpers/{crc32.d.ts → files/crc32.d.ts} +0 -0
- /package/lib/api/services/helpers/{crc32.js → files/crc32.js} +0 -0
- /package/lib/api/services/helpers/{triangulation.d.ts → geometry/triangulation.d.ts} +0 -0
- /package/lib/api/services/helpers/{mesh-measures.d.ts → mesh/mesh-measures.d.ts} +0 -0
- /package/lib/api/services/helpers/{mesh-measures.js → mesh/mesh-measures.js} +0 -0
- /package/lib/api/services/helpers/{mesh-primitives.constants.d.ts → mesh/mesh-primitives.constants.d.ts} +0 -0
- /package/lib/api/services/helpers/{mesh-primitives.constants.js → mesh/mesh-primitives.constants.js} +0 -0
|
@@ -1,67 +1,9 @@
|
|
|
1
|
+
import { radiansOf } from "../geometry/scalars";
|
|
1
2
|
const CORNERS = 3;
|
|
2
3
|
const COORDINATES = 3;
|
|
3
|
-
const X = 0;
|
|
4
4
|
const Y = 1;
|
|
5
5
|
const Z = 2;
|
|
6
|
-
const HALF_TURN_DEGREES = 180;
|
|
7
|
-
const DEGREES_TO_RADIANS = Math.PI / HALF_TURN_DEGREES;
|
|
8
6
|
const ANGLE_SLACK = 1e-9;
|
|
9
|
-
/**
|
|
10
|
-
* Compute smooth vertex normals for a mesh that arrives without them.
|
|
11
|
-
* Accumulates each triangle's cross product onto its three vertices, then normalizes, so a vertex
|
|
12
|
-
* shared by several triangles ends up with their average and the mesh shades smoothly.
|
|
13
|
-
* @param positions - Flat array of vertex positions [x,y,z,x,y,z,...]
|
|
14
|
-
* @param indices - Triangle indices
|
|
15
|
-
* @returns Flat array of normals [nx,ny,nz,nx,ny,nz,...]
|
|
16
|
-
*/
|
|
17
|
-
export function computeVertexNormals(positions, indices) {
|
|
18
|
-
const numVertices = positions.length / COORDINATES;
|
|
19
|
-
const normals = new Float32Array(positions.length);
|
|
20
|
-
for (let i = 0; i < indices.length; i += CORNERS) {
|
|
21
|
-
const i0 = indices[i];
|
|
22
|
-
const i1 = indices[i + 1];
|
|
23
|
-
const i2 = indices[i + 2];
|
|
24
|
-
const v0x = positions[i0 * COORDINATES + X];
|
|
25
|
-
const v0y = positions[i0 * COORDINATES + Y];
|
|
26
|
-
const v0z = positions[i0 * COORDINATES + Z];
|
|
27
|
-
const v1x = positions[i1 * COORDINATES + X];
|
|
28
|
-
const v1y = positions[i1 * COORDINATES + Y];
|
|
29
|
-
const v1z = positions[i1 * COORDINATES + Z];
|
|
30
|
-
const v2x = positions[i2 * COORDINATES + X];
|
|
31
|
-
const v2y = positions[i2 * COORDINATES + Y];
|
|
32
|
-
const v2z = positions[i2 * COORDINATES + Z];
|
|
33
|
-
const e1x = v1x - v0x;
|
|
34
|
-
const e1y = v1y - v0y;
|
|
35
|
-
const e1z = v1z - v0z;
|
|
36
|
-
const e2x = v2x - v0x;
|
|
37
|
-
const e2y = v2y - v0y;
|
|
38
|
-
const e2z = v2z - v0z;
|
|
39
|
-
const nx = e1y * e2z - e1z * e2y;
|
|
40
|
-
const ny = e1z * e2x - e1x * e2z;
|
|
41
|
-
const nz = e1x * e2y - e1y * e2x;
|
|
42
|
-
normals[i0 * COORDINATES + X] += nx;
|
|
43
|
-
normals[i0 * COORDINATES + Y] += ny;
|
|
44
|
-
normals[i0 * COORDINATES + Z] += nz;
|
|
45
|
-
normals[i1 * COORDINATES + X] += nx;
|
|
46
|
-
normals[i1 * COORDINATES + Y] += ny;
|
|
47
|
-
normals[i1 * COORDINATES + Z] += nz;
|
|
48
|
-
normals[i2 * COORDINATES + X] += nx;
|
|
49
|
-
normals[i2 * COORDINATES + Y] += ny;
|
|
50
|
-
normals[i2 * COORDINATES + Z] += nz;
|
|
51
|
-
}
|
|
52
|
-
for (let i = 0; i < numVertices; i++) {
|
|
53
|
-
const x = normals[i * COORDINATES + X];
|
|
54
|
-
const y = normals[i * COORDINATES + Y];
|
|
55
|
-
const z = normals[i * COORDINATES + Z];
|
|
56
|
-
const len = Math.sqrt(x * x + y * y + z * z);
|
|
57
|
-
if (len > 0) {
|
|
58
|
-
normals[i * COORDINATES + X] = x / len;
|
|
59
|
-
normals[i * COORDINATES + Y] = y / len;
|
|
60
|
-
normals[i * COORDINATES + Z] = z / len;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return Array.from(normals);
|
|
64
|
-
}
|
|
65
7
|
const faceNormalsOf = (positions, indices) => {
|
|
66
8
|
const normals = new Float64Array(indices.length);
|
|
67
9
|
for (let at = 0; at + CORNERS - 1 < indices.length; at += CORNERS) {
|
|
@@ -95,7 +37,44 @@ const facesAround = (indices, vertexCount) => {
|
|
|
95
37
|
}
|
|
96
38
|
return [starts, faces];
|
|
97
39
|
};
|
|
98
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Smooth normals for a mesh that arrives without them: each point takes the sum of the normals of
|
|
42
|
+
* the triangles around it, each as long as twice its triangle's area, scaled to length 1, so a large
|
|
43
|
+
* triangle counts for more than a sliver and the mesh shades smoothly. A point that no triangle with
|
|
44
|
+
* an area touches keeps a normal of zero.
|
|
45
|
+
* @param positions - Flat array of vertex positions [x,y,z,x,y,z,...]
|
|
46
|
+
* @param indices - Triangle indices
|
|
47
|
+
* @returns Flat array of normals [nx,ny,nz,nx,ny,nz,...]
|
|
48
|
+
*/
|
|
49
|
+
export function computeVertexNormals(positions, indices) {
|
|
50
|
+
const faces = faceNormalsOf(positions, indices);
|
|
51
|
+
const normals = new Float64Array(positions.length);
|
|
52
|
+
for (let corner = 0; corner < faces.length; corner++) {
|
|
53
|
+
const face = corner - corner % CORNERS;
|
|
54
|
+
const at = indices[corner] * COORDINATES;
|
|
55
|
+
normals[at] = normals[at] + faces[face];
|
|
56
|
+
normals[at + Y] = normals[at + Y] + faces[face + Y];
|
|
57
|
+
normals[at + Z] = normals[at + Z] + faces[face + Z];
|
|
58
|
+
}
|
|
59
|
+
for (let at = 0; at + Z < normals.length; at += COORDINATES) {
|
|
60
|
+
const length = Math.hypot(normals[at], normals[at + Y], normals[at + Z]);
|
|
61
|
+
if (length > 0) {
|
|
62
|
+
normals[at] = normals[at] / length;
|
|
63
|
+
normals[at + Y] = normals[at + Y] / length;
|
|
64
|
+
normals[at + Z] = normals[at + Z] / length;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return Array.from(normals);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Normals that keep sharp edges sharp: around each point, a triangle's corner takes the
|
|
71
|
+
* area-weighted sum of the normals of the triangles around that point that turn from it by less than
|
|
72
|
+
* `minSharpAngle` degrees. Where corners of one point end up with different normals the point is
|
|
73
|
+
* split, so a cube keeps hard edges while a cylinder's side stays smooth. Gives, for each point made,
|
|
74
|
+
* the point it was made from, its normal, and the triangles over the points made; points no
|
|
75
|
+
* triangle uses are left out.
|
|
76
|
+
*/
|
|
77
|
+
export const creasedVertices = (positions, indices, minSharpAngle) => {
|
|
99
78
|
const vertexCount = Math.floor(positions.length / COORDINATES);
|
|
100
79
|
const triangleCount = Math.floor(indices.length / CORNERS);
|
|
101
80
|
const weighted = faceNormalsOf(positions, indices);
|
|
@@ -104,8 +83,8 @@ export const creasedMesh = (positions, indices, minSharpAngle) => {
|
|
|
104
83
|
lengths[face] = Math.hypot(weighted[face * COORDINATES], weighted[face * COORDINATES + Y], weighted[face * COORDINATES + Z]);
|
|
105
84
|
}
|
|
106
85
|
const [starts, faces] = facesAround(indices, vertexCount);
|
|
107
|
-
const cosine = Math.cos(minSharpAngle
|
|
108
|
-
const
|
|
86
|
+
const cosine = Math.cos(radiansOf(minSharpAngle)) - ANGLE_SLACK;
|
|
87
|
+
const sources = [];
|
|
109
88
|
const outNormals = [];
|
|
110
89
|
const outIndices = new Uint32Array(triangleCount * CORNERS);
|
|
111
90
|
const made = Array.from({ length: vertexCount }, () => []);
|
|
@@ -134,8 +113,8 @@ export const creasedMesh = (positions, indices, minSharpAngle) => {
|
|
|
134
113
|
}
|
|
135
114
|
const reuse = made[vertex].find((index) => outNormals[index * COORDINATES] === nx && outNormals[index * COORDINATES + Y] === ny && outNormals[index * COORDINATES + Z] === nz);
|
|
136
115
|
if (reuse === undefined) {
|
|
137
|
-
const index =
|
|
138
|
-
|
|
116
|
+
const index = sources.length;
|
|
117
|
+
sources.push(vertex);
|
|
139
118
|
outNormals.push(nx, ny, nz);
|
|
140
119
|
made[vertex].push(index);
|
|
141
120
|
outIndices[corner] = index;
|
|
@@ -144,5 +123,15 @@ export const creasedMesh = (positions, indices, minSharpAngle) => {
|
|
|
144
123
|
outIndices[corner] = reuse;
|
|
145
124
|
}
|
|
146
125
|
}
|
|
147
|
-
return {
|
|
126
|
+
return { sources: Uint32Array.from(sources), normals: Float64Array.from(outNormals), indices: outIndices };
|
|
127
|
+
};
|
|
128
|
+
export const creasedMesh = (positions, indices, minSharpAngle) => {
|
|
129
|
+
const creased = creasedVertices(positions, indices, minSharpAngle);
|
|
130
|
+
const outPositions = new Float32Array(creased.sources.length * COORDINATES);
|
|
131
|
+
creased.sources.forEach((vertex, at) => {
|
|
132
|
+
outPositions[at * COORDINATES] = positions[vertex * COORDINATES];
|
|
133
|
+
outPositions[at * COORDINATES + Y] = positions[vertex * COORDINATES + Y];
|
|
134
|
+
outPositions[at * COORDINATES + Z] = positions[vertex * COORDINATES + Z];
|
|
135
|
+
});
|
|
136
|
+
return { positions: outPositions, normals: Float32Array.from(creased.normals), indices: creased.indices };
|
|
148
137
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { WindingComponents } from "../helper-types";
|
|
2
|
+
/**
|
|
3
|
+
* Finds which triangles of a mesh to turn over so that every edge two triangles share is run one way
|
|
4
|
+
* by one and the other way by the other, and which connected piece each triangle belongs to. The
|
|
5
|
+
* first triangle of each piece keeps its winding; an edge shared by more than two triangles is not
|
|
6
|
+
* followed.
|
|
7
|
+
* @param indices - Triangle corners, three per triangle
|
|
8
|
+
* @param start - The first index of the range to read
|
|
9
|
+
* @param end - The index after the range to read
|
|
10
|
+
* @returns For each triangle of the range, whether to turn it over and its piece, and how many pieces there are
|
|
11
|
+
*/
|
|
12
|
+
export declare function windingComponents(indices: ArrayLike<number>, start?: number, end?: number): WindingComponents;
|
|
13
|
+
/**
|
|
14
|
+
* Finds which triangles of a mesh wind against the rest of their connected piece and should be
|
|
15
|
+
* turned over: within each piece, the winding most of its area already has is kept, so a few faces
|
|
16
|
+
* written inside out are mended while a piece wound inward on purpose, such as the inside of a
|
|
17
|
+
* hollow profile, stays as it is.
|
|
18
|
+
* @param positions - Flat `x, y, z` triples
|
|
19
|
+
* @param indices - Triangle corners, three per triangle
|
|
20
|
+
* @param start - The first index of the range to read
|
|
21
|
+
* @param end - The index after the range to read
|
|
22
|
+
* @returns For each triangle of the range, 1 where it should be turned over
|
|
23
|
+
*/
|
|
24
|
+
export declare function windingRepairs(positions: ArrayLike<number>, indices: ArrayLike<number>, start?: number, end?: number): Uint8Array;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const CORNERS = 3;
|
|
2
|
+
function cornerOf(indices, start, triangle, corner) {
|
|
3
|
+
return indices[start + triangle * CORNERS + (corner % CORNERS)];
|
|
4
|
+
}
|
|
5
|
+
function edgeUsesOf(indices, start, triangles) {
|
|
6
|
+
let highest = 0;
|
|
7
|
+
for (let at = start; at < start + triangles * CORNERS; at++) {
|
|
8
|
+
highest = Math.max(highest, indices[at]);
|
|
9
|
+
}
|
|
10
|
+
const stride = highest + 1;
|
|
11
|
+
const uses = new Map();
|
|
12
|
+
for (let triangle = 0; triangle < triangles; triangle++) {
|
|
13
|
+
for (let corner = 0; corner < CORNERS; corner++) {
|
|
14
|
+
const a = cornerOf(indices, start, triangle, corner);
|
|
15
|
+
const b = cornerOf(indices, start, triangle, corner + 1);
|
|
16
|
+
if (a === b) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const key = a < b ? a * stride + b : b * stride + a;
|
|
20
|
+
const known = uses.get(key);
|
|
21
|
+
if (known === undefined) {
|
|
22
|
+
uses.set(key, [triangle * CORNERS + corner]);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
known.push(triangle * CORNERS + corner);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return { uses, stride };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Finds which triangles of a mesh to turn over so that every edge two triangles share is run one way
|
|
33
|
+
* by one and the other way by the other, and which connected piece each triangle belongs to. The
|
|
34
|
+
* first triangle of each piece keeps its winding; an edge shared by more than two triangles is not
|
|
35
|
+
* followed.
|
|
36
|
+
* @param indices - Triangle corners, three per triangle
|
|
37
|
+
* @param start - The first index of the range to read
|
|
38
|
+
* @param end - The index after the range to read
|
|
39
|
+
* @returns For each triangle of the range, whether to turn it over and its piece, and how many pieces there are
|
|
40
|
+
*/
|
|
41
|
+
export function windingComponents(indices, start = 0, end = indices.length) {
|
|
42
|
+
const triangles = Math.max(0, Math.floor((end - start) / CORNERS));
|
|
43
|
+
const flips = new Uint8Array(triangles);
|
|
44
|
+
const component = new Int32Array(triangles).fill(-1);
|
|
45
|
+
const { uses, stride } = edgeUsesOf(indices, start, triangles);
|
|
46
|
+
const queue = new Int32Array(triangles);
|
|
47
|
+
let count = 0;
|
|
48
|
+
for (let seed = 0; seed < triangles; seed++) {
|
|
49
|
+
if (component[seed] >= 0) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
component[seed] = count;
|
|
53
|
+
let head = 0;
|
|
54
|
+
let tail = 0;
|
|
55
|
+
queue[tail++] = seed;
|
|
56
|
+
while (head < tail) {
|
|
57
|
+
const triangle = queue[head++];
|
|
58
|
+
for (let corner = 0; corner < CORNERS; corner++) {
|
|
59
|
+
const a = cornerOf(indices, start, triangle, corner);
|
|
60
|
+
const b = cornerOf(indices, start, triangle, corner + 1);
|
|
61
|
+
const shared = a === b ? undefined : uses.get(a < b ? a * stride + b : b * stride + a);
|
|
62
|
+
const other = (shared === null || shared === void 0 ? void 0 : shared.length) === 2 ? shared.find((use) => Math.floor(use / CORNERS) !== triangle) : undefined;
|
|
63
|
+
if (other === undefined) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const neighbour = Math.floor(other / CORNERS);
|
|
67
|
+
if (component[neighbour] >= 0) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const sameDirection = cornerOf(indices, start, neighbour, other % CORNERS) === a;
|
|
71
|
+
flips[neighbour] = sameDirection ? 1 - flips[triangle] : flips[triangle];
|
|
72
|
+
component[neighbour] = count;
|
|
73
|
+
queue[tail++] = neighbour;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
count++;
|
|
77
|
+
}
|
|
78
|
+
return { flips, component, count };
|
|
79
|
+
}
|
|
80
|
+
function twiceArea(positions, indices, start, triangle) {
|
|
81
|
+
const [a, b, c] = [0, 1, 2].map((corner) => cornerOf(indices, start, triangle, corner) * CORNERS);
|
|
82
|
+
const [ux, uy, uz] = [positions[b] - positions[a], positions[b + 1] - positions[a + 1], positions[b + 2] - positions[a + 2]];
|
|
83
|
+
const [vx, vy, vz] = [positions[c] - positions[a], positions[c + 1] - positions[a + 1], positions[c + 2] - positions[a + 2]];
|
|
84
|
+
return Math.hypot(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Finds which triangles of a mesh wind against the rest of their connected piece and should be
|
|
88
|
+
* turned over: within each piece, the winding most of its area already has is kept, so a few faces
|
|
89
|
+
* written inside out are mended while a piece wound inward on purpose, such as the inside of a
|
|
90
|
+
* hollow profile, stays as it is.
|
|
91
|
+
* @param positions - Flat `x, y, z` triples
|
|
92
|
+
* @param indices - Triangle corners, three per triangle
|
|
93
|
+
* @param start - The first index of the range to read
|
|
94
|
+
* @param end - The index after the range to read
|
|
95
|
+
* @returns For each triangle of the range, 1 where it should be turned over
|
|
96
|
+
*/
|
|
97
|
+
export function windingRepairs(positions, indices, start = 0, end = indices.length) {
|
|
98
|
+
const { flips, component, count } = windingComponents(indices, start, end);
|
|
99
|
+
const balance = new Float64Array(count);
|
|
100
|
+
flips.forEach((flip, triangle) => {
|
|
101
|
+
balance[component[triangle]] += flip === 1 ? -twiceArea(positions, indices, start, triangle) : twiceArea(positions, indices, start, triangle);
|
|
102
|
+
});
|
|
103
|
+
return flips.map((flip, triangle) => (balance[component[triangle]] < 0 ? 1 - flip : flip));
|
|
104
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { MeshArrays } from "
|
|
1
|
+
import type { MeshArrays } from "../helper-types";
|
|
2
2
|
export declare const icosphere: (detail: number) => MeshArrays;
|
|
3
3
|
export declare const frustum: (sides: number, bottomRadius: number, topRadius: number, height: number) => MeshArrays;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { unitOf } from "../geometry/frame-axes";
|
|
2
|
+
import { between3, polar2 } from "../geometry/vectors";
|
|
1
3
|
import { ICOSAHEDRON_FACES, ICOSAHEDRON_POINTS } from "./mesh-primitives.constants";
|
|
2
|
-
function onUnitSphere(
|
|
3
|
-
|
|
4
|
-
return [x / length, y / length, z / length];
|
|
4
|
+
function onUnitSphere(point) {
|
|
5
|
+
return unitOf([point[0], point[1], point[2]]);
|
|
5
6
|
}
|
|
6
7
|
export const icosphere = (detail) => {
|
|
7
8
|
const points = ICOSAHEDRON_POINTS.map(onUnitSphere);
|
|
@@ -13,7 +14,7 @@ export const icosphere = (detail) => {
|
|
|
13
14
|
let index = middles.get(key);
|
|
14
15
|
if (index === undefined) {
|
|
15
16
|
const [p, q] = [points[a], points[b]];
|
|
16
|
-
index = points.push(onUnitSphere(
|
|
17
|
+
index = points.push(onUnitSphere(between3(p, q, 1 / 2))) - 1;
|
|
17
18
|
middles.set(key, index);
|
|
18
19
|
}
|
|
19
20
|
return index;
|
|
@@ -30,7 +31,7 @@ export const frustum = (sides, bottomRadius, topRadius, height) => {
|
|
|
30
31
|
for (const [radius, z] of [[bottomRadius, 0], [topRadius, height]]) {
|
|
31
32
|
for (let side = 0; side < sides; side++) {
|
|
32
33
|
const angle = side / sides * 2 * Math.PI;
|
|
33
|
-
positions.push(radius
|
|
34
|
+
positions.push(...polar2(radius, angle), z);
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
const bottom = (side) => 2 + side % sides;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const LEAF_TRIANGLES = 8;
|
|
2
|
+
export declare const RAY_DIRECTIONS: readonly (readonly [number, number, number])[];
|
|
3
|
+
export declare const PARALLEL = 1e-12;
|
|
4
|
+
export declare const POINT_SHARE = 1e-12;
|
|
5
|
+
export declare const FLAT_SHARE = 1e-28;
|
|
6
|
+
export declare const WELD_SHARE = 1e-9;
|
|
7
|
+
export declare const PRUNE_SLACK: number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const LEAF_TRIANGLES = 8;
|
|
2
|
+
export const RAY_DIRECTIONS = [
|
|
3
|
+
[0.5773, 0.5779, 0.5767],
|
|
4
|
+
[-0.6123, 0.7071, 0.3536],
|
|
5
|
+
[0.2673, -0.5345, 0.8018],
|
|
6
|
+
];
|
|
7
|
+
export const PARALLEL = 1e-12;
|
|
8
|
+
export const POINT_SHARE = 1e-12;
|
|
9
|
+
export const FLAT_SHARE = 1e-28;
|
|
10
|
+
export const WELD_SHARE = 1e-9;
|
|
11
|
+
export const PRUNE_SLACK = 8 * Number.EPSILON;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as Inputs from "../../../inputs";
|
|
2
|
+
import type { TreeBox, TriangleTree } from "../helper-types";
|
|
3
|
+
type Vec = Inputs.Base.Point3;
|
|
4
|
+
export declare function triangleTree(positions: ArrayLike<number>, indices: ArrayLike<number>): TriangleTree;
|
|
5
|
+
export declare function treesWithin(first: TriangleTree, second: TriangleTree, limit: number): boolean;
|
|
6
|
+
export declare function pointInTree(tree: TriangleTree, point: Vec): boolean;
|
|
7
|
+
export declare function pointOnTree(tree: TriangleTree): Vec | undefined;
|
|
8
|
+
export declare function treesNested(first: TriangleTree, second: TriangleTree): boolean;
|
|
9
|
+
export declare function pointsOnTree(tree: TriangleTree, most: number): Vec[];
|
|
10
|
+
export declare function treeBox(tree: TriangleTree): TreeBox | undefined;
|
|
11
|
+
export {};
|