matterviz 0.3.2 → 0.3.3
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/dist/EmptyState.svelte +10 -2
- package/dist/FilePicker.svelte +123 -82
- package/dist/Icon.svelte +18 -12
- package/dist/MillerIndexInput.svelte +27 -21
- package/dist/api/optimade.js +6 -6
- package/dist/app.css +216 -207
- package/dist/brillouin/BrillouinZone.svelte +292 -149
- package/dist/brillouin/BrillouinZone.svelte.d.ts +1 -1
- package/dist/brillouin/BrillouinZoneControls.svelte +32 -5
- package/dist/brillouin/BrillouinZoneExportPane.svelte +69 -42
- package/dist/brillouin/BrillouinZoneExportPane.svelte.d.ts +1 -1
- package/dist/brillouin/BrillouinZoneInfoPane.svelte +99 -68
- package/dist/brillouin/BrillouinZoneScene.svelte +275 -163
- package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +1 -1
- package/dist/brillouin/BrillouinZoneTooltip.svelte +17 -7
- package/dist/brillouin/compute.js +11 -6
- package/dist/chempot-diagram/ChemPotDiagram.svelte +162 -27
- package/dist/chempot-diagram/ChemPotDiagram2D.svelte +451 -281
- package/dist/chempot-diagram/ChemPotDiagram3D.svelte +2148 -1642
- package/dist/chempot-diagram/ChemPotScene3D.svelte +8 -5
- package/dist/chempot-diagram/async-compute.svelte.d.ts +3 -0
- package/dist/chempot-diagram/async-compute.svelte.js +77 -0
- package/dist/chempot-diagram/chempot-worker.d.ts +1 -0
- package/dist/chempot-diagram/chempot-worker.js +11 -0
- package/dist/chempot-diagram/color.js +1 -2
- package/dist/chempot-diagram/compute.d.ts +10 -0
- package/dist/chempot-diagram/compute.js +250 -88
- package/dist/chempot-diagram/index.d.ts +2 -1
- package/dist/chempot-diagram/index.js +2 -1
- package/dist/chempot-diagram/temperature.js +8 -9
- package/dist/chempot-diagram/types.d.ts +3 -0
- package/dist/chempot-diagram/types.js +1 -0
- package/dist/colors/index.d.ts +1 -1
- package/dist/colors/index.js +5 -3
- package/dist/composition/BarChart.svelte +128 -55
- package/dist/composition/BubbleChart.svelte +102 -49
- package/dist/composition/Composition.svelte +100 -79
- package/dist/composition/Formula.svelte +108 -62
- package/dist/composition/FormulaFilter.svelte +665 -537
- package/dist/composition/PieChart.svelte +183 -108
- package/dist/composition/format.d.ts +5 -0
- package/dist/composition/format.js +20 -3
- package/dist/composition/parse.js +14 -9
- package/dist/convex-hull/ConvexHull.svelte +93 -40
- package/dist/convex-hull/ConvexHull.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHull2D.svelte +549 -360
- package/dist/convex-hull/ConvexHull2D.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHull3D.svelte +1296 -827
- package/dist/convex-hull/ConvexHull3D.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHull4D.svelte +1004 -688
- package/dist/convex-hull/ConvexHull4D.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHullControls.svelte +115 -28
- package/dist/convex-hull/ConvexHullControls.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHullInfoPane.svelte +29 -3
- package/dist/convex-hull/ConvexHullStats.svelte +425 -328
- package/dist/convex-hull/ConvexHullTooltip.svelte +40 -16
- package/dist/convex-hull/GasPressureControls.svelte +104 -61
- package/dist/convex-hull/StructurePopup.svelte +25 -4
- package/dist/convex-hull/TemperatureSlider.svelte +45 -25
- package/dist/convex-hull/barycentric-coords.js +13 -7
- package/dist/convex-hull/demo-temperature.js +8 -4
- package/dist/convex-hull/gas-thermodynamics.js +17 -12
- package/dist/convex-hull/helpers.d.ts +9 -0
- package/dist/convex-hull/helpers.js +77 -34
- package/dist/convex-hull/thermodynamics.js +61 -56
- package/dist/convex-hull/types.d.ts +9 -14
- package/dist/convex-hull/types.js +0 -17
- package/dist/coordination/CoordinationBarPlot.svelte +227 -154
- package/dist/element/BohrAtom.svelte +55 -12
- package/dist/element/ElementHeading.svelte +7 -2
- package/dist/element/ElementPhoto.svelte +15 -9
- package/dist/element/ElementStats.svelte +10 -4
- package/dist/element/ElementTile.svelte +137 -73
- package/dist/element/Nucleus.svelte +39 -11
- package/dist/feedback/ClickFeedback.svelte +16 -5
- package/dist/feedback/DragOverlay.svelte +10 -2
- package/dist/feedback/Spinner.svelte +4 -2
- package/dist/feedback/StatusMessage.svelte +8 -2
- package/dist/fermi-surface/FermiSlice.svelte +118 -88
- package/dist/fermi-surface/FermiSurface.svelte +328 -187
- package/dist/fermi-surface/FermiSurface.svelte.d.ts +1 -1
- package/dist/fermi-surface/FermiSurfaceControls.svelte +113 -46
- package/dist/fermi-surface/FermiSurfaceControls.svelte.d.ts +1 -1
- package/dist/fermi-surface/FermiSurfaceScene.svelte +535 -342
- package/dist/fermi-surface/FermiSurfaceScene.svelte.d.ts +1 -1
- package/dist/fermi-surface/FermiSurfaceTooltip.svelte +14 -5
- package/dist/fermi-surface/compute.js +16 -20
- package/dist/fermi-surface/parse.js +24 -14
- package/dist/fermi-surface/symmetry.js +2 -7
- package/dist/fermi-surface/types.d.ts +3 -5
- package/dist/heatmap-matrix/HeatmapMatrix.svelte +1019 -765
- package/dist/heatmap-matrix/HeatmapMatrix.svelte.d.ts +1 -1
- package/dist/heatmap-matrix/HeatmapMatrixControls.svelte +76 -22
- package/dist/heatmap-matrix/HeatmapMatrixControls.svelte.d.ts +2 -3
- package/dist/icons.js +47 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/io/decompress.js +1 -1
- package/dist/io/export.d.ts +3 -0
- package/dist/io/export.js +129 -143
- package/dist/io/is-binary.js +2 -3
- package/dist/io/url-drop.js +1 -2
- package/dist/isosurface/Isosurface.svelte +202 -148
- package/dist/isosurface/IsosurfaceControls.svelte +46 -28
- package/dist/isosurface/parse.js +34 -29
- package/dist/isosurface/slice.js +5 -10
- package/dist/isosurface/types.d.ts +2 -1
- package/dist/isosurface/types.js +61 -12
- package/dist/labels.js +11 -8
- package/dist/layout/FullscreenToggle.svelte +11 -2
- package/dist/layout/InfoCard.svelte +38 -6
- package/dist/layout/InfoTag.svelte +63 -32
- package/dist/layout/PropertyFilter.svelte +82 -37
- package/dist/layout/SettingsSection.svelte +85 -55
- package/dist/layout/SubpageGrid.svelte +10 -2
- package/dist/layout/json-tree/JsonNode.svelte +183 -138
- package/dist/layout/json-tree/JsonTree.svelte +499 -413
- package/dist/layout/json-tree/JsonValue.svelte +127 -99
- package/dist/layout/json-tree/utils.js +4 -2
- package/dist/marching-cubes.js +25 -2
- package/dist/math.d.ts +13 -17
- package/dist/math.js +133 -67
- package/dist/overlays/ContextMenu.svelte +65 -40
- package/dist/overlays/DraggablePane.svelte +211 -139
- package/dist/periodic-table/PeriodicTable.svelte +278 -145
- package/dist/periodic-table/PeriodicTableControls.svelte +178 -128
- package/dist/periodic-table/PropertySelect.svelte +25 -7
- package/dist/periodic-table/TableInset.svelte +8 -3
- package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte +446 -309
- package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +1 -1
- package/dist/phase-diagram/PhaseDiagramControls.svelte +102 -43
- package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +1 -1
- package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +63 -40
- package/dist/phase-diagram/PhaseDiagramExportPane.svelte +71 -28
- package/dist/phase-diagram/PhaseDiagramExportPane.svelte.d.ts +1 -1
- package/dist/phase-diagram/PhaseDiagramTooltip.svelte +158 -101
- package/dist/phase-diagram/TdbInfoPanel.svelte +28 -4
- package/dist/phase-diagram/build-diagram.js +9 -9
- package/dist/phase-diagram/colors.js +1 -3
- package/dist/phase-diagram/parse.js +10 -9
- package/dist/phase-diagram/svg-to-diagram.js +53 -49
- package/dist/phase-diagram/utils.d.ts +1 -0
- package/dist/phase-diagram/utils.js +80 -25
- package/dist/plot/AxisLabel.svelte +28 -3
- package/dist/plot/BarPlot.svelte +1182 -734
- package/dist/plot/BarPlot.svelte.d.ts +2 -2
- package/dist/plot/BarPlotControls.svelte +31 -5
- package/dist/plot/BarPlotControls.svelte.d.ts +1 -1
- package/dist/plot/ColorBar.svelte +479 -329
- package/dist/plot/ColorScaleSelect.svelte +27 -6
- package/dist/plot/ElementScatter.svelte +36 -15
- package/dist/plot/FillArea.svelte +152 -95
- package/dist/plot/Histogram.svelte +934 -571
- package/dist/plot/Histogram.svelte.d.ts +1 -1
- package/dist/plot/HistogramControls.svelte +53 -9
- package/dist/plot/HistogramControls.svelte.d.ts +1 -1
- package/dist/plot/InteractiveAxisLabel.svelte +34 -11
- package/dist/plot/InteractiveAxisLabel.svelte.d.ts +1 -1
- package/dist/plot/Line.svelte +63 -28
- package/dist/plot/PlotControls.svelte +157 -114
- package/dist/plot/PlotControls.svelte.d.ts +1 -1
- package/dist/plot/PlotLegend.svelte +174 -91
- package/dist/plot/PlotTooltip.svelte +45 -6
- package/dist/plot/PortalSelect.svelte +175 -147
- package/dist/plot/ReferenceLine.svelte +76 -22
- package/dist/plot/ReferenceLine3D.svelte +132 -107
- package/dist/plot/ReferencePlane.svelte +146 -121
- package/dist/plot/ScatterPlot.svelte +1681 -1091
- package/dist/plot/ScatterPlot.svelte.d.ts +2 -2
- package/dist/plot/ScatterPlot3D.svelte +256 -131
- package/dist/plot/ScatterPlot3D.svelte.d.ts +2 -2
- package/dist/plot/ScatterPlot3DControls.svelte +113 -63
- package/dist/plot/ScatterPlot3DControls.svelte.d.ts +2 -1
- package/dist/plot/ScatterPlot3DScene.svelte +608 -403
- package/dist/plot/ScatterPlot3DScene.svelte.d.ts +2 -2
- package/dist/plot/ScatterPlotControls.svelte +65 -25
- package/dist/plot/ScatterPlotControls.svelte.d.ts +1 -1
- package/dist/plot/ScatterPoint.svelte +98 -26
- package/dist/plot/ScatterPoint.svelte.d.ts +1 -0
- package/dist/plot/SpacegroupBarPlot.svelte +142 -85
- package/dist/plot/Surface3D.svelte +159 -108
- package/dist/plot/ZeroLines.svelte +55 -3
- package/dist/plot/ZoomRect.svelte +4 -2
- package/dist/plot/axis-utils.js +1 -3
- package/dist/plot/data-cleaning.js +12 -28
- package/dist/plot/data-transform.js +2 -1
- package/dist/plot/fill-utils.js +2 -0
- package/dist/plot/layout.d.ts +4 -1
- package/dist/plot/layout.js +33 -14
- package/dist/plot/reference-line.d.ts +2 -2
- package/dist/plot/reference-line.js +7 -5
- package/dist/plot/scales.js +24 -36
- package/dist/plot/types.d.ts +11 -23
- package/dist/plot/types.js +6 -11
- package/dist/plot/utils/label-placement.d.ts +32 -15
- package/dist/plot/utils/label-placement.js +227 -66
- package/dist/plot/utils/series-visibility.js +2 -3
- package/dist/rdf/RdfPlot.svelte +143 -91
- package/dist/rdf/calc-rdf.js +4 -5
- package/dist/sanitize.d.ts +4 -0
- package/dist/sanitize.js +107 -0
- package/dist/settings.d.ts +18 -6
- package/dist/settings.js +46 -16
- package/dist/spectral/Bands.svelte +632 -453
- package/dist/spectral/BandsAndDos.svelte +90 -49
- package/dist/spectral/BrillouinBandsDos.svelte +151 -93
- package/dist/spectral/Dos.svelte +389 -258
- package/dist/spectral/helpers.js +55 -43
- package/dist/state.svelte.d.ts +1 -1
- package/dist/state.svelte.js +3 -2
- package/dist/structure/Arrow.svelte +59 -20
- package/dist/structure/AtomLegend.svelte +215 -134
- package/dist/structure/Bond.svelte +73 -47
- package/dist/structure/CanvasTooltip.svelte +10 -2
- package/dist/structure/CellSelect.svelte +72 -45
- package/dist/structure/Cylinder.svelte +33 -17
- package/dist/structure/Lattice.svelte +88 -33
- package/dist/structure/Structure.svelte +1063 -797
- package/dist/structure/Structure.svelte.d.ts +1 -1
- package/dist/structure/StructureControls.svelte +349 -118
- package/dist/structure/StructureExportPane.svelte +124 -89
- package/dist/structure/StructureExportPane.svelte.d.ts +1 -1
- package/dist/structure/StructureInfoPane.svelte +304 -237
- package/dist/structure/StructureScene.svelte +879 -443
- package/dist/structure/StructureScene.svelte.d.ts +15 -7
- package/dist/structure/atom-properties.js +8 -8
- package/dist/structure/bonding.js +6 -7
- package/dist/structure/export.js +14 -29
- package/dist/structure/ferrox-wasm.js +1 -1
- package/dist/structure/index.d.ts +13 -3
- package/dist/structure/index.js +83 -23
- package/dist/structure/measure.d.ts +2 -2
- package/dist/structure/measure.js +4 -44
- package/dist/structure/parse.js +113 -141
- package/dist/structure/partial-occupancy.js +7 -10
- package/dist/structure/pbc.d.ts +1 -0
- package/dist/structure/pbc.js +16 -6
- package/dist/structure/supercell.d.ts +2 -2
- package/dist/structure/supercell.js +12 -22
- package/dist/structure/validation.js +1 -2
- package/dist/symmetry/SymmetryStats.svelte +84 -41
- package/dist/symmetry/WyckoffTable.svelte +26 -6
- package/dist/symmetry/cell-transform.js +5 -3
- package/dist/symmetry/index.js +8 -7
- package/dist/symmetry/spacegroups.js +148 -148
- package/dist/table/HeatmapTable.svelte +790 -554
- package/dist/table/HeatmapTable.svelte.d.ts +1 -1
- package/dist/table/ToggleMenu.svelte +125 -92
- package/dist/table/index.js +2 -4
- package/dist/theme/ThemeControl.svelte +21 -12
- package/dist/time.js +4 -1
- package/dist/tooltip/TooltipContent.svelte +33 -8
- package/dist/trajectory/Trajectory.svelte +758 -558
- package/dist/trajectory/TrajectoryError.svelte +14 -3
- package/dist/trajectory/TrajectoryExportPane.svelte +137 -83
- package/dist/trajectory/TrajectoryInfoPane.svelte +272 -143
- package/dist/trajectory/extract.js +10 -26
- package/dist/trajectory/format-detect.js +5 -5
- package/dist/trajectory/frame-reader.d.ts +1 -1
- package/dist/trajectory/frame-reader.js +5 -12
- package/dist/trajectory/helpers.d.ts +0 -1
- package/dist/trajectory/helpers.js +2 -17
- package/dist/trajectory/index.js +14 -12
- package/dist/trajectory/parse/ase.js +5 -4
- package/dist/trajectory/parse/hdf5.js +26 -18
- package/dist/trajectory/parse/index.js +13 -18
- package/dist/trajectory/parse/lammps.js +17 -7
- package/dist/trajectory/parse/vasp.js +5 -2
- package/dist/trajectory/parse/xyz.js +8 -7
- package/dist/trajectory/plotting.js +13 -8
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +13 -0
- package/dist/xrd/XrdPlot.svelte +337 -247
- package/dist/xrd/broadening.js +14 -9
- package/dist/xrd/calc-xrd.js +12 -18
- package/dist/xrd/parse.d.ts +1 -1
- package/dist/xrd/parse.js +17 -17
- package/package.json +99 -103
- package/readme.md +1 -1
- /package/dist/theme/{themes.js → themes.mjs} +0 -0
|
@@ -1,127 +1,152 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// ReferenceLine3D: 3D reference lines for axis-parallel, segments, and extended lines
|
|
3
|
+
// Uses Line2 for proper variable-width lines (WebGL ignores linewidth on basic lines)
|
|
4
|
+
import type { Vec3 } from '../math'
|
|
5
|
+
import { T, useThrelte } from '@threlte/core'
|
|
6
|
+
import * as THREE from 'three'
|
|
7
|
+
import { Line2 } from 'three/examples/jsm/lines/Line2.js'
|
|
8
|
+
import { LineGeometry } from 'three/examples/jsm/lines/LineGeometry.js'
|
|
9
|
+
import { LineMaterial } from 'three/examples/jsm/lines/LineMaterial.js'
|
|
10
|
+
import { create_to_threejs, span_or } from './reference-line'
|
|
11
|
+
import type { RefLine3D } from './types'
|
|
12
|
+
|
|
13
|
+
let { ref_line, scene_size = [10, 10, 5], ranges }: {
|
|
14
|
+
ref_line: RefLine3D
|
|
15
|
+
scene_size?: Vec3
|
|
16
|
+
ranges: { x: [number, number]; y: [number, number]; z: [number, number] }
|
|
17
|
+
} = $props()
|
|
18
|
+
|
|
19
|
+
const { size } = useThrelte()
|
|
20
|
+
let [scene_x, scene_y, scene_z] = $derived(scene_size)
|
|
21
|
+
let { x: x_range, y: y_range, z: z_range } = $derived(ranges)
|
|
22
|
+
|
|
23
|
+
// Transform data coords to Three.js coordinates
|
|
24
|
+
let to_coords = $derived.by(() => {
|
|
13
25
|
const transform = create_to_threejs({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
})
|
|
21
|
-
return (ux, uy, uz) => transform(ux, uy, uz)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
scene_x,
|
|
27
|
+
scene_y,
|
|
28
|
+
scene_z,
|
|
29
|
+
x_range,
|
|
30
|
+
y_range,
|
|
31
|
+
z_range,
|
|
32
|
+
})
|
|
33
|
+
return (ux: number, uy: number, uz: number) => transform(ux, uy, uz)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// Compute line endpoints based on type
|
|
37
|
+
let endpoints = $derived.by(
|
|
38
|
+
():
|
|
39
|
+
| [{ x: number; y: number; z: number }, { x: number; y: number; z: number }]
|
|
40
|
+
| null => {
|
|
41
|
+
if (ref_line.visible === false) return null
|
|
42
|
+
const [x_min, x_max] = span_or(ref_line.x_span, x_range)
|
|
43
|
+
const [y_min, y_max] = span_or(ref_line.y_span, y_range)
|
|
44
|
+
const [z_min, z_max] = span_or(ref_line.z_span, z_range)
|
|
45
|
+
|
|
46
|
+
switch (ref_line.type) {
|
|
31
47
|
case `x-axis`:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
48
|
+
return [
|
|
49
|
+
to_coords(x_min, ref_line.y, ref_line.z),
|
|
50
|
+
to_coords(x_max, ref_line.y, ref_line.z),
|
|
51
|
+
]
|
|
36
52
|
case `y-axis`:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
return [
|
|
54
|
+
to_coords(ref_line.x, y_min, ref_line.z),
|
|
55
|
+
to_coords(ref_line.x, y_max, ref_line.z),
|
|
56
|
+
]
|
|
41
57
|
case `z-axis`:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
return [
|
|
59
|
+
to_coords(ref_line.x, ref_line.y, z_min),
|
|
60
|
+
to_coords(ref_line.x, ref_line.y, z_max),
|
|
61
|
+
]
|
|
46
62
|
case `segment`:
|
|
47
|
-
|
|
63
|
+
return [to_coords(...ref_line.p1), to_coords(...ref_line.p2)]
|
|
48
64
|
case `line`: {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
];
|
|
65
|
+
// Extend line through two points to bounding box
|
|
66
|
+
const [p1x, p1y, p1z] = ref_line.p1
|
|
67
|
+
const [dx, dy, dz] = [
|
|
68
|
+
ref_line.p2[0] - p1x,
|
|
69
|
+
ref_line.p2[1] - p1y,
|
|
70
|
+
ref_line.p2[2] - p1z,
|
|
71
|
+
]
|
|
72
|
+
// Find t values at each boundary plane
|
|
73
|
+
const t_values = [
|
|
74
|
+
...(dx !== 0 ? [(x_min - p1x) / dx, (x_max - p1x) / dx] : []),
|
|
75
|
+
...(dy !== 0 ? [(y_min - p1y) / dy, (y_max - p1y) / dy] : []),
|
|
76
|
+
...(dz !== 0 ? [(z_min - p1z) / dz, (z_max - p1z) / dz] : []),
|
|
77
|
+
]
|
|
78
|
+
// Keep only t values where the resulting point is inside bounds
|
|
79
|
+
const eps = 1e-6
|
|
80
|
+
const valid_t = t_values.filter((t) => {
|
|
81
|
+
const [px, py, pz] = [p1x + t * dx, p1y + t * dy, p1z + t * dz]
|
|
82
|
+
return px >= x_min - eps && px <= x_max + eps &&
|
|
83
|
+
py >= y_min - eps && py <= y_max + eps && pz >= z_min - eps &&
|
|
84
|
+
pz <= z_max + eps
|
|
85
|
+
})
|
|
86
|
+
if (valid_t.length < 2) return null
|
|
87
|
+
const t_min = Math.min(...valid_t)
|
|
88
|
+
const t_max = Math.max(...valid_t)
|
|
89
|
+
return [
|
|
90
|
+
to_coords(p1x + t_min * dx, p1y + t_min * dy, p1z + t_min * dz),
|
|
91
|
+
to_coords(p1x + t_max * dx, p1y + t_max * dy, p1z + t_max * dz),
|
|
92
|
+
]
|
|
78
93
|
}
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
// Line style (with defaults)
|
|
99
|
+
let style = $derived({
|
|
83
100
|
color: ref_line.style?.color ?? `white`,
|
|
84
101
|
opacity: ref_line.style?.opacity ?? 1,
|
|
85
102
|
width: ref_line.style?.width ?? 2,
|
|
86
103
|
dashed: !!ref_line.style?.dash,
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
let
|
|
91
|
-
$
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
// Create Line2 with LineGeometry and LineMaterial for proper variable-width lines
|
|
107
|
+
let line2: Line2 | null = $state(null)
|
|
108
|
+
let material: LineMaterial | null = $state(null)
|
|
109
|
+
|
|
110
|
+
$effect(() => {
|
|
92
111
|
if (!endpoints) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
112
|
+
line2 = null
|
|
113
|
+
material = null
|
|
114
|
+
return
|
|
96
115
|
}
|
|
97
|
-
const [p1, p2] = endpoints
|
|
98
|
-
|
|
99
|
-
geo
|
|
116
|
+
const [p1, p2] = endpoints
|
|
117
|
+
|
|
118
|
+
const geo = new LineGeometry()
|
|
119
|
+
geo.setPositions([p1.x, p1.y, p1.z, p2.x, p2.y, p2.z])
|
|
120
|
+
|
|
100
121
|
const mat = new LineMaterial({
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
line
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
color: new THREE.Color(style.color).getHex(),
|
|
123
|
+
linewidth: style.width,
|
|
124
|
+
transparent: style.opacity < 1,
|
|
125
|
+
opacity: style.opacity,
|
|
126
|
+
dashed: style.dashed,
|
|
127
|
+
dashSize: 0.3,
|
|
128
|
+
gapSize: 0.1,
|
|
129
|
+
resolution: new THREE.Vector2($size.width || 1, $size.height || 1),
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const line = new Line2(geo, mat)
|
|
133
|
+
line.computeLineDistances() // Required for dashed lines
|
|
134
|
+
|
|
135
|
+
material = mat
|
|
136
|
+
line2 = line
|
|
137
|
+
|
|
114
138
|
return () => {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
|
|
139
|
+
geo.dispose()
|
|
140
|
+
mat.dispose()
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
// Update material resolution when canvas size changes
|
|
145
|
+
$effect(() => {
|
|
121
146
|
if (material) {
|
|
122
|
-
|
|
147
|
+
material.resolution.set($size.width || 1, $size.height || 1)
|
|
123
148
|
}
|
|
124
|
-
})
|
|
149
|
+
})
|
|
125
150
|
</script>
|
|
126
151
|
|
|
127
152
|
{#if line2}
|
|
@@ -1,137 +1,162 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// ReferencePlane: 3D reference planes (axis-aligned, normal-defined, or point-defined)
|
|
3
|
+
import type { Vec3 } from '../math'
|
|
4
|
+
import { cross_3d, normalize_vec3 } from '../math'
|
|
5
|
+
import { T } from '@threlte/core'
|
|
6
|
+
import * as THREE from 'three'
|
|
7
|
+
import { create_to_threejs, span_or } from './reference-line'
|
|
8
|
+
import type { RefPlane } from './types'
|
|
9
|
+
|
|
10
|
+
let { ref_plane, scene_size = [10, 10, 5], ranges }: {
|
|
11
|
+
ref_plane: RefPlane
|
|
12
|
+
scene_size?: Vec3
|
|
13
|
+
ranges: { x: [number, number]; y: [number, number]; z: [number, number] }
|
|
14
|
+
} = $props()
|
|
15
|
+
|
|
16
|
+
let [scene_x, scene_y, scene_z] = $derived(scene_size)
|
|
17
|
+
let { x: x_range, y: y_range, z: z_range } = $derived(ranges)
|
|
18
|
+
|
|
19
|
+
// Transform data coords to Three.js Vector3
|
|
20
|
+
let to_vec3 = $derived.by(() => {
|
|
10
21
|
const transform = create_to_threejs({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})
|
|
18
|
-
return (ux, uy, uz) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let [
|
|
26
|
-
let [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
scene_x,
|
|
23
|
+
scene_y,
|
|
24
|
+
scene_z,
|
|
25
|
+
x_range,
|
|
26
|
+
y_range,
|
|
27
|
+
z_range,
|
|
28
|
+
})
|
|
29
|
+
return (ux: number, uy: number, uz: number) => {
|
|
30
|
+
const { x, y, z } = transform(ux, uy, uz)
|
|
31
|
+
return new THREE.Vector3(x, y, z)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// Apply span constraints or use full range
|
|
36
|
+
let [x_min, x_max] = $derived(span_or(ref_plane.x_span, x_range))
|
|
37
|
+
let [y_min, y_max] = $derived(span_or(ref_plane.y_span, y_range))
|
|
38
|
+
let [z_min, z_max] = $derived(span_or(ref_plane.z_span, z_range))
|
|
39
|
+
|
|
40
|
+
// Helper to create quad from 4 corner coords
|
|
41
|
+
const quad = (coords: Vec3[]) =>
|
|
42
|
+
create_quad_geometry(coords.map(([ux, uy, uz]) => to_vec3(ux, uy, uz)))
|
|
43
|
+
|
|
44
|
+
// Compute plane geometry based on type - returns result to use in $effect
|
|
45
|
+
function compute_geometry(): THREE.BufferGeometry | null {
|
|
46
|
+
if (ref_plane.visible === false) return null
|
|
47
|
+
|
|
33
48
|
switch (ref_plane.type) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
default:
|
|
76
|
-
return null;
|
|
49
|
+
case `xy`: {
|
|
50
|
+
const zval = ref_plane.z
|
|
51
|
+
return quad([
|
|
52
|
+
[x_min, y_min, zval],
|
|
53
|
+
[x_max, y_min, zval],
|
|
54
|
+
[x_max, y_max, zval],
|
|
55
|
+
[x_min, y_max, zval],
|
|
56
|
+
])
|
|
57
|
+
}
|
|
58
|
+
case `xz`: {
|
|
59
|
+
const yval = ref_plane.y
|
|
60
|
+
return quad([
|
|
61
|
+
[x_min, yval, z_min],
|
|
62
|
+
[x_max, yval, z_min],
|
|
63
|
+
[x_max, yval, z_max],
|
|
64
|
+
[x_min, yval, z_max],
|
|
65
|
+
])
|
|
66
|
+
}
|
|
67
|
+
case `yz`: {
|
|
68
|
+
const xval = ref_plane.x
|
|
69
|
+
return quad([
|
|
70
|
+
[xval, y_min, z_min],
|
|
71
|
+
[xval, y_max, z_min],
|
|
72
|
+
[xval, y_max, z_max],
|
|
73
|
+
[xval, y_min, z_max],
|
|
74
|
+
])
|
|
75
|
+
}
|
|
76
|
+
case `normal`: {
|
|
77
|
+
if (Math.hypot(...ref_plane.normal) < 1e-9) return null // degenerate normal
|
|
78
|
+
return create_plane_from_normal(ref_plane.normal, ref_plane.point)
|
|
79
|
+
}
|
|
80
|
+
case `points`: {
|
|
81
|
+
const { p1, p2, p3 } = ref_plane
|
|
82
|
+
const v1: Vec3 = [p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]]
|
|
83
|
+
const v2: Vec3 = [p3[0] - p1[0], p3[1] - p1[1], p3[2] - p1[2]]
|
|
84
|
+
const cross = cross_3d(v1, v2)
|
|
85
|
+
if (Math.hypot(...cross) < 1e-9) return null // collinear points
|
|
86
|
+
return create_plane_from_normal(normalize_vec3(cross), p1)
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
return null
|
|
77
90
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
$
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
geo
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Create geometry with proper disposal on dependency change
|
|
94
|
+
let geometry: THREE.BufferGeometry | null = $state(null)
|
|
95
|
+
|
|
96
|
+
$effect(() => {
|
|
97
|
+
const geo = compute_geometry()
|
|
98
|
+
geometry = geo
|
|
99
|
+
return () => geo?.dispose()
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
// Create a quad geometry from 4 corners (two triangles: 0-1-2 and 0-2-3)
|
|
103
|
+
function create_quad_geometry(corners: THREE.Vector3[]): THREE.BufferGeometry {
|
|
104
|
+
const geo = new THREE.BufferGeometry()
|
|
105
|
+
const [c0, c1, c2, c3] = corners
|
|
106
|
+
const verts = [c0, c1, c2, c0, c2, c3].flatMap((corner) => [corner.x, corner.y, corner.z])
|
|
107
|
+
geo.setAttribute(
|
|
108
|
+
`position`,
|
|
109
|
+
new THREE.BufferAttribute(new Float32Array(verts), 3),
|
|
110
|
+
)
|
|
111
|
+
geo.computeVertexNormals()
|
|
112
|
+
return geo
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Create plane from normal and point, scaled to cover bounding box
|
|
116
|
+
function create_plane_from_normal(normal: Vec3, point: Vec3): THREE.BufferGeometry {
|
|
117
|
+
const normalized = normalize_vec3(normal)
|
|
98
118
|
// Pick u perpendicular to normal (use axis least aligned with normal)
|
|
99
|
-
const u_dir = normalize_vec3(
|
|
100
|
-
|
|
119
|
+
const u_dir = normalize_vec3(
|
|
120
|
+
cross_3d(normalized, Math.abs(normalized[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0]),
|
|
121
|
+
)
|
|
122
|
+
const v_dir = cross_3d(normalized, u_dir)
|
|
101
123
|
// Scale to cover bounding box
|
|
102
|
-
const scale = Math.max(x_max - x_min, y_max - y_min, z_max - z_min) * 2
|
|
103
|
-
const [px, py, pz] = point
|
|
124
|
+
const scale = Math.max(x_max - x_min, y_max - y_min, z_max - z_min) * 2
|
|
125
|
+
const [px, py, pz] = point
|
|
104
126
|
// Helper to offset point by u*su + v*sv
|
|
105
|
-
const corner = (su, sv) => [
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
]
|
|
127
|
+
const corner = (su: number, sv: number): Vec3 => [
|
|
128
|
+
px + u_dir[0] * su + v_dir[0] * sv,
|
|
129
|
+
py + u_dir[1] * su + v_dir[1] * sv,
|
|
130
|
+
pz + u_dir[2] * su + v_dir[2] * sv,
|
|
131
|
+
]
|
|
110
132
|
const corners = [
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
]
|
|
116
|
-
return create_quad_geometry(corners.map(([ux, uy, uz]) => to_vec3(ux, uy, uz)))
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
133
|
+
corner(-scale, -scale),
|
|
134
|
+
corner(scale, -scale),
|
|
135
|
+
corner(scale, scale),
|
|
136
|
+
corner(-scale, scale),
|
|
137
|
+
]
|
|
138
|
+
return create_quad_geometry(corners.map(([ux, uy, uz]) => to_vec3(ux, uy, uz)))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Material properties (with defaults)
|
|
142
|
+
let style = $derived({
|
|
120
143
|
color: ref_plane.style?.color ?? `#4488ff`,
|
|
121
144
|
opacity: ref_plane.style?.opacity ?? 0.3,
|
|
122
145
|
wireframe: ref_plane.style?.wireframe ?? false,
|
|
123
146
|
wireframe_color: ref_plane.style?.wireframe_color ?? `white`,
|
|
124
147
|
double_sided: ref_plane.style?.double_sided ?? true,
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
$
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
// Create wireframe geometry with automatic disposal when dependencies change
|
|
151
|
+
let wireframe_geometry: THREE.WireframeGeometry | null = $state(null)
|
|
152
|
+
|
|
153
|
+
$effect(() => {
|
|
129
154
|
const wf_geo = geometry && style.wireframe
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
wireframe_geometry = wf_geo
|
|
133
|
-
return () => wf_geo?.dispose()
|
|
134
|
-
})
|
|
155
|
+
? new THREE.WireframeGeometry(geometry)
|
|
156
|
+
: null
|
|
157
|
+
wireframe_geometry = wf_geo
|
|
158
|
+
return () => wf_geo?.dispose()
|
|
159
|
+
})
|
|
135
160
|
</script>
|
|
136
161
|
|
|
137
162
|
{#if geometry}
|