@3driseai/3drise-viewer 0.1.1 → 0.1.2
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.
|
@@ -24,14 +24,11 @@ export interface GeometryMeshProps {
|
|
|
24
24
|
/** Material for the solid path (defaults to a standard material). */
|
|
25
25
|
children?: ReactNode;
|
|
26
26
|
}
|
|
27
|
-
export declare function useShapeGeometry(options: GeometryShapeConfig): BufferGeometry;
|
|
28
|
-
/** interior fill via point-in-mesh ray-parity (closed meshes only) */
|
|
27
|
+
export declare function useShapeGeometry(options: GeometryShapeConfig | null | undefined): BufferGeometry;
|
|
29
28
|
export declare function volumeFill(geo: BufferGeometry, count: number, oversample?: number): Float32Array;
|
|
30
29
|
/** area-weighted points on the skin — the keystone for the modes below */
|
|
31
30
|
export declare function surfaceScatter(geo: BufferGeometry, count: number): Float32Array;
|
|
32
|
-
/** fold into one wedge, mirror, rotate-copy around Z → kaleidoscope */
|
|
33
31
|
export declare function symmetricScatter(geo: BufferGeometry, count: number, sym: number): Float32Array;
|
|
34
|
-
/** blue-noise: oversample then reject anything closer than minDist (grid-hashed) */
|
|
35
32
|
export declare function evenScatter(geo: BufferGeometry, count: number, spacing: number): Float32Array;
|
|
36
33
|
export declare function meshVertices(geo: BufferGeometry): Float32Array;
|
|
37
34
|
export declare function edges3D(geo: BufferGeometry, angleDeg: number): Pt[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeometryShape.d.ts","sourceRoot":"","sources":["../../src/components/GeometryShape.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"GeometryShape.d.ts","sourceRoot":"","sources":["../../src/components/GeometryShape.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE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jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useEffect, useMemo } from 'react';
|
|
3
3
|
import { EdgesGeometry, WireframeGeometry, Mesh, MeshBasicMaterial, Raycaster, Vector3, DoubleSide, } from 'three';
|
|
4
4
|
import { Line } from '@react-three/drei';
|
|
5
|
-
// ── Wire these to your project ───────────────────────────────────────────────
|
|
6
5
|
import { shapeGenerators } from '../utils/shapes.js';
|
|
7
6
|
import PointCloud from './PointCloud.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const defaultModeConfig = {
|
|
8
|
+
mode: 'solid',
|
|
9
|
+
count: 1000,
|
|
10
|
+
symmetry: 3,
|
|
11
|
+
spacing: 0.1,
|
|
12
|
+
slices: 8,
|
|
13
|
+
linkRadius: 0.05,
|
|
14
|
+
angle: 18,
|
|
15
|
+
lineWidth: 1,
|
|
16
|
+
};
|
|
17
|
+
function normalizeShapeConfig(config) {
|
|
18
|
+
if (config && typeof config === 'object' && typeof config.type === 'string' && config.type in shapeGenerators) {
|
|
19
|
+
return config;
|
|
20
|
+
}
|
|
21
|
+
return { type: 'box' };
|
|
22
|
+
}
|
|
23
|
+
function normalizeModeConfig(config) {
|
|
24
|
+
return {
|
|
25
|
+
...defaultModeConfig,
|
|
26
|
+
...(config || {}),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
12
29
|
export function useShapeGeometry(options) {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
30
|
+
const safeOptions = useMemo(() => normalizeShapeConfig(options), [options]);
|
|
31
|
+
const key = JSON.stringify(safeOptions);
|
|
32
|
+
const geometry = useMemo(() => {
|
|
33
|
+
const generator = shapeGenerators[safeOptions.type] ?? shapeGenerators.box;
|
|
34
|
+
return generator(safeOptions);
|
|
35
|
+
}, [safeOptions.type, key]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
15
36
|
useEffect(() => () => geometry.dispose(), [geometry]);
|
|
16
37
|
return geometry;
|
|
17
38
|
}
|
|
@@ -41,10 +62,6 @@ function toPairs(arr) {
|
|
|
41
62
|
out.push([arr[i], arr[i + 1], arr[i + 2]]);
|
|
42
63
|
return out;
|
|
43
64
|
}
|
|
44
|
-
/* â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
|
|
45
|
-
* POINT transforms → Float32Array of xyz.
|
|
46
|
-
* â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â• */
|
|
47
|
-
/** interior fill via point-in-mesh ray-parity (closed meshes only) */
|
|
48
65
|
export function volumeFill(geo, count, oversample = 80) {
|
|
49
66
|
const probe = new Mesh(geo, new MeshBasicMaterial({ side: DoubleSide }));
|
|
50
67
|
probe.updateMatrixWorld(true);
|
|
@@ -106,7 +123,6 @@ export function surfaceScatter(geo, count) {
|
|
|
106
123
|
}
|
|
107
124
|
return out;
|
|
108
125
|
}
|
|
109
|
-
/** fold into one wedge, mirror, rotate-copy around Z → kaleidoscope */
|
|
110
126
|
export function symmetricScatter(geo, count, sym) {
|
|
111
127
|
const base = surfaceScatter(geo, Math.max(1, Math.floor(count / (2 * sym))));
|
|
112
128
|
const w = (Math.PI * 2) / sym;
|
|
@@ -125,7 +141,6 @@ export function symmetricScatter(geo, count, sym) {
|
|
|
125
141
|
}
|
|
126
142
|
return new Float32Array(out);
|
|
127
143
|
}
|
|
128
|
-
/** blue-noise: oversample then reject anything closer than minDist (grid-hashed) */
|
|
129
144
|
export function evenScatter(geo, count, spacing) {
|
|
130
145
|
const cand = surfaceScatter(geo, count * 6);
|
|
131
146
|
const minD = (spacing * bboxDiag(geo)) / Math.sqrt(count);
|
|
@@ -169,9 +184,6 @@ export function meshVertices(geo) {
|
|
|
169
184
|
}
|
|
170
185
|
return out;
|
|
171
186
|
}
|
|
172
|
-
/* â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
|
|
173
|
-
* LINE transforms → segment endpoint pairs (Pt[]).
|
|
174
|
-
* â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â• */
|
|
175
187
|
export function edges3D(geo, angleDeg) {
|
|
176
188
|
const e = new EdgesGeometry(geo, angleDeg);
|
|
177
189
|
const pts = toPairs(e.attributes.position.array);
|
|
@@ -228,9 +240,6 @@ export function contourSlices(geo, slices, axis = 1) {
|
|
|
228
240
|
}
|
|
229
241
|
return out;
|
|
230
242
|
}
|
|
231
|
-
/* â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
|
|
232
|
-
* PLEXUS → points + links to near neighbours.
|
|
233
|
-
* â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â• */
|
|
234
243
|
export function plexus(geo, count, radiusMul, maxLinks = 6) {
|
|
235
244
|
const pts = surfaceScatter(geo, count);
|
|
236
245
|
const n = pts.length / 3;
|
|
@@ -288,24 +297,23 @@ export function computeMode(geo, c) {
|
|
|
288
297
|
}
|
|
289
298
|
}
|
|
290
299
|
function useModeData(geometry, config) {
|
|
291
|
-
|
|
292
|
-
const key = [
|
|
293
|
-
return useMemo(() => computeMode(geometry,
|
|
300
|
+
const safeConfig = normalizeModeConfig(config);
|
|
301
|
+
const key = [safeConfig.mode, safeConfig.count, safeConfig.symmetry, safeConfig.spacing, safeConfig.slices, safeConfig.linkRadius, safeConfig.angle].join('|');
|
|
302
|
+
return useMemo(() => computeMode(geometry, safeConfig), [geometry, key]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
294
303
|
}
|
|
295
|
-
const defaultModeConfig = { mode: 'solid', count: 1000, symmetry: 3, spacing: 0.1, slices: 8, linkRadius: 0.05, angle: 18, lineWidth: 1 };
|
|
296
304
|
export function GeometryMesh({ config, materialSettings, animations, modeConfig = defaultModeConfig, color = '#ffffff', children }) {
|
|
297
305
|
const geometry = useShapeGeometry(config);
|
|
298
|
-
const
|
|
306
|
+
const safeModeConfig = normalizeModeConfig(modeConfig);
|
|
307
|
+
const data = useModeData(geometry, safeModeConfig);
|
|
299
308
|
// if (data.kind === 'points') return <PointCloud positions={data.positions} color={color} size={modeConfig.mode === 'vertices' ? 0.035 : 0.02} />;
|
|
300
309
|
if (data.kind === 'points')
|
|
301
310
|
return _jsx(PointCloud, { positions: data.positions, animations: animations, materialSettings: materialSettings });
|
|
302
311
|
if (data.kind === 'lines')
|
|
303
|
-
return data.points.length ? _jsx(Line, { points: data.points, segments: true, color: color, lineWidth:
|
|
312
|
+
return data.points.length ? _jsx(Line, { points: data.points, segments: true, color: color, lineWidth: safeModeConfig.lineWidth }) : null;
|
|
304
313
|
if (data.kind === 'plexus')
|
|
305
|
-
return (_jsxs("group", { children: [_jsx(PointCloud, { positions: data.positions, animations: animations, materialSettings: materialSettings }), data.segments.length > 0 && _jsx(Line, { points: data.segments, segments: true, color: color, lineWidth:
|
|
314
|
+
return (_jsxs("group", { children: [_jsx(PointCloud, { positions: data.positions, animations: animations, materialSettings: materialSettings }), data.segments.length > 0 && _jsx(Line, { points: data.segments, segments: true, color: color, lineWidth: safeModeConfig.lineWidth, transparent: true, opacity: 0.45 })] }));
|
|
306
315
|
return (_jsx("mesh", { geometry: geometry, children: children ?? _jsx("meshPhongMaterial", { color: color, side: DoubleSide }) }));
|
|
307
316
|
}
|
|
308
|
-
/* ── Optional host-owned auto-fit (generators return raw geometry). ── */
|
|
309
317
|
export function FitGroup({ geometry, radius = 1.7, children }) {
|
|
310
318
|
const { scale, position } = useMemo(() => {
|
|
311
319
|
geometry.computeBoundingSphere();
|