three-hilbert-geometry 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 +21 -0
- package/README.md +59 -2
- package/dist/three-hilbert-geometry.d.ts +15 -0
- package/dist/three-hilbert-geometry.js +434 -0
- package/dist/three-hilbert-geometry.js.map +1 -0
- package/dist/three-hilbert-geometry.min.js +2 -0
- package/dist/three-hilbert-geometry.mjs +426 -0
- package/package.json +61 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vasco Asturiano
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
ThreeJS Hilbert Geometry
|
|
2
|
+
==============
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
[![NPM package][npm-img]][npm-url]
|
|
5
|
+
[![Build Size][build-size-img]][build-size-url]
|
|
6
|
+
[![NPM Downloads][npm-downloads-img]][npm-downloads-url]
|
|
7
|
+
|
|
8
|
+
A Three.js geometry for constructing a square-tube Hilbert curve with a recursive 3D path.
|
|
9
|
+
|
|
10
|
+
## Quick start
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
import HilbertGeometry from 'three-hilbert-geometry';
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
or using a script tag:
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<script src="//unpkg.com/three-hilbert-geometry"></script>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
then
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
const myMesh = new THREE.Mesh(
|
|
26
|
+
new HilbertGeometry(5, 0, 128),
|
|
27
|
+
new THREE.MeshBasicMaterial({ color: 'blue' })
|
|
28
|
+
);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Why this geometry?
|
|
32
|
+
|
|
33
|
+
The Hilbert curve is a space-filling path that preserves locality: adjacent points in the curve stay close in 3D space. This makes it useful for:
|
|
34
|
+
|
|
35
|
+
* Visualizing recursive structures and fractal ordering
|
|
36
|
+
* Building dense, ordered paths in 3D scenes
|
|
37
|
+
* Generating procedural line-like geometry with a compact footprint
|
|
38
|
+
* Creating animated or data-driven spatial layouts
|
|
39
|
+
|
|
40
|
+
## API reference
|
|
41
|
+
|
|
42
|
+
### Constructor
|
|
43
|
+
|
|
44
|
+
<b>HilbertGeometry</b>(<b>order</b>: <i>Integer</i>, <b>start</b>: <i>Number | BigInt</i>, <b>length</b>: <i>Number | BigInt</i>, <b>options</b>: <i>Object</i>)
|
|
45
|
+
|
|
46
|
+
Creates a square-tubed Hilbert curve segment. The geometry is built from a recursive 3D Hilbert path and then expanded into a thickened square tube.
|
|
47
|
+
|
|
48
|
+
* <b>order</b>: Recursion depth of the Hilbert curve. Higher values create finer, more detailed curves.
|
|
49
|
+
* <b>start</b>: Index of the first point to generate. Accepts a number or bigint for large ranges.
|
|
50
|
+
* <b>length</b>: Number of curve points to include. Also accepts a number or bigint.
|
|
51
|
+
* <b>options</b>: Optional settings object.
|
|
52
|
+
* <b>padding</b>: Fractional relative padding between of the tube. Value is in the range `[0, 1)`. Default is `0`.
|
|
53
|
+
* <b>simplifyCurves</b>: If `true`, the curve is simplified by reducing the order whenever possible when both `start` and `length` are divisible by 8. Default is `true`.
|
|
54
|
+
|
|
55
|
+
[npm-img]: https://img.shields.io/npm/v/three-hilbert-geometry
|
|
56
|
+
[npm-url]: https://npmjs.org/package/three-hilbert-geometry
|
|
57
|
+
[build-size-img]: https://img.shields.io/bundlephobia/minzip/three-hilbert-geometry
|
|
58
|
+
[build-size-url]: https://bundlephobia.com/result?p=three-hilbert-geometry
|
|
59
|
+
[npm-downloads-img]: https://img.shields.io/npm/dt/three-hilbert-geometry
|
|
60
|
+
[npm-downloads-url]: https://www.npmtrends.com/three-hilbert-geometry
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BufferGeometry } from 'three';
|
|
2
|
+
|
|
3
|
+
declare class HilbertGeometry extends BufferGeometry {
|
|
4
|
+
constructor(
|
|
5
|
+
order: number,
|
|
6
|
+
start: number | bigint,
|
|
7
|
+
length: number | bigint,
|
|
8
|
+
optionalArgs?: {
|
|
9
|
+
padding?: number,
|
|
10
|
+
simplifyCurves?: boolean
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { HilbertGeometry as default };
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
// Version 1.0.0 three-hilbert-geometry - https://github.com/vasturiano/three-hilbert-geometry
|
|
2
|
+
(function (global, factory) {
|
|
3
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('three')) :
|
|
4
|
+
typeof define === 'function' && define.amd ? define(['three'], factory) :
|
|
5
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.HilbertGeometry = factory(global.THREE));
|
|
6
|
+
})(this, (function (three) { 'use strict';
|
|
7
|
+
|
|
8
|
+
const CHILD_PERMUTATIONS = [[0, 3, 4, 7, 6, 5, 2, 1], [0, 7, 6, 1, 2, 5, 4, 3], [0, 7, 6, 1, 2, 5, 4, 3], [2, 3, 0, 1, 6, 7, 4, 5], [2, 3, 0, 1, 6, 7, 4, 5], [4, 3, 2, 5, 6, 1, 0, 7], [4, 3, 2, 5, 6, 1, 0, 7], [6, 5, 2, 1, 0, 3, 4, 7]];
|
|
9
|
+
const ORIENTATIONS = [[0, 1, 2, 3, 4, 5, 6, 7]];
|
|
10
|
+
const ORIENTATION_TRANSITIONS = [];
|
|
11
|
+
const ORIENTATION_IDS = new Map([[ORIENTATIONS[0].join(''), 0]]);
|
|
12
|
+
for (let i = 0; i < ORIENTATIONS.length; i++) {
|
|
13
|
+
const orientation = ORIENTATIONS[i];
|
|
14
|
+
const transitions = [];
|
|
15
|
+
for (const permutation of CHILD_PERMUTATIONS) {
|
|
16
|
+
const childOrientation = permutation.map(index => orientation[index]);
|
|
17
|
+
const key = childOrientation.join('');
|
|
18
|
+
let id = ORIENTATION_IDS.get(key);
|
|
19
|
+
if (id === undefined) {
|
|
20
|
+
id = ORIENTATIONS.length;
|
|
21
|
+
ORIENTATIONS.push(childOrientation);
|
|
22
|
+
ORIENTATION_IDS.set(key, id);
|
|
23
|
+
}
|
|
24
|
+
transitions.push(id);
|
|
25
|
+
}
|
|
26
|
+
ORIENTATION_TRANSITIONS.push(transitions);
|
|
27
|
+
}
|
|
28
|
+
const BIGINT_CHILD_INDEXES = [0n, 1n, 2n, 3n, 4n, 5n, 6n, 7n];
|
|
29
|
+
const ZERO_CENTER = new three.Vector3(0, 0, 0);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Generates a portion of the 3D Hilbert curve.
|
|
33
|
+
*
|
|
34
|
+
* @param {Vector3} [center] - Center of Hilbert curve.
|
|
35
|
+
* @param {number} [size=10] - Total width of Hilbert curve.
|
|
36
|
+
* @param {number} [order=1] - Number of subdivisions.
|
|
37
|
+
* @param {number|bigint} [start=0] - Index of the first point to generate.
|
|
38
|
+
* @param {number|bigint} [length] - Number of points to generate.
|
|
39
|
+
* @param {number} [v0=0] - Corner index -X, +Y, -Z.
|
|
40
|
+
* @param {number} [v1=1] - Corner index -X, +Y, +Z.
|
|
41
|
+
* @param {number} [v2=2] - Corner index -X, -Y, +Z.
|
|
42
|
+
* @param {number} [v3=3] - Corner index -X, -Y, -Z.
|
|
43
|
+
* @param {number} [v4=4] - Corner index +X, -Y, -Z.
|
|
44
|
+
* @param {number} [v5=5] - Corner index +X, -Y, +Z.
|
|
45
|
+
* @param {number} [v6=6] - Corner index +X, +Y, +Z.
|
|
46
|
+
* @param {number} [v7=7] - Corner index +X, +Y, -Z.
|
|
47
|
+
* @returns {Array<Vector3>} The requested Hilbert curve points.
|
|
48
|
+
*/
|
|
49
|
+
function hilbert3D(center = ZERO_CENTER, size = 10, order = 1, start = 0, length, v0 = 0, v1 = 1, v2 = 2, v3 = 3, v4 = 4, v5 = 5, v6 = 6, v7 = 7) {
|
|
50
|
+
if (order < 0) return [new three.Vector3(0, 0, 0)];
|
|
51
|
+
if (!Number.isInteger(order)) throw new TypeError('Order must be an integer.');
|
|
52
|
+
const points = [];
|
|
53
|
+
if (typeof start === 'bigint' || typeof length === 'bigint') {
|
|
54
|
+
const first = toBigInt(start);
|
|
55
|
+
const count = 8n ** BigInt(order + 1);
|
|
56
|
+
const requestedLength = length === undefined ? count : toBigInt(length);
|
|
57
|
+
const rangeStart = first < 0n ? 0n : first;
|
|
58
|
+
const requestedEnd = rangeStart + (requestedLength > 0n ? requestedLength : 0n);
|
|
59
|
+
const rangeEnd = requestedEnd > count ? count : requestedEnd;
|
|
60
|
+
if (rangeStart >= rangeEnd) return points;
|
|
61
|
+
const baseCorners = [v0, v1, v2, v3, v4, v5, v6, v7];
|
|
62
|
+
if (rangeEnd - rangeStart === 1n) {
|
|
63
|
+
generateSingleBigInt(points, center.x, center.y, center.z, size, order, rangeStart, BigInt(order * 3), 0, baseCorners);
|
|
64
|
+
return points;
|
|
65
|
+
}
|
|
66
|
+
generateBigInt(points, center.x, center.y, center.z, size, order, 0n, count / 8n, 0, rangeStart, rangeEnd, baseCorners);
|
|
67
|
+
return points;
|
|
68
|
+
}
|
|
69
|
+
const pointCount = 8 ** (order + 1);
|
|
70
|
+
const rawStart = Math.floor(start);
|
|
71
|
+
const first = Math.max(0, rawStart);
|
|
72
|
+
const requestedLength = length === undefined ? pointCount : Math.max(0, Math.floor(length));
|
|
73
|
+
const end = Math.min(pointCount, first + requestedLength);
|
|
74
|
+
if (first >= end) return points;
|
|
75
|
+
const baseCorners = [v0, v1, v2, v3, v4, v5, v6, v7];
|
|
76
|
+
generateNumber(points, center.x, center.y, center.z, size, order, 0, pointCount / 8, 0, first, end, baseCorners);
|
|
77
|
+
return points;
|
|
78
|
+
}
|
|
79
|
+
function generateNumber(points, x, y, z, size, order, offset, chunkSize, orientationId, first, end, baseCorners) {
|
|
80
|
+
const orientation = ORIENTATIONS[orientationId];
|
|
81
|
+
const transitions = ORIENTATION_TRANSITIONS[orientationId];
|
|
82
|
+
const half = size / 2;
|
|
83
|
+
for (let i = 0; i < 8; i++) {
|
|
84
|
+
const childOffset = offset + i * chunkSize;
|
|
85
|
+
const childEnd = childOffset + chunkSize;
|
|
86
|
+
if (childEnd <= first || childOffset >= end) continue;
|
|
87
|
+
const actualCorner = baseCorners[orientation[i]];
|
|
88
|
+
const childX = x + (actualCorner < 4 ? -half : half);
|
|
89
|
+
const childY = y + (actualCorner < 2 || actualCorner > 5 ? half : -half);
|
|
90
|
+
const childZ = z + (actualCorner % 4 === 1 || actualCorner % 4 === 2 ? half : -half);
|
|
91
|
+
if (order === 0) {
|
|
92
|
+
points.push(new three.Vector3(childX, childY, childZ));
|
|
93
|
+
} else {
|
|
94
|
+
generateNumber(points, childX, childY, childZ, half, order - 1, childOffset, chunkSize / 8, transitions[i], first, end, baseCorners);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function generateBigInt(points, x, y, z, size, order, offset, chunkSize, orientationId, first, end, baseCorners) {
|
|
99
|
+
const orientation = ORIENTATIONS[orientationId];
|
|
100
|
+
const transitions = ORIENTATION_TRANSITIONS[orientationId];
|
|
101
|
+
const half = size / 2;
|
|
102
|
+
const childChunkSize = chunkSize / 8n;
|
|
103
|
+
const nodeEnd = offset + chunkSize * 8n;
|
|
104
|
+
const firstChild = first <= offset ? 0 : Number((first - offset) / chunkSize);
|
|
105
|
+
const lastChild = end >= nodeEnd ? 7 : Number((end - 1n - offset) / chunkSize);
|
|
106
|
+
let childOffset = offset + BIGINT_CHILD_INDEXES[firstChild] * chunkSize;
|
|
107
|
+
for (let i = firstChild; i <= lastChild; i++, childOffset += chunkSize) {
|
|
108
|
+
const actualCorner = baseCorners[orientation[i]];
|
|
109
|
+
const childX = x + (actualCorner < 4 ? -half : half);
|
|
110
|
+
const childY = y + (actualCorner < 2 || actualCorner > 5 ? half : -half);
|
|
111
|
+
const childZ = z + (actualCorner % 4 === 1 || actualCorner % 4 === 2 ? half : -half);
|
|
112
|
+
if (order === 0) {
|
|
113
|
+
points.push(new three.Vector3(childX, childY, childZ));
|
|
114
|
+
} else {
|
|
115
|
+
generateBigInt(points, childX, childY, childZ, half, order - 1, childOffset, childChunkSize, transitions[i], first, end, baseCorners);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function generateSingleBigInt(points, x, y, z, size, order, index, shift, orientationId, baseCorners) {
|
|
120
|
+
const orientation = ORIENTATIONS[orientationId];
|
|
121
|
+
const child = Number(index >> shift & 7n);
|
|
122
|
+
const actualCorner = baseCorners[orientation[child]];
|
|
123
|
+
const half = size / 2;
|
|
124
|
+
const childX = x + (actualCorner < 4 ? -half : half);
|
|
125
|
+
const childY = y + (actualCorner < 2 || actualCorner > 5 ? half : -half);
|
|
126
|
+
const childZ = z + (actualCorner % 4 === 1 || actualCorner % 4 === 2 ? half : -half);
|
|
127
|
+
if (order === 0) {
|
|
128
|
+
points.push(new three.Vector3(childX, childY, childZ));
|
|
129
|
+
} else {
|
|
130
|
+
generateSingleBigInt(points, childX, childY, childZ, half, order - 1, index, shift - 3n, ORIENTATION_TRANSITIONS[orientationId][child], baseCorners);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function toBigInt(value) {
|
|
134
|
+
if (typeof value === 'bigint') return value;
|
|
135
|
+
if (!Number.isSafeInteger(value)) throw new TypeError('BigInt ranges require integer values.');
|
|
136
|
+
return BigInt(value);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const SINGLE_CUBE_FACES = [[0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7], [0, 3, 2, 1], [4, 5, 6, 7]];
|
|
140
|
+
const SINGLE_CUBE_CORNERS = [[-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1], [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]];
|
|
141
|
+
const SINGLE_CUBE_UVS = new Float32Array(24 * 2);
|
|
142
|
+
const SINGLE_CUBE_NORMALS = new Float32Array(24 * 3);
|
|
143
|
+
const SINGLE_CUBE_INDICES = new Uint16Array(36);
|
|
144
|
+
const SINGLE_CUBE_NORMALS_BY_FACE = [[0, -1, 0], [1, 0, 0], [0, 1, 0], [-1, 0, 0], [0, 0, -1], [0, 0, 1]];
|
|
145
|
+
for (let faceIndex = 0; faceIndex < SINGLE_CUBE_FACES.length; faceIndex++) {
|
|
146
|
+
const face = SINGLE_CUBE_FACES[faceIndex];
|
|
147
|
+
const normal = SINGLE_CUBE_NORMALS_BY_FACE[faceIndex];
|
|
148
|
+
for (let i = 0; i < 4; i++) {
|
|
149
|
+
const vertex = faceIndex * 4 + i;
|
|
150
|
+
const corner = face[i];
|
|
151
|
+
SINGLE_CUBE_UVS[vertex * 2] = corner % 2;
|
|
152
|
+
SINGLE_CUBE_UVS[vertex * 2 + 1] = Math.floor(corner / 2) % 2;
|
|
153
|
+
SINGLE_CUBE_NORMALS.set(normal, vertex * 3);
|
|
154
|
+
}
|
|
155
|
+
const vertexOffset = faceIndex * 4;
|
|
156
|
+
const indexOffset = faceIndex * 6;
|
|
157
|
+
SINGLE_CUBE_INDICES.set([vertexOffset, vertexOffset + 1, vertexOffset + 2, vertexOffset, vertexOffset + 2, vertexOffset + 3], indexOffset);
|
|
158
|
+
}
|
|
159
|
+
class SquareTubeGeometry extends three.BufferGeometry {
|
|
160
|
+
constructor(points = [], width = 1) {
|
|
161
|
+
super();
|
|
162
|
+
if (!Array.isArray(points)) {
|
|
163
|
+
throw new TypeError('points must be an array of Vector3 instances');
|
|
164
|
+
}
|
|
165
|
+
if (!Number.isFinite(width) || width < 0) {
|
|
166
|
+
throw new RangeError('width must be a non-negative finite number');
|
|
167
|
+
}
|
|
168
|
+
this.type = 'SquareTubeGeometry';
|
|
169
|
+
if (points.length <= 1) {
|
|
170
|
+
const point = points[0];
|
|
171
|
+
if (points.length === 1 && (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z))) {
|
|
172
|
+
throw new TypeError('points[0] must have finite x, y, and z coordinates');
|
|
173
|
+
}
|
|
174
|
+
this.parameters = {
|
|
175
|
+
points: point ? [new three.Vector3(point.x, point.y, point.z)] : [],
|
|
176
|
+
width
|
|
177
|
+
};
|
|
178
|
+
if (!point || width === 0) {
|
|
179
|
+
this.setIndex([]);
|
|
180
|
+
this.setAttribute('position', new three.Float32BufferAttribute([], 3));
|
|
181
|
+
this.setAttribute('uv', new three.Float32BufferAttribute([], 2));
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const halfWidth = width / 2;
|
|
185
|
+
const x = point.x;
|
|
186
|
+
const y = point.y;
|
|
187
|
+
const z = point.z;
|
|
188
|
+
const positions = new Float32Array(24 * 3);
|
|
189
|
+
let positionOffset = 0;
|
|
190
|
+
for (const face of SINGLE_CUBE_FACES) {
|
|
191
|
+
for (const corner of face) {
|
|
192
|
+
const signs = SINGLE_CUBE_CORNERS[corner];
|
|
193
|
+
positions[positionOffset++] = x + signs[0] * halfWidth;
|
|
194
|
+
positions[positionOffset++] = y + signs[1] * halfWidth;
|
|
195
|
+
positions[positionOffset++] = z + signs[2] * halfWidth;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
this.setIndex(new three.Uint16BufferAttribute(SINGLE_CUBE_INDICES.slice(), 1));
|
|
199
|
+
this.setAttribute('position', new three.Float32BufferAttribute(positions, 3));
|
|
200
|
+
this.setAttribute('uv', new three.Float32BufferAttribute(SINGLE_CUBE_UVS.slice(), 2));
|
|
201
|
+
this.setAttribute('normal', new three.Float32BufferAttribute(SINGLE_CUBE_NORMALS.slice(), 3));
|
|
202
|
+
this.boundingBox = new three.Box3(new three.Vector3(x - halfWidth, y - halfWidth, z - halfWidth), new three.Vector3(x + halfWidth, y + halfWidth, z + halfWidth));
|
|
203
|
+
this.boundingSphere = new three.Sphere(new three.Vector3(x, y, z), Math.sqrt(3) * halfWidth);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const path = points.map((point, index) => {
|
|
207
|
+
if (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z)) {
|
|
208
|
+
throw new TypeError(`points[${index}] must have finite x, y, and z coordinates`);
|
|
209
|
+
}
|
|
210
|
+
return new three.Vector3(point.x, point.y, point.z);
|
|
211
|
+
}).filter((point, index, list) => index === 0 || point.distanceToSquared(list[index - 1]) > 0);
|
|
212
|
+
this.parameters = {
|
|
213
|
+
points: path.map(point => point.clone()),
|
|
214
|
+
width
|
|
215
|
+
};
|
|
216
|
+
if (path.length === 0 || width === 0) {
|
|
217
|
+
this.setIndex([]);
|
|
218
|
+
this.setAttribute('position', new three.Float32BufferAttribute([], 3));
|
|
219
|
+
this.setAttribute('uv', new three.Float32BufferAttribute([], 2));
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const directions = path.slice(1).map((point, index) => point.clone().sub(path[index]).normalize());
|
|
223
|
+
const turnTolerance = 1e-6;
|
|
224
|
+
let turnCount = 0;
|
|
225
|
+
for (let i = 1; i < directions.length; i++) {
|
|
226
|
+
const dot = directions[i - 1].dot(directions[i]);
|
|
227
|
+
const isRightAngle = Math.abs(dot) <= turnTolerance;
|
|
228
|
+
const continuesStraight = dot >= 1 - turnTolerance;
|
|
229
|
+
if (!isRightAngle && !continuesStraight) {
|
|
230
|
+
throw new RangeError('path turns must be 90 degrees; straight segments are also allowed');
|
|
231
|
+
}
|
|
232
|
+
if (isRightAngle) turnCount++;
|
|
233
|
+
}
|
|
234
|
+
const halfWidth = width / 2;
|
|
235
|
+
const frames = [];
|
|
236
|
+
const normal = new three.Vector3();
|
|
237
|
+
const binormal = new three.Vector3();
|
|
238
|
+
const rotation = new three.Quaternion();
|
|
239
|
+
for (let i = 0; i < directions.length; i++) {
|
|
240
|
+
if (i === 0) {
|
|
241
|
+
const tangent = directions[i];
|
|
242
|
+
const absX = Math.abs(tangent.x);
|
|
243
|
+
const absY = Math.abs(tangent.y);
|
|
244
|
+
const absZ = Math.abs(tangent.z);
|
|
245
|
+
normal.set(absX <= absY && absX <= absZ ? 1 : 0, absY < absX && absY <= absZ ? 1 : 0, absZ < absX && absZ < absY ? 1 : 0);
|
|
246
|
+
normal.addScaledVector(tangent, -normal.dot(tangent)).normalize();
|
|
247
|
+
} else {
|
|
248
|
+
rotation.setFromUnitVectors(directions[i - 1], directions[i]);
|
|
249
|
+
normal.applyQuaternion(rotation);
|
|
250
|
+
normal.addScaledVector(directions[i], -normal.dot(directions[i])).normalize();
|
|
251
|
+
}
|
|
252
|
+
binormal.crossVectors(directions[i], normal).normalize();
|
|
253
|
+
frames.push({
|
|
254
|
+
normal: normal.clone(),
|
|
255
|
+
binormal: binormal.clone()
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
const faces = [[0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7], [0, 3, 2, 1], [4, 5, 6, 7]];
|
|
259
|
+
const solidCount = path.length === 1 ? 1 : directions.length + turnCount;
|
|
260
|
+
const positions = new Float32Array(solidCount * 24 * 3);
|
|
261
|
+
const uvs = new Float32Array(solidCount * 24 * 2);
|
|
262
|
+
const use32BitIndices = solidCount * 24 > 65535;
|
|
263
|
+
const IndexAttribute = use32BitIndices ? three.Uint32BufferAttribute : three.Uint16BufferAttribute;
|
|
264
|
+
const indices = use32BitIndices ? new Uint32Array(solidCount * 36) : new Uint16Array(solidCount * 36);
|
|
265
|
+
let positionOffset = 0;
|
|
266
|
+
let uvOffset = 0;
|
|
267
|
+
let vertexOffset = 0;
|
|
268
|
+
let indexOffset = 0;
|
|
269
|
+
function addSolid(corners) {
|
|
270
|
+
for (const face of faces) {
|
|
271
|
+
for (const cornerIndex of face) {
|
|
272
|
+
const point = corners[cornerIndex];
|
|
273
|
+
positions[positionOffset++] = point.x;
|
|
274
|
+
positions[positionOffset++] = point.y;
|
|
275
|
+
positions[positionOffset++] = point.z;
|
|
276
|
+
uvs[uvOffset++] = cornerIndex % 2;
|
|
277
|
+
uvs[uvOffset++] = Math.floor(cornerIndex / 2) % 2;
|
|
278
|
+
}
|
|
279
|
+
indices[indexOffset++] = vertexOffset;
|
|
280
|
+
indices[indexOffset++] = vertexOffset + 1;
|
|
281
|
+
indices[indexOffset++] = vertexOffset + 2;
|
|
282
|
+
indices[indexOffset++] = vertexOffset;
|
|
283
|
+
indices[indexOffset++] = vertexOffset + 2;
|
|
284
|
+
indices[indexOffset++] = vertexOffset + 3;
|
|
285
|
+
vertexOffset += 4;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (path.length === 1) {
|
|
289
|
+
const [x, y, z] = path[0].toArray();
|
|
290
|
+
addSolid([new three.Vector3(x - halfWidth, y - halfWidth, z - halfWidth), new three.Vector3(x + halfWidth, y - halfWidth, z - halfWidth), new three.Vector3(x + halfWidth, y + halfWidth, z - halfWidth), new three.Vector3(x - halfWidth, y + halfWidth, z - halfWidth), new three.Vector3(x - halfWidth, y - halfWidth, z + halfWidth), new three.Vector3(x + halfWidth, y - halfWidth, z + halfWidth), new three.Vector3(x + halfWidth, y + halfWidth, z + halfWidth), new three.Vector3(x - halfWidth, y + halfWidth, z + halfWidth)]);
|
|
291
|
+
this.setIndex(new IndexAttribute(indices, 1));
|
|
292
|
+
this.setAttribute('position', new three.Float32BufferAttribute(positions, 3));
|
|
293
|
+
this.setAttribute('uv', new three.Float32BufferAttribute(uvs, 2));
|
|
294
|
+
this.computeVertexNormals();
|
|
295
|
+
this.computeBoundingBox();
|
|
296
|
+
this.computeBoundingSphere();
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
for (let i = 0; i < directions.length; i++) {
|
|
300
|
+
const direction = directions[i];
|
|
301
|
+
const start = path[i].clone();
|
|
302
|
+
const end = path[i + 1].clone();
|
|
303
|
+
if (i === 0) start.addScaledVector(direction, -halfWidth);
|
|
304
|
+
if (i === directions.length - 1) end.addScaledVector(direction, halfWidth);
|
|
305
|
+
const sectionCorners = center => [center.clone().addScaledVector(frames[i].normal, halfWidth).addScaledVector(frames[i].binormal, halfWidth), center.clone().addScaledVector(frames[i].normal, -halfWidth).addScaledVector(frames[i].binormal, halfWidth), center.clone().addScaledVector(frames[i].normal, -halfWidth).addScaledVector(frames[i].binormal, -halfWidth), center.clone().addScaledVector(frames[i].normal, halfWidth).addScaledVector(frames[i].binormal, -halfWidth)];
|
|
306
|
+
addSolid([...sectionCorners(start), ...sectionCorners(end)]);
|
|
307
|
+
}
|
|
308
|
+
for (let i = 1; i < path.length - 1; i++) {
|
|
309
|
+
if (Math.abs(directions[i - 1].dot(directions[i])) <= turnTolerance) {
|
|
310
|
+
const [x, y, z] = path[i].toArray();
|
|
311
|
+
addSolid([new three.Vector3(x - halfWidth, y - halfWidth, z - halfWidth), new three.Vector3(x + halfWidth, y - halfWidth, z - halfWidth), new three.Vector3(x + halfWidth, y + halfWidth, z - halfWidth), new three.Vector3(x - halfWidth, y + halfWidth, z - halfWidth), new three.Vector3(x - halfWidth, y - halfWidth, z + halfWidth), new three.Vector3(x + halfWidth, y - halfWidth, z + halfWidth), new three.Vector3(x + halfWidth, y + halfWidth, z + halfWidth), new three.Vector3(x - halfWidth, y + halfWidth, z + halfWidth)]);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
this.setIndex(new IndexAttribute(indices, 1));
|
|
315
|
+
this.setAttribute('position', new three.Float32BufferAttribute(positions, 3));
|
|
316
|
+
this.setAttribute('uv', new three.Float32BufferAttribute(uvs, 2));
|
|
317
|
+
this.computeVertexNormals();
|
|
318
|
+
this.computeBoundingBox();
|
|
319
|
+
this.computeBoundingSphere();
|
|
320
|
+
}
|
|
321
|
+
copy(source) {
|
|
322
|
+
super.copy(source);
|
|
323
|
+
this.parameters = {
|
|
324
|
+
points: source.parameters.points.map(point => point.clone()),
|
|
325
|
+
width: source.parameters.width
|
|
326
|
+
};
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
class ThreeHilbertGeometry extends SquareTubeGeometry {
|
|
332
|
+
constructor(order, start, length, {
|
|
333
|
+
padding = 0,
|
|
334
|
+
simplifyCurves = true
|
|
335
|
+
} = {}) {
|
|
336
|
+
super(...getSuperParams());
|
|
337
|
+
this.type = 'HilbertGeometry';
|
|
338
|
+
function getSuperParams() {
|
|
339
|
+
typeof start !== 'bigint' && (start = Math.round(start));
|
|
340
|
+
typeof length !== 'bigint' && (length = Math.round(length));
|
|
341
|
+
if (simplifyCurves) {
|
|
342
|
+
// resolution simplification
|
|
343
|
+
const n8 = typeof start === 'bigint' ? 8n : 8;
|
|
344
|
+
while (!(start % n8) && !(length % n8) && order > 0) {
|
|
345
|
+
start /= n8;
|
|
346
|
+
length /= n8;
|
|
347
|
+
order -= 1;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const points = hilbert3D(undefined, 1, order - 1, start, length);
|
|
351
|
+
const lineWidth = 1 / 2 ** (order - 1) * (1 - Math.min(1, padding));
|
|
352
|
+
return [points, lineWidth];
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/*
|
|
358
|
+
const geometryCache = (() => {
|
|
359
|
+
const cache = {};
|
|
360
|
+
cache[''] = new SquareTubeGeometry([new Vector3()]);
|
|
361
|
+
for (const nPnts of [2, 4]) {
|
|
362
|
+
for (let start = 0; start < 8; start++) {
|
|
363
|
+
const pnts = hilbert3D(undefined, 1, 0, start, nPnts);
|
|
364
|
+
const key = getCurvePath(pnts);
|
|
365
|
+
cache[key] = new SquareTubeGeometry(pnts);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return cache;
|
|
369
|
+
})();
|
|
370
|
+
|
|
371
|
+
// console.log(geometryCache);
|
|
372
|
+
|
|
373
|
+
function genInstancedGeometry(order, start, length, {
|
|
374
|
+
padding = 0,
|
|
375
|
+
simplifyCurves
|
|
376
|
+
} = {}) {
|
|
377
|
+
// resolution simplification
|
|
378
|
+
const n8 = typeof start === 'bigint' ? 8n : 8;
|
|
379
|
+
while (!(start % n8) && !(length % n8) && order > 0) {
|
|
380
|
+
start /= n8;
|
|
381
|
+
length /= n8;
|
|
382
|
+
order -= 1;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const points = hilbert3D(undefined, 1, order - 1, start, length);
|
|
386
|
+
|
|
387
|
+
let geometry;
|
|
388
|
+
let position = new Vector3();
|
|
389
|
+
let scale = 1;
|
|
390
|
+
|
|
391
|
+
if ([1, 2, 4].some(l => l === points.length)) {
|
|
392
|
+
// Most common simple cases
|
|
393
|
+
const key = getCurvePath(points);
|
|
394
|
+
geometry = geometryCache[key];
|
|
395
|
+
} else {
|
|
396
|
+
// More complex cases, fallback to regular geometry generation
|
|
397
|
+
geometry = new ThreeHilbertGeometry(order, start, length, { padding, simplifyCurves });
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
return {
|
|
401
|
+
geometry,
|
|
402
|
+
position,
|
|
403
|
+
scale,
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function getCurvePath(points) {
|
|
408
|
+
const path = [];
|
|
409
|
+
let prevPnt = points[0];
|
|
410
|
+
|
|
411
|
+
for (let i = 1; i < points.length; i++) {
|
|
412
|
+
const pnt = points[i];
|
|
413
|
+
for (const c of ['x', 'y', 'z']) {
|
|
414
|
+
const dist = pnt[c] - prevPnt[c];
|
|
415
|
+
if (dist) {
|
|
416
|
+
path.push(
|
|
417
|
+
c === 'x' ? dist > 0 ? 'R' : 'L'
|
|
418
|
+
: c === 'y' ? dist > 0 ? 'U' : 'D'
|
|
419
|
+
: dist > 0 ? 'B' : 'F'
|
|
420
|
+
);
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
prevPnt = pnt;
|
|
425
|
+
}
|
|
426
|
+
return path.join('');
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
*/
|
|
430
|
+
|
|
431
|
+
return ThreeHilbertGeometry;
|
|
432
|
+
|
|
433
|
+
}));
|
|
434
|
+
//# sourceMappingURL=three-hilbert-geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"three-hilbert-geometry.js","sources":["../src/hilbert3d.js","../src/SquareTubeGeometry.js","../src/index.js"],"sourcesContent":["import { Vector3 } from 'three';\n\nconst CHILD_PERMUTATIONS = [\n\t[ 0, 3, 4, 7, 6, 5, 2, 1 ],\n\t[ 0, 7, 6, 1, 2, 5, 4, 3 ],\n\t[ 0, 7, 6, 1, 2, 5, 4, 3 ],\n\t[ 2, 3, 0, 1, 6, 7, 4, 5 ],\n\t[ 2, 3, 0, 1, 6, 7, 4, 5 ],\n\t[ 4, 3, 2, 5, 6, 1, 0, 7 ],\n\t[ 4, 3, 2, 5, 6, 1, 0, 7 ],\n\t[ 6, 5, 2, 1, 0, 3, 4, 7 ]\n];\nconst ORIENTATIONS = [ [ 0, 1, 2, 3, 4, 5, 6, 7 ] ];\nconst ORIENTATION_TRANSITIONS = [];\nconst ORIENTATION_IDS = new Map( [ [ ORIENTATIONS[ 0 ].join( '' ), 0 ] ] );\n\nfor ( let i = 0; i < ORIENTATIONS.length; i ++ ) {\n\tconst orientation = ORIENTATIONS[ i ];\n\tconst transitions = [];\n\n\tfor ( const permutation of CHILD_PERMUTATIONS ) {\n\t\tconst childOrientation = permutation.map( index => orientation[ index ] );\n\t\tconst key = childOrientation.join( '' );\n\t\tlet id = ORIENTATION_IDS.get( key );\n\n\t\tif ( id === undefined ) {\n\t\t\tid = ORIENTATIONS.length;\n\t\t\tORIENTATIONS.push( childOrientation );\n\t\t\tORIENTATION_IDS.set( key, id );\n\t\t}\n\n\t\ttransitions.push( id );\n\t}\n\n\tORIENTATION_TRANSITIONS.push( transitions );\n}\n\nconst BIGINT_CHILD_INDEXES = [ 0n, 1n, 2n, 3n, 4n, 5n, 6n, 7n ];\nconst ZERO_CENTER = new Vector3( 0, 0, 0 );\n\n/**\n * Generates a portion of the 3D Hilbert curve.\n *\n * @param {Vector3} [center] - Center of Hilbert curve.\n * @param {number} [size=10] - Total width of Hilbert curve.\n * @param {number} [order=1] - Number of subdivisions.\n * @param {number|bigint} [start=0] - Index of the first point to generate.\n * @param {number|bigint} [length] - Number of points to generate.\n * @param {number} [v0=0] - Corner index -X, +Y, -Z.\n * @param {number} [v1=1] - Corner index -X, +Y, +Z.\n * @param {number} [v2=2] - Corner index -X, -Y, +Z.\n * @param {number} [v3=3] - Corner index -X, -Y, -Z.\n * @param {number} [v4=4] - Corner index +X, -Y, -Z.\n * @param {number} [v5=5] - Corner index +X, -Y, +Z.\n * @param {number} [v6=6] - Corner index +X, +Y, +Z.\n * @param {number} [v7=7] - Corner index +X, +Y, -Z.\n * @returns {Array<Vector3>} The requested Hilbert curve points.\n */\nexport function hilbert3D(\n\tcenter = ZERO_CENTER,\n\tsize = 10,\n\torder = 1,\n\tstart = 0,\n\tlength,\n\tv0 = 0,\n\tv1 = 1,\n\tv2 = 2,\n\tv3 = 3,\n\tv4 = 4,\n\tv5 = 5,\n\tv6 = 6,\n\tv7 = 7\n) {\n\tif ( order < 0 ) return [ new Vector3( 0, 0, 0 ) ];\n\tif ( ! Number.isInteger( order ) ) throw new TypeError( 'Order must be an integer.' );\n\n\tconst points = [];\n\n\tif ( typeof start === 'bigint' || typeof length === 'bigint' ) {\n\t\tconst first = toBigInt( start );\n\t\tconst count = 8n ** BigInt( order + 1 );\n\t\tconst requestedLength = length === undefined ? count : toBigInt( length );\n\t\tconst rangeStart = first < 0n ? 0n : first;\n\t\tconst requestedEnd = rangeStart + ( requestedLength > 0n ? requestedLength : 0n );\n\t\tconst rangeEnd = requestedEnd > count ? count : requestedEnd;\n\n\t\tif ( rangeStart >= rangeEnd ) return points;\n\n\t\tconst baseCorners = [ v0, v1, v2, v3, v4, v5, v6, v7 ];\n\t\tif ( rangeEnd - rangeStart === 1n ) {\n\t\t\tgenerateSingleBigInt( points, center.x, center.y, center.z, size, order, rangeStart, BigInt( order * 3 ), 0, baseCorners );\n\t\t\treturn points;\n\t\t}\n\n\t\tgenerateBigInt( points, center.x, center.y, center.z, size, order, 0n, count / 8n, 0, rangeStart, rangeEnd, baseCorners );\n\t\treturn points;\n\t}\n\n\tconst pointCount = 8 ** ( order + 1 );\n\tconst rawStart = Math.floor( start );\n\tconst first = Math.max( 0, rawStart );\n\tconst requestedLength = length === undefined ? pointCount : Math.max( 0, Math.floor( length ) );\n\tconst end = Math.min( pointCount, first + requestedLength );\n\n\tif ( first >= end ) return points;\n\n\tconst baseCorners = [ v0, v1, v2, v3, v4, v5, v6, v7 ];\n\tgenerateNumber( points, center.x, center.y, center.z, size, order, 0, pointCount / 8, 0, first, end, baseCorners );\n\treturn points;\n}\n\nexport default hilbert3D;\n\nfunction generateNumber( points, x, y, z, size, order, offset, chunkSize, orientationId, first, end, baseCorners ) {\n\tconst orientation = ORIENTATIONS[ orientationId ];\n\tconst transitions = ORIENTATION_TRANSITIONS[ orientationId ];\n\tconst half = size / 2;\n\n\tfor ( let i = 0; i < 8; i ++ ) {\n\t\tconst childOffset = offset + i * chunkSize;\n\t\tconst childEnd = childOffset + chunkSize;\n\t\tif ( childEnd <= first || childOffset >= end ) continue;\n\n\t\tconst actualCorner = baseCorners[ orientation[ i ] ];\n\t\tconst childX = x + ( actualCorner < 4 ? -half : half );\n\t\tconst childY = y + ( actualCorner < 2 || actualCorner > 5 ? half : -half );\n\t\tconst childZ = z + ( actualCorner % 4 === 1 || actualCorner % 4 === 2 ? half : -half );\n\n\t\tif ( order === 0 ) {\n\t\t\tpoints.push( new Vector3( childX, childY, childZ ) );\n\t\t} else {\n\t\t\tgenerateNumber( points, childX, childY, childZ, half, order - 1, childOffset, chunkSize / 8, transitions[ i ], first, end, baseCorners );\n\t\t}\n\t}\n}\n\nfunction generateBigInt( points, x, y, z, size, order, offset, chunkSize, orientationId, first, end, baseCorners ) {\n\tconst orientation = ORIENTATIONS[ orientationId ];\n\tconst transitions = ORIENTATION_TRANSITIONS[ orientationId ];\n\tconst half = size / 2;\n\tconst childChunkSize = chunkSize / 8n;\n\tconst nodeEnd = offset + chunkSize * 8n;\n\tconst firstChild = first <= offset ? 0 : Number( ( first - offset ) / chunkSize );\n\tconst lastChild = end >= nodeEnd ? 7 : Number( ( end - 1n - offset ) / chunkSize );\n\tlet childOffset = offset + BIGINT_CHILD_INDEXES[ firstChild ] * chunkSize;\n\n\tfor ( let i = firstChild; i <= lastChild; i ++, childOffset += chunkSize ) {\n\n\t\tconst actualCorner = baseCorners[ orientation[ i ] ];\n\t\tconst childX = x + ( actualCorner < 4 ? -half : half );\n\t\tconst childY = y + ( actualCorner < 2 || actualCorner > 5 ? half : -half );\n\t\tconst childZ = z + ( actualCorner % 4 === 1 || actualCorner % 4 === 2 ? half : -half );\n\n\t\tif ( order === 0 ) {\n\t\t\tpoints.push( new Vector3( childX, childY, childZ ) );\n\t\t} else {\n\t\t\tgenerateBigInt( points, childX, childY, childZ, half, order - 1, childOffset, childChunkSize, transitions[ i ], first, end, baseCorners );\n\t\t}\n\t}\n}\n\nfunction generateSingleBigInt( points, x, y, z, size, order, index, shift, orientationId, baseCorners ) {\n\tconst orientation = ORIENTATIONS[ orientationId ];\n\tconst child = Number( ( index >> shift ) & 7n );\n\tconst actualCorner = baseCorners[ orientation[ child ] ];\n\tconst half = size / 2;\n\tconst childX = x + ( actualCorner < 4 ? -half : half );\n\tconst childY = y + ( actualCorner < 2 || actualCorner > 5 ? half : -half );\n\tconst childZ = z + ( actualCorner % 4 === 1 || actualCorner % 4 === 2 ? half : -half );\n\n\tif ( order === 0 ) {\n\t\tpoints.push( new Vector3( childX, childY, childZ ) );\n\t} else {\n\t\tgenerateSingleBigInt( points, childX, childY, childZ, half, order - 1, index, shift - 3n, ORIENTATION_TRANSITIONS[ orientationId ][ child ], baseCorners );\n\t}\n}\n\nfunction toBigInt( value ) {\n\tif ( typeof value === 'bigint' ) return value;\n\tif ( ! Number.isSafeInteger( value ) ) throw new TypeError( 'BigInt ranges require integer values.' );\n\treturn BigInt( value );\n}\n","import {\n Box3,\n BufferGeometry,\n Float32BufferAttribute,\n Quaternion,\n Sphere,\n Uint16BufferAttribute,\n Uint32BufferAttribute,\n Vector3\n} from 'three';\n\nconst SINGLE_CUBE_FACES = [\n [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7],\n [0, 3, 2, 1], [4, 5, 6, 7]\n];\nconst SINGLE_CUBE_CORNERS = [\n [-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1],\n [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]\n];\nconst SINGLE_CUBE_UVS = new Float32Array(24 * 2);\nconst SINGLE_CUBE_NORMALS = new Float32Array(24 * 3);\nconst SINGLE_CUBE_INDICES = new Uint16Array(36);\nconst SINGLE_CUBE_NORMALS_BY_FACE = [\n [0, -1, 0], [1, 0, 0], [0, 1, 0], [-1, 0, 0], [0, 0, -1], [0, 0, 1]\n];\n\nfor (let faceIndex = 0; faceIndex < SINGLE_CUBE_FACES.length; faceIndex++) {\n const face = SINGLE_CUBE_FACES[faceIndex];\n const normal = SINGLE_CUBE_NORMALS_BY_FACE[faceIndex];\n\n for (let i = 0; i < 4; i++) {\n const vertex = faceIndex * 4 + i;\n const corner = face[i];\n SINGLE_CUBE_UVS[vertex * 2] = corner % 2;\n SINGLE_CUBE_UVS[vertex * 2 + 1] = Math.floor(corner / 2) % 2;\n SINGLE_CUBE_NORMALS.set(normal, vertex * 3);\n }\n\n const vertexOffset = faceIndex * 4;\n const indexOffset = faceIndex * 6;\n SINGLE_CUBE_INDICES.set([\n vertexOffset, vertexOffset + 1, vertexOffset + 2,\n vertexOffset, vertexOffset + 2, vertexOffset + 3\n ], indexOffset);\n}\n\nexport default class SquareTubeGeometry extends BufferGeometry {\n constructor(points = [], width = 1) {\n super();\n\n if (!Array.isArray(points)) {\n throw new TypeError('points must be an array of Vector3 instances');\n }\n if (!Number.isFinite(width) || width < 0) {\n throw new RangeError('width must be a non-negative finite number');\n }\n\n this.type = 'SquareTubeGeometry';\n\n if (points.length <= 1) {\n const point = points[0];\n if (points.length === 1 && (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z))) {\n throw new TypeError('points[0] must have finite x, y, and z coordinates');\n }\n\n this.parameters = {\n points: point ? [new Vector3(point.x, point.y, point.z)] : [],\n width\n };\n\n if (!point || width === 0) {\n this.setIndex([]);\n this.setAttribute('position', new Float32BufferAttribute([], 3));\n this.setAttribute('uv', new Float32BufferAttribute([], 2));\n return;\n }\n\n const halfWidth = width / 2;\n const x = point.x;\n const y = point.y;\n const z = point.z;\n const positions = new Float32Array(24 * 3);\n let positionOffset = 0;\n\n for (const face of SINGLE_CUBE_FACES) {\n for (const corner of face) {\n const signs = SINGLE_CUBE_CORNERS[corner];\n positions[positionOffset++] = x + signs[0] * halfWidth;\n positions[positionOffset++] = y + signs[1] * halfWidth;\n positions[positionOffset++] = z + signs[2] * halfWidth;\n }\n }\n\n this.setIndex(new Uint16BufferAttribute(SINGLE_CUBE_INDICES.slice(), 1));\n this.setAttribute('position', new Float32BufferAttribute(positions, 3));\n this.setAttribute('uv', new Float32BufferAttribute(SINGLE_CUBE_UVS.slice(), 2));\n this.setAttribute('normal', new Float32BufferAttribute(SINGLE_CUBE_NORMALS.slice(), 3));\n this.boundingBox = new Box3(\n new Vector3(x - halfWidth, y - halfWidth, z - halfWidth),\n new Vector3(x + halfWidth, y + halfWidth, z + halfWidth)\n );\n this.boundingSphere = new Sphere(\n new Vector3(x, y, z),\n Math.sqrt(3) * halfWidth\n );\n return;\n }\n\n const path = points.map((point, index) => {\n if (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z)) {\n throw new TypeError(`points[${index}] must have finite x, y, and z coordinates`);\n }\n return new Vector3(point.x, point.y, point.z);\n }).filter((point, index, list) => index === 0 || point.distanceToSquared(list[index - 1]) > 0);\n\n this.parameters = { points: path.map(point => point.clone()), width };\n\n if (path.length === 0 || width === 0) {\n this.setIndex([]);\n this.setAttribute('position', new Float32BufferAttribute([], 3));\n this.setAttribute('uv', new Float32BufferAttribute([], 2));\n return;\n }\n\n const directions = path.slice(1).map((point, index) =>\n point.clone().sub(path[index]).normalize()\n );\n const turnTolerance = 1e-6;\n let turnCount = 0;\n for (let i = 1; i < directions.length; i++) {\n const dot = directions[i - 1].dot(directions[i]);\n const isRightAngle = Math.abs(dot) <= turnTolerance;\n const continuesStraight = dot >= 1 - turnTolerance;\n if (!isRightAngle && !continuesStraight) {\n throw new RangeError('path turns must be 90 degrees; straight segments are also allowed');\n }\n if (isRightAngle) turnCount++;\n }\n\n const halfWidth = width / 2;\n const frames = [];\n const normal = new Vector3();\n const binormal = new Vector3();\n const rotation = new Quaternion();\n\n for (let i = 0; i < directions.length; i++) {\n if (i === 0) {\n const tangent = directions[i];\n const absX = Math.abs(tangent.x);\n const absY = Math.abs(tangent.y);\n const absZ = Math.abs(tangent.z);\n normal.set(\n absX <= absY && absX <= absZ ? 1 : 0,\n absY < absX && absY <= absZ ? 1 : 0,\n absZ < absX && absZ < absY ? 1 : 0\n );\n normal.addScaledVector(tangent, -normal.dot(tangent)).normalize();\n } else {\n rotation.setFromUnitVectors(directions[i - 1], directions[i]);\n normal.applyQuaternion(rotation);\n normal.addScaledVector(directions[i], -normal.dot(directions[i])).normalize();\n }\n binormal.crossVectors(directions[i], normal).normalize();\n frames.push({ normal: normal.clone(), binormal: binormal.clone() });\n }\n\n const faces = [\n [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7],\n [0, 3, 2, 1], [4, 5, 6, 7]\n ];\n const solidCount = path.length === 1 ? 1 : directions.length + turnCount;\n const positions = new Float32Array(solidCount * 24 * 3);\n const uvs = new Float32Array(solidCount * 24 * 2);\n const use32BitIndices = solidCount * 24 > 65535;\n const IndexAttribute = use32BitIndices ? Uint32BufferAttribute : Uint16BufferAttribute;\n const indices = use32BitIndices ? new Uint32Array(solidCount * 36) : new Uint16Array(solidCount * 36);\n let positionOffset = 0;\n let uvOffset = 0;\n let vertexOffset = 0;\n let indexOffset = 0;\n\n function addSolid(corners) {\n for (const face of faces) {\n for (const cornerIndex of face) {\n const point = corners[cornerIndex];\n positions[positionOffset++] = point.x;\n positions[positionOffset++] = point.y;\n positions[positionOffset++] = point.z;\n uvs[uvOffset++] = cornerIndex % 2;\n uvs[uvOffset++] = Math.floor(cornerIndex / 2) % 2;\n }\n indices[indexOffset++] = vertexOffset;\n indices[indexOffset++] = vertexOffset + 1;\n indices[indexOffset++] = vertexOffset + 2;\n indices[indexOffset++] = vertexOffset;\n indices[indexOffset++] = vertexOffset + 2;\n indices[indexOffset++] = vertexOffset + 3;\n vertexOffset += 4;\n }\n }\n\n if (path.length === 1) {\n const [x, y, z] = path[0].toArray();\n addSolid([\n new Vector3(x - halfWidth, y - halfWidth, z - halfWidth),\n new Vector3(x + halfWidth, y - halfWidth, z - halfWidth),\n new Vector3(x + halfWidth, y + halfWidth, z - halfWidth),\n new Vector3(x - halfWidth, y + halfWidth, z - halfWidth),\n new Vector3(x - halfWidth, y - halfWidth, z + halfWidth),\n new Vector3(x + halfWidth, y - halfWidth, z + halfWidth),\n new Vector3(x + halfWidth, y + halfWidth, z + halfWidth),\n new Vector3(x - halfWidth, y + halfWidth, z + halfWidth)\n ]);\n\n this.setIndex(new IndexAttribute(indices, 1));\n this.setAttribute('position', new Float32BufferAttribute(positions, 3));\n this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));\n this.computeVertexNormals();\n this.computeBoundingBox();\n this.computeBoundingSphere();\n return;\n }\n\n for (let i = 0; i < directions.length; i++) {\n const direction = directions[i];\n const start = path[i].clone();\n const end = path[i + 1].clone();\n if (i === 0) start.addScaledVector(direction, -halfWidth);\n if (i === directions.length - 1) end.addScaledVector(direction, halfWidth);\n\n const sectionCorners = (center) => [\n center.clone().addScaledVector(frames[i].normal, halfWidth).addScaledVector(frames[i].binormal, halfWidth),\n center.clone().addScaledVector(frames[i].normal, -halfWidth).addScaledVector(frames[i].binormal, halfWidth),\n center.clone().addScaledVector(frames[i].normal, -halfWidth).addScaledVector(frames[i].binormal, -halfWidth),\n center.clone().addScaledVector(frames[i].normal, halfWidth).addScaledVector(frames[i].binormal, -halfWidth)\n ];\n\n addSolid([...sectionCorners(start), ...sectionCorners(end)]);\n }\n\n for (let i = 1; i < path.length - 1; i++) {\n if (Math.abs(directions[i - 1].dot(directions[i])) <= turnTolerance) {\n const [x, y, z] = path[i].toArray();\n addSolid([\n new Vector3(x - halfWidth, y - halfWidth, z - halfWidth),\n new Vector3(x + halfWidth, y - halfWidth, z - halfWidth),\n new Vector3(x + halfWidth, y + halfWidth, z - halfWidth),\n new Vector3(x - halfWidth, y + halfWidth, z - halfWidth),\n new Vector3(x - halfWidth, y - halfWidth, z + halfWidth),\n new Vector3(x + halfWidth, y - halfWidth, z + halfWidth),\n new Vector3(x + halfWidth, y + halfWidth, z + halfWidth),\n new Vector3(x - halfWidth, y + halfWidth, z + halfWidth)\n ]);\n }\n }\n\n this.setIndex(new IndexAttribute(indices, 1));\n this.setAttribute('position', new Float32BufferAttribute(positions, 3));\n this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));\n this.computeVertexNormals();\n this.computeBoundingBox();\n this.computeBoundingSphere();\n }\n\n copy(source) {\n super.copy(source);\n this.parameters = {\n points: source.parameters.points.map(point => point.clone()),\n width: source.parameters.width\n };\n return this;\n }\n}\n","import hilbert3D from './hilbert3d.js';\nimport SquareTubeGeometry from './SquareTubeGeometry.js';\n\nexport default class ThreeHilbertGeometry extends SquareTubeGeometry {\n constructor(order, start, length, {\n padding = 0,\n simplifyCurves = true\n } = {}) {\n super(...getSuperParams());\n\n this.type = 'HilbertGeometry';\n\n function getSuperParams() {\n typeof start !== 'bigint' && (start = Math.round(start));\n typeof length !== 'bigint' && (length = Math.round(length));\n\n if (simplifyCurves) {\n // resolution simplification\n const n8 = typeof start === 'bigint' ? 8n : 8;\n while (!(start % n8) && !(length % n8) && order > 0) {\n start /= n8;\n length /= n8;\n order -= 1;\n }\n }\n\n const points = hilbert3D(undefined, 1, order - 1, start, length);\n const lineWidth = 1 / (2**(order-1)) * (1 - Math.min(1, padding));\n\n return [points, lineWidth];\n }\n }\n}\n\n/*\nconst geometryCache = (() => {\n const cache = {};\n cache[''] = new SquareTubeGeometry([new Vector3()]);\n for (const nPnts of [2, 4]) {\n for (let start = 0; start < 8; start++) {\n const pnts = hilbert3D(undefined, 1, 0, start, nPnts);\n const key = getCurvePath(pnts);\n cache[key] = new SquareTubeGeometry(pnts);\n }\n }\n return cache;\n})();\n\n// console.log(geometryCache);\n\nfunction genInstancedGeometry(order, start, length, {\n padding = 0,\n simplifyCurves\n} = {}) {\n // resolution simplification\n const n8 = typeof start === 'bigint' ? 8n : 8;\n while (!(start % n8) && !(length % n8) && order > 0) {\n start /= n8;\n length /= n8;\n order -= 1;\n }\n\n const points = hilbert3D(undefined, 1, order - 1, start, length);\n\n let geometry;\n let position = new Vector3();\n let scale = 1;\n\n if ([1, 2, 4].some(l => l === points.length)) {\n // Most common simple cases\n const key = getCurvePath(points);\n geometry = geometryCache[key];\n } else {\n // More complex cases, fallback to regular geometry generation\n geometry = new ThreeHilbertGeometry(order, start, length, { padding, simplifyCurves });\n }\n\n return {\n geometry,\n position,\n scale,\n }\n}\n\nfunction getCurvePath(points) {\n const path = [];\n let prevPnt = points[0];\n\n for (let i = 1; i < points.length; i++) {\n const pnt = points[i];\n for (const c of ['x', 'y', 'z']) {\n const dist = pnt[c] - prevPnt[c];\n if (dist) {\n path.push(\n c === 'x' ? dist > 0 ? 'R' : 'L'\n : c === 'y' ? dist > 0 ? 'U' : 'D'\n : dist > 0 ? 'B' : 'F'\n );\n break;\n }\n }\n prevPnt = pnt;\n }\n return path.join('');\n}\n\n */"],"names":["Vector3","BufferGeometry","Float32BufferAttribute","Uint16BufferAttribute","Box3","Sphere","Quaternion","Uint32BufferAttribute"],"mappings":";;;;;;;CAEA,MAAM,kBAAkB,GAAG,CAC1B,CAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAE,EAC1B,CAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAE,EAC1B,CAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAE,EAC1B,CAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,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EAAA;CACF;;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CAEA;;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CAEA;;CAEA;CACA;CACA;;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CAEA;CACA;CACA;CACA;CACA;CACA;;CAEA;CACA;CACA;;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CAEA;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// Version 1.0.0 three-hilbert-geometry - https://github.com/vasturiano/three-hilbert-geometry
|
|
2
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("three")):"function"==typeof define&&define.amd?define(["three"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).HilbertGeometry=e(t.THREE)}(this,function(t){"use strict";const e=[[0,3,4,7,6,5,2,1],[0,7,6,1,2,5,4,3],[0,7,6,1,2,5,4,3],[2,3,0,1,6,7,4,5],[2,3,0,1,6,7,4,5],[4,3,2,5,6,1,0,7],[4,3,2,5,6,1,0,7],[6,5,2,1,0,3,4,7]],n=[[0,1,2,3,4,5,6,7]],r=[],o=new Map([[n[0].join(""),0]]);for(let t=0;t<n.length;t++){const i=n[t],s=[];for(const t of e){const e=t.map(t=>i[t]),r=e.join("");let a=o.get(r);void 0===a&&(a=n.length,n.push(e),o.set(r,a)),s.push(a)}r.push(s)}const i=[0n,1n,2n,3n,4n,5n,6n,7n],s=new t.Vector3(0,0,0);function a(e=s,n=10,r=1,o=0,i,a=0,h=1,d=2,w=3,p=4,b=5,m=6,y=7){if(r<0)return[new t.Vector3(0,0,0)];if(!Number.isInteger(r))throw new TypeError("Order must be an integer.");const g=[];if("bigint"==typeof o||"bigint"==typeof i){const t=f(o),s=8n**BigInt(r+1),c=void 0===i?s:f(i),V=t<0n?0n:t,A=V+(c>0n?c:0n),x=A>s?s:A;if(V>=x)return g;const B=[a,h,d,w,p,b,m,y];return x-V===1n?(l(g,e.x,e.y,e.z,n,r,V,BigInt(3*r),0,B),g):(u(g,e.x,e.y,e.z,n,r,0n,s/8n,0,V,x,B),g)}const V=8**(r+1),A=Math.floor(o),x=Math.max(0,A),B=void 0===i?V:Math.max(0,Math.floor(i)),F=Math.min(V,x+B);if(x>=F)return g;const S=[a,h,d,w,p,b,m,y];return c(g,e.x,e.y,e.z,n,r,0,V/8,0,x,F,S),g}function c(e,o,i,s,a,u,l,f,h,d,w,p){const b=n[h],m=r[h],y=a/2;for(let n=0;n<8;n++){const r=l+n*f;if(r+f<=d||r>=w)continue;const a=p[b[n]],h=o+(a<4?-y:y),g=i+(a<2||a>5?y:-y),V=s+(a%4==1||a%4==2?y:-y);0===u?e.push(new t.Vector3(h,g,V)):c(e,h,g,V,y,u-1,r,f/8,m[n],d,w,p)}}function u(e,o,s,a,c,l,f,h,d,w,p,b){const m=n[d],y=r[d],g=c/2,V=h/8n,A=f+8n*h,x=w<=f?0:Number((w-f)/h),B=p>=A?7:Number((p-1n-f)/h);let F=f+i[x]*h;for(let n=x;n<=B;n++,F+=h){const r=b[m[n]],i=o+(r<4?-g:g),c=s+(r<2||r>5?g:-g),f=a+(r%4==1||r%4==2?g:-g);0===l?e.push(new t.Vector3(i,c,f)):u(e,i,c,f,g,l-1,F,V,y[n],w,p,b)}}function l(e,o,i,s,a,c,u,f,h,d){const w=n[h],p=Number(u>>f&7n),b=d[w[p]],m=a/2,y=o+(b<4?-m:m),g=i+(b<2||b>5?m:-m),V=s+(b%4==1||b%4==2?m:-m);0===c?e.push(new t.Vector3(y,g,V)):l(e,y,g,V,m,c-1,u,f-3n,r[h][p],d)}function f(t){if("bigint"==typeof t)return t;if(!Number.isSafeInteger(t))throw new TypeError("BigInt ranges require integer values.");return BigInt(t)}const h=[[0,1,5,4],[1,2,6,5],[2,3,7,6],[3,0,4,7],[0,3,2,1],[4,5,6,7]],d=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]],w=new Float32Array(48),p=new Float32Array(72),b=new Uint16Array(36),m=[[0,-1,0],[1,0,0],[0,1,0],[-1,0,0],[0,0,-1],[0,0,1]];for(let t=0;t<h.length;t++){const e=h[t],n=m[t];for(let r=0;r<4;r++){const o=4*t+r,i=e[r];w[2*o]=i%2,w[2*o+1]=Math.floor(i/2)%2,p.set(n,3*o)}const r=4*t,o=6*t;b.set([r,r+1,r+2,r,r+2,r+3],o)}class y extends t.BufferGeometry{constructor(e=[],n=1){if(super(),!Array.isArray(e))throw new TypeError("points must be an array of Vector3 instances");if(!Number.isFinite(n)||n<0)throw new RangeError("width must be a non-negative finite number");if(this.type="SquareTubeGeometry",e.length<=1){const r=e[0];if(!(1!==e.length||r&&Number.isFinite(r.x)&&Number.isFinite(r.y)&&Number.isFinite(r.z)))throw new TypeError("points[0] must have finite x, y, and z coordinates");if(this.parameters={points:r?[new t.Vector3(r.x,r.y,r.z)]:[],width:n},!r||0===n)return this.setIndex([]),this.setAttribute("position",new t.Float32BufferAttribute([],3)),void this.setAttribute("uv",new t.Float32BufferAttribute([],2));const o=n/2,i=r.x,s=r.y,a=r.z,c=new Float32Array(72);let u=0;for(const t of h)for(const e of t){const t=d[e];c[u++]=i+t[0]*o,c[u++]=s+t[1]*o,c[u++]=a+t[2]*o}return this.setIndex(new t.Uint16BufferAttribute(b.slice(),1)),this.setAttribute("position",new t.Float32BufferAttribute(c,3)),this.setAttribute("uv",new t.Float32BufferAttribute(w.slice(),2)),this.setAttribute("normal",new t.Float32BufferAttribute(p.slice(),3)),this.boundingBox=new t.Box3(new t.Vector3(i-o,s-o,a-o),new t.Vector3(i+o,s+o,a+o)),void(this.boundingSphere=new t.Sphere(new t.Vector3(i,s,a),Math.sqrt(3)*o))}const r=e.map((e,n)=>{if(!(e&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.z)))throw new TypeError(`points[${n}] must have finite x, y, and z coordinates`);return new t.Vector3(e.x,e.y,e.z)}).filter((t,e,n)=>0===e||t.distanceToSquared(n[e-1])>0);if(this.parameters={points:r.map(t=>t.clone()),width:n},0===r.length||0===n)return this.setIndex([]),this.setAttribute("position",new t.Float32BufferAttribute([],3)),void this.setAttribute("uv",new t.Float32BufferAttribute([],2));const o=r.slice(1).map((t,e)=>t.clone().sub(r[e]).normalize()),i=1e-6;let s=0;for(let t=1;t<o.length;t++){const e=o[t-1].dot(o[t]),n=Math.abs(e)<=i;if(!n&&!(e>=.999999))throw new RangeError("path turns must be 90 degrees; straight segments are also allowed");n&&s++}const a=n/2,c=[],u=new t.Vector3,l=new t.Vector3,f=new t.Quaternion;for(let t=0;t<o.length;t++){if(0===t){const e=o[t],n=Math.abs(e.x),r=Math.abs(e.y),i=Math.abs(e.z);u.set(n<=r&&n<=i?1:0,r<n&&r<=i?1:0,i<n&&i<r?1:0),u.addScaledVector(e,-u.dot(e)).normalize()}else f.setFromUnitVectors(o[t-1],o[t]),u.applyQuaternion(f),u.addScaledVector(o[t],-u.dot(o[t])).normalize();l.crossVectors(o[t],u).normalize(),c.push({normal:u.clone(),binormal:l.clone()})}const m=[[0,1,5,4],[1,2,6,5],[2,3,7,6],[3,0,4,7],[0,3,2,1],[4,5,6,7]],y=1===r.length?1:o.length+s,g=new Float32Array(24*y*3),V=new Float32Array(24*y*2),A=24*y>65535,x=A?t.Uint32BufferAttribute:t.Uint16BufferAttribute,B=A?new Uint32Array(36*y):new Uint16Array(36*y);let F=0,S=0,v=0,M=0;function z(t){for(const e of m){for(const n of e){const e=t[n];g[F++]=e.x,g[F++]=e.y,g[F++]=e.z,V[S++]=n%2,V[S++]=Math.floor(n/2)%2}B[M++]=v,B[M++]=v+1,B[M++]=v+2,B[M++]=v,B[M++]=v+2,B[M++]=v+3,v+=4}}if(1===r.length){const[e,n,o]=r[0].toArray();return z([new t.Vector3(e-a,n-a,o-a),new t.Vector3(e+a,n-a,o-a),new t.Vector3(e+a,n+a,o-a),new t.Vector3(e-a,n+a,o-a),new t.Vector3(e-a,n-a,o+a),new t.Vector3(e+a,n-a,o+a),new t.Vector3(e+a,n+a,o+a),new t.Vector3(e-a,n+a,o+a)]),this.setIndex(new x(B,1)),this.setAttribute("position",new t.Float32BufferAttribute(g,3)),this.setAttribute("uv",new t.Float32BufferAttribute(V,2)),this.computeVertexNormals(),this.computeBoundingBox(),void this.computeBoundingSphere()}for(let t=0;t<o.length;t++){const e=o[t],n=r[t].clone(),i=r[t+1].clone();0===t&&n.addScaledVector(e,-a),t===o.length-1&&i.addScaledVector(e,a);const s=e=>[e.clone().addScaledVector(c[t].normal,a).addScaledVector(c[t].binormal,a),e.clone().addScaledVector(c[t].normal,-a).addScaledVector(c[t].binormal,a),e.clone().addScaledVector(c[t].normal,-a).addScaledVector(c[t].binormal,-a),e.clone().addScaledVector(c[t].normal,a).addScaledVector(c[t].binormal,-a)];z([...s(n),...s(i)])}for(let e=1;e<r.length-1;e++)if(Math.abs(o[e-1].dot(o[e]))<=i){const[n,o,i]=r[e].toArray();z([new t.Vector3(n-a,o-a,i-a),new t.Vector3(n+a,o-a,i-a),new t.Vector3(n+a,o+a,i-a),new t.Vector3(n-a,o+a,i-a),new t.Vector3(n-a,o-a,i+a),new t.Vector3(n+a,o-a,i+a),new t.Vector3(n+a,o+a,i+a),new t.Vector3(n-a,o+a,i+a)])}this.setIndex(new x(B,1)),this.setAttribute("position",new t.Float32BufferAttribute(g,3)),this.setAttribute("uv",new t.Float32BufferAttribute(V,2)),this.computeVertexNormals(),this.computeBoundingBox(),this.computeBoundingSphere()}copy(t){return super.copy(t),this.parameters={points:t.parameters.points.map(t=>t.clone()),width:t.parameters.width},this}}return class extends y{constructor(t,e,n,{padding:r=0,simplifyCurves:o=!0}={}){super(...function(){if("bigint"!=typeof e&&(e=Math.round(e)),"bigint"!=typeof n&&(n=Math.round(n)),o){const r="bigint"==typeof e?8n:8;for(;!(e%r)&&!(n%r)&&t>0;)e/=r,n/=r,t-=1}const i=a(void 0,1,t-1,e,n),s=1/2**(t-1)*(1-Math.min(1,r));return[i,s]}()),this.type="HilbertGeometry"}}});
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { Vector3, BufferGeometry, Float32BufferAttribute, Uint16BufferAttribute, Box3, Sphere, Quaternion, Uint32BufferAttribute } from 'three';
|
|
2
|
+
|
|
3
|
+
const CHILD_PERMUTATIONS = [[0, 3, 4, 7, 6, 5, 2, 1], [0, 7, 6, 1, 2, 5, 4, 3], [0, 7, 6, 1, 2, 5, 4, 3], [2, 3, 0, 1, 6, 7, 4, 5], [2, 3, 0, 1, 6, 7, 4, 5], [4, 3, 2, 5, 6, 1, 0, 7], [4, 3, 2, 5, 6, 1, 0, 7], [6, 5, 2, 1, 0, 3, 4, 7]];
|
|
4
|
+
const ORIENTATIONS = [[0, 1, 2, 3, 4, 5, 6, 7]];
|
|
5
|
+
const ORIENTATION_TRANSITIONS = [];
|
|
6
|
+
const ORIENTATION_IDS = new Map([[ORIENTATIONS[0].join(''), 0]]);
|
|
7
|
+
for (let i = 0; i < ORIENTATIONS.length; i++) {
|
|
8
|
+
const orientation = ORIENTATIONS[i];
|
|
9
|
+
const transitions = [];
|
|
10
|
+
for (const permutation of CHILD_PERMUTATIONS) {
|
|
11
|
+
const childOrientation = permutation.map(index => orientation[index]);
|
|
12
|
+
const key = childOrientation.join('');
|
|
13
|
+
let id = ORIENTATION_IDS.get(key);
|
|
14
|
+
if (id === undefined) {
|
|
15
|
+
id = ORIENTATIONS.length;
|
|
16
|
+
ORIENTATIONS.push(childOrientation);
|
|
17
|
+
ORIENTATION_IDS.set(key, id);
|
|
18
|
+
}
|
|
19
|
+
transitions.push(id);
|
|
20
|
+
}
|
|
21
|
+
ORIENTATION_TRANSITIONS.push(transitions);
|
|
22
|
+
}
|
|
23
|
+
const BIGINT_CHILD_INDEXES = [0n, 1n, 2n, 3n, 4n, 5n, 6n, 7n];
|
|
24
|
+
const ZERO_CENTER = new Vector3(0, 0, 0);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generates a portion of the 3D Hilbert curve.
|
|
28
|
+
*
|
|
29
|
+
* @param {Vector3} [center] - Center of Hilbert curve.
|
|
30
|
+
* @param {number} [size=10] - Total width of Hilbert curve.
|
|
31
|
+
* @param {number} [order=1] - Number of subdivisions.
|
|
32
|
+
* @param {number|bigint} [start=0] - Index of the first point to generate.
|
|
33
|
+
* @param {number|bigint} [length] - Number of points to generate.
|
|
34
|
+
* @param {number} [v0=0] - Corner index -X, +Y, -Z.
|
|
35
|
+
* @param {number} [v1=1] - Corner index -X, +Y, +Z.
|
|
36
|
+
* @param {number} [v2=2] - Corner index -X, -Y, +Z.
|
|
37
|
+
* @param {number} [v3=3] - Corner index -X, -Y, -Z.
|
|
38
|
+
* @param {number} [v4=4] - Corner index +X, -Y, -Z.
|
|
39
|
+
* @param {number} [v5=5] - Corner index +X, -Y, +Z.
|
|
40
|
+
* @param {number} [v6=6] - Corner index +X, +Y, +Z.
|
|
41
|
+
* @param {number} [v7=7] - Corner index +X, +Y, -Z.
|
|
42
|
+
* @returns {Array<Vector3>} The requested Hilbert curve points.
|
|
43
|
+
*/
|
|
44
|
+
function hilbert3D(center = ZERO_CENTER, size = 10, order = 1, start = 0, length, v0 = 0, v1 = 1, v2 = 2, v3 = 3, v4 = 4, v5 = 5, v6 = 6, v7 = 7) {
|
|
45
|
+
if (order < 0) return [new Vector3(0, 0, 0)];
|
|
46
|
+
if (!Number.isInteger(order)) throw new TypeError('Order must be an integer.');
|
|
47
|
+
const points = [];
|
|
48
|
+
if (typeof start === 'bigint' || typeof length === 'bigint') {
|
|
49
|
+
const first = toBigInt(start);
|
|
50
|
+
const count = 8n ** BigInt(order + 1);
|
|
51
|
+
const requestedLength = length === undefined ? count : toBigInt(length);
|
|
52
|
+
const rangeStart = first < 0n ? 0n : first;
|
|
53
|
+
const requestedEnd = rangeStart + (requestedLength > 0n ? requestedLength : 0n);
|
|
54
|
+
const rangeEnd = requestedEnd > count ? count : requestedEnd;
|
|
55
|
+
if (rangeStart >= rangeEnd) return points;
|
|
56
|
+
const baseCorners = [v0, v1, v2, v3, v4, v5, v6, v7];
|
|
57
|
+
if (rangeEnd - rangeStart === 1n) {
|
|
58
|
+
generateSingleBigInt(points, center.x, center.y, center.z, size, order, rangeStart, BigInt(order * 3), 0, baseCorners);
|
|
59
|
+
return points;
|
|
60
|
+
}
|
|
61
|
+
generateBigInt(points, center.x, center.y, center.z, size, order, 0n, count / 8n, 0, rangeStart, rangeEnd, baseCorners);
|
|
62
|
+
return points;
|
|
63
|
+
}
|
|
64
|
+
const pointCount = 8 ** (order + 1);
|
|
65
|
+
const rawStart = Math.floor(start);
|
|
66
|
+
const first = Math.max(0, rawStart);
|
|
67
|
+
const requestedLength = length === undefined ? pointCount : Math.max(0, Math.floor(length));
|
|
68
|
+
const end = Math.min(pointCount, first + requestedLength);
|
|
69
|
+
if (first >= end) return points;
|
|
70
|
+
const baseCorners = [v0, v1, v2, v3, v4, v5, v6, v7];
|
|
71
|
+
generateNumber(points, center.x, center.y, center.z, size, order, 0, pointCount / 8, 0, first, end, baseCorners);
|
|
72
|
+
return points;
|
|
73
|
+
}
|
|
74
|
+
function generateNumber(points, x, y, z, size, order, offset, chunkSize, orientationId, first, end, baseCorners) {
|
|
75
|
+
const orientation = ORIENTATIONS[orientationId];
|
|
76
|
+
const transitions = ORIENTATION_TRANSITIONS[orientationId];
|
|
77
|
+
const half = size / 2;
|
|
78
|
+
for (let i = 0; i < 8; i++) {
|
|
79
|
+
const childOffset = offset + i * chunkSize;
|
|
80
|
+
const childEnd = childOffset + chunkSize;
|
|
81
|
+
if (childEnd <= first || childOffset >= end) continue;
|
|
82
|
+
const actualCorner = baseCorners[orientation[i]];
|
|
83
|
+
const childX = x + (actualCorner < 4 ? -half : half);
|
|
84
|
+
const childY = y + (actualCorner < 2 || actualCorner > 5 ? half : -half);
|
|
85
|
+
const childZ = z + (actualCorner % 4 === 1 || actualCorner % 4 === 2 ? half : -half);
|
|
86
|
+
if (order === 0) {
|
|
87
|
+
points.push(new Vector3(childX, childY, childZ));
|
|
88
|
+
} else {
|
|
89
|
+
generateNumber(points, childX, childY, childZ, half, order - 1, childOffset, chunkSize / 8, transitions[i], first, end, baseCorners);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function generateBigInt(points, x, y, z, size, order, offset, chunkSize, orientationId, first, end, baseCorners) {
|
|
94
|
+
const orientation = ORIENTATIONS[orientationId];
|
|
95
|
+
const transitions = ORIENTATION_TRANSITIONS[orientationId];
|
|
96
|
+
const half = size / 2;
|
|
97
|
+
const childChunkSize = chunkSize / 8n;
|
|
98
|
+
const nodeEnd = offset + chunkSize * 8n;
|
|
99
|
+
const firstChild = first <= offset ? 0 : Number((first - offset) / chunkSize);
|
|
100
|
+
const lastChild = end >= nodeEnd ? 7 : Number((end - 1n - offset) / chunkSize);
|
|
101
|
+
let childOffset = offset + BIGINT_CHILD_INDEXES[firstChild] * chunkSize;
|
|
102
|
+
for (let i = firstChild; i <= lastChild; i++, childOffset += chunkSize) {
|
|
103
|
+
const actualCorner = baseCorners[orientation[i]];
|
|
104
|
+
const childX = x + (actualCorner < 4 ? -half : half);
|
|
105
|
+
const childY = y + (actualCorner < 2 || actualCorner > 5 ? half : -half);
|
|
106
|
+
const childZ = z + (actualCorner % 4 === 1 || actualCorner % 4 === 2 ? half : -half);
|
|
107
|
+
if (order === 0) {
|
|
108
|
+
points.push(new Vector3(childX, childY, childZ));
|
|
109
|
+
} else {
|
|
110
|
+
generateBigInt(points, childX, childY, childZ, half, order - 1, childOffset, childChunkSize, transitions[i], first, end, baseCorners);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function generateSingleBigInt(points, x, y, z, size, order, index, shift, orientationId, baseCorners) {
|
|
115
|
+
const orientation = ORIENTATIONS[orientationId];
|
|
116
|
+
const child = Number(index >> shift & 7n);
|
|
117
|
+
const actualCorner = baseCorners[orientation[child]];
|
|
118
|
+
const half = size / 2;
|
|
119
|
+
const childX = x + (actualCorner < 4 ? -half : half);
|
|
120
|
+
const childY = y + (actualCorner < 2 || actualCorner > 5 ? half : -half);
|
|
121
|
+
const childZ = z + (actualCorner % 4 === 1 || actualCorner % 4 === 2 ? half : -half);
|
|
122
|
+
if (order === 0) {
|
|
123
|
+
points.push(new Vector3(childX, childY, childZ));
|
|
124
|
+
} else {
|
|
125
|
+
generateSingleBigInt(points, childX, childY, childZ, half, order - 1, index, shift - 3n, ORIENTATION_TRANSITIONS[orientationId][child], baseCorners);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function toBigInt(value) {
|
|
129
|
+
if (typeof value === 'bigint') return value;
|
|
130
|
+
if (!Number.isSafeInteger(value)) throw new TypeError('BigInt ranges require integer values.');
|
|
131
|
+
return BigInt(value);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const SINGLE_CUBE_FACES = [[0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7], [0, 3, 2, 1], [4, 5, 6, 7]];
|
|
135
|
+
const SINGLE_CUBE_CORNERS = [[-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1], [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]];
|
|
136
|
+
const SINGLE_CUBE_UVS = new Float32Array(24 * 2);
|
|
137
|
+
const SINGLE_CUBE_NORMALS = new Float32Array(24 * 3);
|
|
138
|
+
const SINGLE_CUBE_INDICES = new Uint16Array(36);
|
|
139
|
+
const SINGLE_CUBE_NORMALS_BY_FACE = [[0, -1, 0], [1, 0, 0], [0, 1, 0], [-1, 0, 0], [0, 0, -1], [0, 0, 1]];
|
|
140
|
+
for (let faceIndex = 0; faceIndex < SINGLE_CUBE_FACES.length; faceIndex++) {
|
|
141
|
+
const face = SINGLE_CUBE_FACES[faceIndex];
|
|
142
|
+
const normal = SINGLE_CUBE_NORMALS_BY_FACE[faceIndex];
|
|
143
|
+
for (let i = 0; i < 4; i++) {
|
|
144
|
+
const vertex = faceIndex * 4 + i;
|
|
145
|
+
const corner = face[i];
|
|
146
|
+
SINGLE_CUBE_UVS[vertex * 2] = corner % 2;
|
|
147
|
+
SINGLE_CUBE_UVS[vertex * 2 + 1] = Math.floor(corner / 2) % 2;
|
|
148
|
+
SINGLE_CUBE_NORMALS.set(normal, vertex * 3);
|
|
149
|
+
}
|
|
150
|
+
const vertexOffset = faceIndex * 4;
|
|
151
|
+
const indexOffset = faceIndex * 6;
|
|
152
|
+
SINGLE_CUBE_INDICES.set([vertexOffset, vertexOffset + 1, vertexOffset + 2, vertexOffset, vertexOffset + 2, vertexOffset + 3], indexOffset);
|
|
153
|
+
}
|
|
154
|
+
class SquareTubeGeometry extends BufferGeometry {
|
|
155
|
+
constructor(points = [], width = 1) {
|
|
156
|
+
super();
|
|
157
|
+
if (!Array.isArray(points)) {
|
|
158
|
+
throw new TypeError('points must be an array of Vector3 instances');
|
|
159
|
+
}
|
|
160
|
+
if (!Number.isFinite(width) || width < 0) {
|
|
161
|
+
throw new RangeError('width must be a non-negative finite number');
|
|
162
|
+
}
|
|
163
|
+
this.type = 'SquareTubeGeometry';
|
|
164
|
+
if (points.length <= 1) {
|
|
165
|
+
const point = points[0];
|
|
166
|
+
if (points.length === 1 && (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z))) {
|
|
167
|
+
throw new TypeError('points[0] must have finite x, y, and z coordinates');
|
|
168
|
+
}
|
|
169
|
+
this.parameters = {
|
|
170
|
+
points: point ? [new Vector3(point.x, point.y, point.z)] : [],
|
|
171
|
+
width
|
|
172
|
+
};
|
|
173
|
+
if (!point || width === 0) {
|
|
174
|
+
this.setIndex([]);
|
|
175
|
+
this.setAttribute('position', new Float32BufferAttribute([], 3));
|
|
176
|
+
this.setAttribute('uv', new Float32BufferAttribute([], 2));
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const halfWidth = width / 2;
|
|
180
|
+
const x = point.x;
|
|
181
|
+
const y = point.y;
|
|
182
|
+
const z = point.z;
|
|
183
|
+
const positions = new Float32Array(24 * 3);
|
|
184
|
+
let positionOffset = 0;
|
|
185
|
+
for (const face of SINGLE_CUBE_FACES) {
|
|
186
|
+
for (const corner of face) {
|
|
187
|
+
const signs = SINGLE_CUBE_CORNERS[corner];
|
|
188
|
+
positions[positionOffset++] = x + signs[0] * halfWidth;
|
|
189
|
+
positions[positionOffset++] = y + signs[1] * halfWidth;
|
|
190
|
+
positions[positionOffset++] = z + signs[2] * halfWidth;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
this.setIndex(new Uint16BufferAttribute(SINGLE_CUBE_INDICES.slice(), 1));
|
|
194
|
+
this.setAttribute('position', new Float32BufferAttribute(positions, 3));
|
|
195
|
+
this.setAttribute('uv', new Float32BufferAttribute(SINGLE_CUBE_UVS.slice(), 2));
|
|
196
|
+
this.setAttribute('normal', new Float32BufferAttribute(SINGLE_CUBE_NORMALS.slice(), 3));
|
|
197
|
+
this.boundingBox = new Box3(new Vector3(x - halfWidth, y - halfWidth, z - halfWidth), new Vector3(x + halfWidth, y + halfWidth, z + halfWidth));
|
|
198
|
+
this.boundingSphere = new Sphere(new Vector3(x, y, z), Math.sqrt(3) * halfWidth);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const path = points.map((point, index) => {
|
|
202
|
+
if (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z)) {
|
|
203
|
+
throw new TypeError(`points[${index}] must have finite x, y, and z coordinates`);
|
|
204
|
+
}
|
|
205
|
+
return new Vector3(point.x, point.y, point.z);
|
|
206
|
+
}).filter((point, index, list) => index === 0 || point.distanceToSquared(list[index - 1]) > 0);
|
|
207
|
+
this.parameters = {
|
|
208
|
+
points: path.map(point => point.clone()),
|
|
209
|
+
width
|
|
210
|
+
};
|
|
211
|
+
if (path.length === 0 || width === 0) {
|
|
212
|
+
this.setIndex([]);
|
|
213
|
+
this.setAttribute('position', new Float32BufferAttribute([], 3));
|
|
214
|
+
this.setAttribute('uv', new Float32BufferAttribute([], 2));
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const directions = path.slice(1).map((point, index) => point.clone().sub(path[index]).normalize());
|
|
218
|
+
const turnTolerance = 1e-6;
|
|
219
|
+
let turnCount = 0;
|
|
220
|
+
for (let i = 1; i < directions.length; i++) {
|
|
221
|
+
const dot = directions[i - 1].dot(directions[i]);
|
|
222
|
+
const isRightAngle = Math.abs(dot) <= turnTolerance;
|
|
223
|
+
const continuesStraight = dot >= 1 - turnTolerance;
|
|
224
|
+
if (!isRightAngle && !continuesStraight) {
|
|
225
|
+
throw new RangeError('path turns must be 90 degrees; straight segments are also allowed');
|
|
226
|
+
}
|
|
227
|
+
if (isRightAngle) turnCount++;
|
|
228
|
+
}
|
|
229
|
+
const halfWidth = width / 2;
|
|
230
|
+
const frames = [];
|
|
231
|
+
const normal = new Vector3();
|
|
232
|
+
const binormal = new Vector3();
|
|
233
|
+
const rotation = new Quaternion();
|
|
234
|
+
for (let i = 0; i < directions.length; i++) {
|
|
235
|
+
if (i === 0) {
|
|
236
|
+
const tangent = directions[i];
|
|
237
|
+
const absX = Math.abs(tangent.x);
|
|
238
|
+
const absY = Math.abs(tangent.y);
|
|
239
|
+
const absZ = Math.abs(tangent.z);
|
|
240
|
+
normal.set(absX <= absY && absX <= absZ ? 1 : 0, absY < absX && absY <= absZ ? 1 : 0, absZ < absX && absZ < absY ? 1 : 0);
|
|
241
|
+
normal.addScaledVector(tangent, -normal.dot(tangent)).normalize();
|
|
242
|
+
} else {
|
|
243
|
+
rotation.setFromUnitVectors(directions[i - 1], directions[i]);
|
|
244
|
+
normal.applyQuaternion(rotation);
|
|
245
|
+
normal.addScaledVector(directions[i], -normal.dot(directions[i])).normalize();
|
|
246
|
+
}
|
|
247
|
+
binormal.crossVectors(directions[i], normal).normalize();
|
|
248
|
+
frames.push({
|
|
249
|
+
normal: normal.clone(),
|
|
250
|
+
binormal: binormal.clone()
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
const faces = [[0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7], [0, 3, 2, 1], [4, 5, 6, 7]];
|
|
254
|
+
const solidCount = path.length === 1 ? 1 : directions.length + turnCount;
|
|
255
|
+
const positions = new Float32Array(solidCount * 24 * 3);
|
|
256
|
+
const uvs = new Float32Array(solidCount * 24 * 2);
|
|
257
|
+
const use32BitIndices = solidCount * 24 > 65535;
|
|
258
|
+
const IndexAttribute = use32BitIndices ? Uint32BufferAttribute : Uint16BufferAttribute;
|
|
259
|
+
const indices = use32BitIndices ? new Uint32Array(solidCount * 36) : new Uint16Array(solidCount * 36);
|
|
260
|
+
let positionOffset = 0;
|
|
261
|
+
let uvOffset = 0;
|
|
262
|
+
let vertexOffset = 0;
|
|
263
|
+
let indexOffset = 0;
|
|
264
|
+
function addSolid(corners) {
|
|
265
|
+
for (const face of faces) {
|
|
266
|
+
for (const cornerIndex of face) {
|
|
267
|
+
const point = corners[cornerIndex];
|
|
268
|
+
positions[positionOffset++] = point.x;
|
|
269
|
+
positions[positionOffset++] = point.y;
|
|
270
|
+
positions[positionOffset++] = point.z;
|
|
271
|
+
uvs[uvOffset++] = cornerIndex % 2;
|
|
272
|
+
uvs[uvOffset++] = Math.floor(cornerIndex / 2) % 2;
|
|
273
|
+
}
|
|
274
|
+
indices[indexOffset++] = vertexOffset;
|
|
275
|
+
indices[indexOffset++] = vertexOffset + 1;
|
|
276
|
+
indices[indexOffset++] = vertexOffset + 2;
|
|
277
|
+
indices[indexOffset++] = vertexOffset;
|
|
278
|
+
indices[indexOffset++] = vertexOffset + 2;
|
|
279
|
+
indices[indexOffset++] = vertexOffset + 3;
|
|
280
|
+
vertexOffset += 4;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (path.length === 1) {
|
|
284
|
+
const [x, y, z] = path[0].toArray();
|
|
285
|
+
addSolid([new Vector3(x - halfWidth, y - halfWidth, z - halfWidth), new Vector3(x + halfWidth, y - halfWidth, z - halfWidth), new Vector3(x + halfWidth, y + halfWidth, z - halfWidth), new Vector3(x - halfWidth, y + halfWidth, z - halfWidth), new Vector3(x - halfWidth, y - halfWidth, z + halfWidth), new Vector3(x + halfWidth, y - halfWidth, z + halfWidth), new Vector3(x + halfWidth, y + halfWidth, z + halfWidth), new Vector3(x - halfWidth, y + halfWidth, z + halfWidth)]);
|
|
286
|
+
this.setIndex(new IndexAttribute(indices, 1));
|
|
287
|
+
this.setAttribute('position', new Float32BufferAttribute(positions, 3));
|
|
288
|
+
this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
|
|
289
|
+
this.computeVertexNormals();
|
|
290
|
+
this.computeBoundingBox();
|
|
291
|
+
this.computeBoundingSphere();
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
for (let i = 0; i < directions.length; i++) {
|
|
295
|
+
const direction = directions[i];
|
|
296
|
+
const start = path[i].clone();
|
|
297
|
+
const end = path[i + 1].clone();
|
|
298
|
+
if (i === 0) start.addScaledVector(direction, -halfWidth);
|
|
299
|
+
if (i === directions.length - 1) end.addScaledVector(direction, halfWidth);
|
|
300
|
+
const sectionCorners = center => [center.clone().addScaledVector(frames[i].normal, halfWidth).addScaledVector(frames[i].binormal, halfWidth), center.clone().addScaledVector(frames[i].normal, -halfWidth).addScaledVector(frames[i].binormal, halfWidth), center.clone().addScaledVector(frames[i].normal, -halfWidth).addScaledVector(frames[i].binormal, -halfWidth), center.clone().addScaledVector(frames[i].normal, halfWidth).addScaledVector(frames[i].binormal, -halfWidth)];
|
|
301
|
+
addSolid([...sectionCorners(start), ...sectionCorners(end)]);
|
|
302
|
+
}
|
|
303
|
+
for (let i = 1; i < path.length - 1; i++) {
|
|
304
|
+
if (Math.abs(directions[i - 1].dot(directions[i])) <= turnTolerance) {
|
|
305
|
+
const [x, y, z] = path[i].toArray();
|
|
306
|
+
addSolid([new Vector3(x - halfWidth, y - halfWidth, z - halfWidth), new Vector3(x + halfWidth, y - halfWidth, z - halfWidth), new Vector3(x + halfWidth, y + halfWidth, z - halfWidth), new Vector3(x - halfWidth, y + halfWidth, z - halfWidth), new Vector3(x - halfWidth, y - halfWidth, z + halfWidth), new Vector3(x + halfWidth, y - halfWidth, z + halfWidth), new Vector3(x + halfWidth, y + halfWidth, z + halfWidth), new Vector3(x - halfWidth, y + halfWidth, z + halfWidth)]);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
this.setIndex(new IndexAttribute(indices, 1));
|
|
310
|
+
this.setAttribute('position', new Float32BufferAttribute(positions, 3));
|
|
311
|
+
this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
|
|
312
|
+
this.computeVertexNormals();
|
|
313
|
+
this.computeBoundingBox();
|
|
314
|
+
this.computeBoundingSphere();
|
|
315
|
+
}
|
|
316
|
+
copy(source) {
|
|
317
|
+
super.copy(source);
|
|
318
|
+
this.parameters = {
|
|
319
|
+
points: source.parameters.points.map(point => point.clone()),
|
|
320
|
+
width: source.parameters.width
|
|
321
|
+
};
|
|
322
|
+
return this;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
class ThreeHilbertGeometry extends SquareTubeGeometry {
|
|
327
|
+
constructor(order, start, length, {
|
|
328
|
+
padding = 0,
|
|
329
|
+
simplifyCurves = true
|
|
330
|
+
} = {}) {
|
|
331
|
+
super(...getSuperParams());
|
|
332
|
+
this.type = 'HilbertGeometry';
|
|
333
|
+
function getSuperParams() {
|
|
334
|
+
typeof start !== 'bigint' && (start = Math.round(start));
|
|
335
|
+
typeof length !== 'bigint' && (length = Math.round(length));
|
|
336
|
+
if (simplifyCurves) {
|
|
337
|
+
// resolution simplification
|
|
338
|
+
const n8 = typeof start === 'bigint' ? 8n : 8;
|
|
339
|
+
while (!(start % n8) && !(length % n8) && order > 0) {
|
|
340
|
+
start /= n8;
|
|
341
|
+
length /= n8;
|
|
342
|
+
order -= 1;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const points = hilbert3D(undefined, 1, order - 1, start, length);
|
|
346
|
+
const lineWidth = 1 / 2 ** (order - 1) * (1 - Math.min(1, padding));
|
|
347
|
+
return [points, lineWidth];
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/*
|
|
353
|
+
const geometryCache = (() => {
|
|
354
|
+
const cache = {};
|
|
355
|
+
cache[''] = new SquareTubeGeometry([new Vector3()]);
|
|
356
|
+
for (const nPnts of [2, 4]) {
|
|
357
|
+
for (let start = 0; start < 8; start++) {
|
|
358
|
+
const pnts = hilbert3D(undefined, 1, 0, start, nPnts);
|
|
359
|
+
const key = getCurvePath(pnts);
|
|
360
|
+
cache[key] = new SquareTubeGeometry(pnts);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return cache;
|
|
364
|
+
})();
|
|
365
|
+
|
|
366
|
+
// console.log(geometryCache);
|
|
367
|
+
|
|
368
|
+
function genInstancedGeometry(order, start, length, {
|
|
369
|
+
padding = 0,
|
|
370
|
+
simplifyCurves
|
|
371
|
+
} = {}) {
|
|
372
|
+
// resolution simplification
|
|
373
|
+
const n8 = typeof start === 'bigint' ? 8n : 8;
|
|
374
|
+
while (!(start % n8) && !(length % n8) && order > 0) {
|
|
375
|
+
start /= n8;
|
|
376
|
+
length /= n8;
|
|
377
|
+
order -= 1;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const points = hilbert3D(undefined, 1, order - 1, start, length);
|
|
381
|
+
|
|
382
|
+
let geometry;
|
|
383
|
+
let position = new Vector3();
|
|
384
|
+
let scale = 1;
|
|
385
|
+
|
|
386
|
+
if ([1, 2, 4].some(l => l === points.length)) {
|
|
387
|
+
// Most common simple cases
|
|
388
|
+
const key = getCurvePath(points);
|
|
389
|
+
geometry = geometryCache[key];
|
|
390
|
+
} else {
|
|
391
|
+
// More complex cases, fallback to regular geometry generation
|
|
392
|
+
geometry = new ThreeHilbertGeometry(order, start, length, { padding, simplifyCurves });
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return {
|
|
396
|
+
geometry,
|
|
397
|
+
position,
|
|
398
|
+
scale,
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function getCurvePath(points) {
|
|
403
|
+
const path = [];
|
|
404
|
+
let prevPnt = points[0];
|
|
405
|
+
|
|
406
|
+
for (let i = 1; i < points.length; i++) {
|
|
407
|
+
const pnt = points[i];
|
|
408
|
+
for (const c of ['x', 'y', 'z']) {
|
|
409
|
+
const dist = pnt[c] - prevPnt[c];
|
|
410
|
+
if (dist) {
|
|
411
|
+
path.push(
|
|
412
|
+
c === 'x' ? dist > 0 ? 'R' : 'L'
|
|
413
|
+
: c === 'y' ? dist > 0 ? 'U' : 'D'
|
|
414
|
+
: dist > 0 ? 'B' : 'F'
|
|
415
|
+
);
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
prevPnt = pnt;
|
|
420
|
+
}
|
|
421
|
+
return path.join('');
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
*/
|
|
425
|
+
|
|
426
|
+
export { ThreeHilbertGeometry as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "three-hilbert-geometry",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "ThreeJS geometry for drawing a Hilbert curve segment",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"unpkg": "dist/three-hilbert-geometry.min.js",
|
|
7
|
+
"main": "dist/three-hilbert-geometry.mjs",
|
|
8
|
+
"module": "dist/three-hilbert-geometry.mjs",
|
|
9
|
+
"types": "dist/three-hilbert-geometry.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
"types": "./dist/three-hilbert-geometry.d.ts",
|
|
12
|
+
"umd": "./dist/three-hilbert-geometry.min.js",
|
|
13
|
+
"default": "./dist/three-hilbert-geometry.mjs"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/vasturiano/three-hilbert-geometry",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/vasturiano/three-hilbert-geometry.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/vasturiano/three-hilbert-geometry/issues"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"keywords": [
|
|
25
|
+
"3d",
|
|
26
|
+
"three",
|
|
27
|
+
"hilbert",
|
|
28
|
+
"webgl"
|
|
29
|
+
],
|
|
30
|
+
"author": {
|
|
31
|
+
"name": "Vasco Asturiano",
|
|
32
|
+
"url": "https://github.com/vasturiano"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist/**/*"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "rimraf dist && rollup -c",
|
|
39
|
+
"dev": "rollup -w -c",
|
|
40
|
+
"prepare": "npm run build"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"three": ">=0.72.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@babel/core": "^8.1.0",
|
|
48
|
+
"@babel/preset-env": "^8.0.7",
|
|
49
|
+
"@rollup/plugin-babel": "^7.1.0",
|
|
50
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
51
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
52
|
+
"@rollup/plugin-terser": "^1.0.2",
|
|
53
|
+
"@types/three": ">=0.72.0",
|
|
54
|
+
"@typescript/typescript6": "^6.0.2",
|
|
55
|
+
"rimraf": "^6.1.4",
|
|
56
|
+
"rollup": "^4.68.0",
|
|
57
|
+
"rollup-plugin-dts": "^6.5.1",
|
|
58
|
+
"typescript": "^7.0.2"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=12"
|
|
62
|
+
}
|
|
63
|
+
}
|