|
| 1 | +/// <reference types="three" /> |
1 | 2 | import React, { useEffect } from "react"; |
2 | 3 |
|
| 4 | +// Tell TS that THREE is available globally |
| 5 | +declare const THREE: typeof import("three"); |
| 6 | + |
| 7 | +declare global { |
| 8 | + interface Window { |
| 9 | + scene: any; |
| 10 | + camera: any; |
| 11 | + renderer: any; |
| 12 | + previewdata: (...args: any[]) => void; |
| 13 | + [key: string]: any; |
| 14 | +} |
| 15 | +} |
| 16 | + |
3 | 17 | const PreviewModal: React.FC<{ |
4 | 18 | isOpen: boolean; |
5 | 19 | dataKey: any; |
6 | 20 | isInternal: boolean; |
7 | 21 | onClose: () => void; |
8 | 22 | }> = ({ isOpen, dataKey, isInternal, onClose }) => { |
9 | | - useEffect(() => { |
10 | | - if (isOpen) { |
11 | | - console.log("🟢 Opening PreviewModal for:", dataKey); |
12 | | - |
13 | | - setTimeout(() => { |
14 | | - // let canvas = document.querySelector("#canvas"); |
15 | | - |
16 | | - // if (!canvas) { |
17 | | - // console.error("❌ Error: #canvas element not found in DOM!"); |
18 | | - // return; |
19 | | - // } |
20 | | - |
21 | | - if (typeof (window as any).previewdata === "function") { |
22 | | - console.log("Calling previewdata to handle Three.js init..."); |
23 | | - (window as any).previewdata(dataKey, 0, isInternal, false); |
24 | | - } else { |
25 | | - console.error("❌ previewdata() is not defined!"); |
26 | | - } |
27 | | - }, 100); // Small delay ensures modal is rendered first |
| 23 | + useEffect(() => { |
| 24 | + if (isOpen) { |
| 25 | + console.log("🟢 Opening PreviewModal for:", dataKey); |
| 26 | + |
| 27 | + // 1. Clear previous canvas |
| 28 | + const canvasDiv = document.getElementById("canvas"); |
| 29 | + if (canvasDiv) { |
| 30 | + while (canvasDiv.firstChild) { |
| 31 | + canvasDiv.removeChild(canvasDiv.firstChild); |
| 32 | + } |
28 | 33 | } |
29 | | - }, [isOpen, dataKey]); |
| 34 | + |
| 35 | + // 2. Clear global references |
| 36 | + window.scene = undefined; |
| 37 | + window.camera = undefined; |
| 38 | + window.renderer = undefined; |
| 39 | + |
| 40 | + // 3. Reinitialize preview |
| 41 | + setTimeout(() => { |
| 42 | + if (typeof window.previewdata === "function") { |
| 43 | + console.log("Calling previewdata to handle Three.js init..."); |
| 44 | + window.previewdata(dataKey, 0, isInternal, false); |
| 45 | + } else { |
| 46 | + console.error("❌ previewdata() is not defined!"); |
| 47 | + } |
| 48 | + }, 100); |
| 49 | + console.log("⏳ Calling previewdata for", dataKey); |
| 50 | + } |
| 51 | +}, [isOpen, dataKey]); |
30 | 52 |
|
31 | 53 | if (!isOpen) return null; |
32 | 54 | return ( |
33 | | - // <div className="preview-modal"> |
34 | | - // <div className="modal-header"> |
35 | | - // <h3>Preview</h3> |
36 | | - // <button className="close-btn" onClick={onClose}>×</button> |
37 | | - // </div> |
38 | | - |
39 | | - // {/* ✅ Display Mode Section */} |
40 | | - // <div id="renderpanel" style={{ width: "100%", backgroundColor: "#222", padding: "10px", color: "#fff" }}> |
41 | | - // <b>Display Mode</b><br /> |
42 | | - // <input type="radio" id="mip-radio-button" name="displaymode" value="mip" defaultChecked /> |
43 | | - // <label htmlFor="mip-radio-button">MIP</label> |
44 | | - // <input type="radio" id="iso-radio-button" name="displaymode" value="iso" /> |
45 | | - // <label htmlFor="iso-radio-button">Isosurface</label> |
46 | | - |
47 | | - // {/* ✅ Colormap Section */} |
48 | | - // <b>Colormap</b><br /> |
49 | | - // <label htmlFor="clim-low">Lower-bound</label> |
50 | | - // <input id="clim-low" type="range" min="1" step="0.25" max="100" defaultValue="50" disabled /><br /> |
51 | | - // <label htmlFor="clim-hi">Upper-bound</label> |
52 | | - // <input id="clim-hi" type="range" min="1" step="0.25" max="100" defaultValue="50" disabled /><br /> |
53 | | - // <label htmlFor="isothreshold">Threshold</label> |
54 | | - // <input id="isothreshold" type="range" min="0" step="0.01" max="1" defaultValue="0.5" disabled /> |
55 | | - // </div> |
56 | | - |
57 | | - // {/* ✅ Cross Sections Section */} |
58 | | - // <b>Cross Sections</b><br /> |
59 | | - // <div className="controlrow"> |
60 | | - // X |
61 | | - // <label htmlFor="cross-x-low">Min</label> |
62 | | - // <input id="cross-x-low" type="range" min="0" max="1" defaultValue="0" step="any" /> |
63 | | - // <label htmlFor="cross-x-hi">Max</label> |
64 | | - // <input id="cross-x-hi" type="range" min="0" max="1" defaultValue="1" step="any" /> |
65 | | - // </div> |
66 | | - // <div className="controlrow"> |
67 | | - // Y |
68 | | - // <label htmlFor="cross-y-low">Min</label> |
69 | | - // <input id="cross-y-low" type="range" min="0" max="1" defaultValue="0" step="any" /> |
70 | | - // <label htmlFor="cross-y-hi">Max</label> |
71 | | - // <input id="cross-y-hi" type="range" min="0" max="1" defaultValue="1" step="any" /> |
72 | | - // </div> |
73 | | - // <div className="controlrow"> |
74 | | - // Z |
75 | | - // <label htmlFor="cross-z-low">Min</label> |
76 | | - // <input id="cross-z-low" type="range" min="0" max="1" defaultValue="0" step="any" /> |
77 | | - // <label htmlFor="cross-z-hi">Max</label> |
78 | | - // <input id="cross-z-hi" type="range" min="0" max="1" defaultValue="1" step="any" /> |
79 | | - // </div> |
80 | | - // <div id="taxis"> |
81 | | - // T |
82 | | - // <label htmlFor="cross-t">Time</label> |
83 | | - // <input id="cross-t" type="range" min="0" max="1" defaultValue="0" step="1" /> |
84 | | - // </div> |
85 | | - |
86 | | - // {/* ✅ Clip Plane Section */} |
87 | | - // <b>Clip Plane</b><br /> |
88 | | - // <label htmlFor="camera-near">Near</label> |
89 | | - // <input id="camera-near" type="range" min="1" max="100" defaultValue="50" /><br /> |
90 | | - // <label htmlFor="camera-far">Far</label> |
91 | | - // <input id="camera-far" type="range" min="1" max="100" defaultValue="50" /> |
92 | | - |
93 | | - // {/* ✅ View Section */} |
94 | | - // <b>View</b><br /> |
95 | | - // <button id="neg-x-view">-X</button> |
96 | | - // <button id="pos-x-view">+X</button> |
97 | | - // <button id="neg-y-view">-Y</button> |
98 | | - // <button id="pos-y-view">+Y</button> |
99 | | - // <button id="neg-z-view">-Z</button> |
100 | | - // <button id="pos-z-view">+Z</button> |
101 | | - |
102 | | - // {/* ✅ Ensure proper rendering with <canvas> */} |
103 | | - // <div |
104 | | - // id="canvas" |
105 | | - // style={{ |
106 | | - // backgroundColor: '#000', |
107 | | - // width: '937px', |
108 | | - // height: '750px', |
109 | | - // border: '1px solid black', |
110 | | - // padding: 0, |
111 | | - // float: 'left', |
112 | | - // }} |
113 | | - // ></div> |
114 | | - // </div> |
115 | 55 | <div |
116 | 56 | className="preview-modal" |
117 | 57 | style={{ |
|
0 commit comments