Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webgl upgrade 2 #1635

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
4b4fa94
removed commas unallowed in button html
theogutt Jun 11, 2024
1ec20f7
node modules for webgl
theogutt Jun 11, 2024
ebd495a
Beggining WebGL ThreeJS Scene made with react components. Added grid …
theogutt Jun 14, 2024
9c5e33c
Sizing for canvas
theogutt Jun 14, 2024
7ae4b6b
Buttons for setting view. Still missing calculation of correct top an…
theogutt Jun 16, 2024
9f2675b
Cleanup in threecanvas and added context for grid size and divisions
theogutt Jun 16, 2024
e8d0a29
Cleanup in threecanvas and added context for grid size and divisions 2
theogutt Jun 16, 2024
4687857
fix for grids turning on when campos changes
theogutt Jun 16, 2024
46899ad
temporary commit for loading instrument/components from json and adju…
theogutt Jun 17, 2024
0850726
loading components succesfully
theogutt Jun 18, 2024
a753d89
Transparency and color editing for a component is now working.
theogutt Jun 19, 2024
2615a1d
.gitignore node_modules, but keep package-lock.json
theogutt Jun 20, 2024
5db8e40
gitignore node_modules\
theogutt Jun 20, 2024
cf50090
remove node_modules
theogutt Jun 20, 2024
214cf21
styling for lists
theogutt Jun 20, 2024
4275544
added scrolling for dropwdown
theogutt Jun 20, 2024
a8d0a32
fix for multilines
theogutt Jun 20, 2024
9ba0f8a
package-lock.json
theogutt Jun 20, 2024
d78a92f
testdata for new UI
theogutt Jun 20, 2024
207dc33
format files
theogutt Jun 20, 2024
11870d1
rotate chevron on open/close
theogutt Jun 20, 2024
02d9552
removed log
theogutt Jun 21, 2024
17c052e
removed unused data
theogutt Jun 21, 2024
4b55dc4
loading rays and show hide
theogutt Jun 21, 2024
e96657b
formatting
theogutt Jun 21, 2024
1a39e1e
testdata
theogutt Jun 21, 2024
0fbb2f2
toggle scatterpoints
theogutt Jun 21, 2024
e6d2a27
reorganize components
theogutt Jun 21, 2024
5474eb7
update imports after reorganizing components
theogutt Jun 21, 2024
16fbc61
limit dropwdownbutton text length, so it doesnt overflow
theogutt Jun 21, 2024
bd37658
smaller particle test data
theogutt Jun 22, 2024
28d75be
restructured main.js to be able to use contexts.
theogutt Jun 22, 2024
dce6d93
restructured main.js to be able to use contexts.
theogutt Jun 22, 2024
082c0eb
specified args datatype in drawcall to number array
theogutt Jun 22, 2024
ad7d9f7
Loading indicator
theogutt Jun 22, 2024
ad03ca5
fallback component when loading
theogutt Jun 22, 2024
9487526
app context: for now just used for loading indicator
theogutt Jun 22, 2024
974b93e
fix for drawcalls shape
theogutt Jun 25, 2024
25b53cf
fix for drawcalls shape
theogutt Jun 25, 2024
0d8efa9
bounding box for grids
theogutt Jun 25, 2024
08b8c1d
updated views with bounding box
theogutt Jun 25, 2024
f0a9c72
cleanup
theogutt Jun 25, 2024
798dd34
Playback for rays
theogutt Jun 25, 2024
2561dc1
play rays by default when clicking showrays
theogutt Jun 25, 2024
61c3975
remove h1 "Menu"
theogutt Jun 25, 2024
1ec62a3
removing console logs
theogutt Jun 25, 2024
ee05133
show all rays
theogutt Jun 25, 2024
06129dc
corrected gridsizes and divisions
theogutt Jun 26, 2024
28e9afc
dont start playback when toggling show rays
theogutt Jun 26, 2024
969ae0e
hide rays when pressing playback
theogutt Jun 26, 2024
8fc34ae
beginning get component info on hover. And show multiple views for re…
theogutt Jun 27, 2024
da3c660
improved 2D views
theogutt Jun 27, 2024
5a4c6db
sticky menu
theogutt Jun 27, 2024
e331f87
split canvas into views
theogutt Jul 1, 2024
61b9759
5 views in divs
theogutt Jul 1, 2024
8162fbc
div text matches p text
theogutt Jul 1, 2024
f2fa241
offset to match menu that is about 25px
theogutt Jul 1, 2024
6f2e062
for making top view show up 90 degrees rotated
theogutt Jul 1, 2024
e92ccfd
remove unused code
theogutt Jul 1, 2024
1fcfb55
fix for sideview
theogutt Jul 1, 2024
a8c9427
dark mode light mode and reset view for primary view.
theogutt Jul 1, 2024
3d7a707
remove unused fov for orthographic cameras
theogutt Jul 1, 2024
601d75b
better code
theogutt Jul 1, 2024
3e05103
cleanup
theogutt Jul 1, 2024
7713560
margin top 25
theogutt Jul 1, 2024
e912fed
centering 2D views
theogutt Jul 1, 2024
49c1e68
labels for 2d views
theogutt Jul 1, 2024
6393ded
dark mode fixes
theogutt Jul 1, 2024
39f93f4
background color toggling
theogutt Jul 3, 2024
6df7b9e
loading rays on show rays button clicked
theogutt Jul 3, 2024
4410913
default testdata
theogutt Jul 3, 2024
92ea076
fetching json
theogutt Jul 3, 2024
c3856d8
small fix
theogutt Jul 4, 2024
4d95a44
load particles.json and instrument json from dist/
theogutt Jul 4, 2024
aea52e3
small fix
theogutt Jul 4, 2024
e0df05c
delete testdata
theogutt Jul 4, 2024
50f2974
never commit instrument.json and particles.json
theogutt Jul 4, 2024
9e1d658
commit node modules
theogutt Jul 4, 2024
1439adb
remove last view
theogutt Jul 4, 2024
993916f
format files
theogutt Jul 4, 2024
a5a7fbe
rename data folder to data-utils
theogutt Jul 4, 2024
b6d86d1
removed dist from gitignore
theogutt Jul 4, 2024
30e0caa
dist
theogutt Jul 4, 2024
254469c
node_modules dist
theogutt Jul 4, 2024
a8c13fa
Merge branch 'McStasMcXtrace:main' into pyqtgraph-replacement-in-webg…
theogutt Jul 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

3rdparty/
Mambaforge-Linux-x86_64.sh
dist/

2 changes: 2 additions & 0 deletions tools/Python/mcdisplay/webgl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
instrument.json
particles.json
17 changes: 17 additions & 0 deletions tools/Python/mcdisplay/webgl/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";
import ThreeCanvas from "./components/scene/ThreeCanvas";
import ConfigureSceneMenu from "./components/configure-scene/ConfigureSceneMenu";
import "./common.css";
import LoadingIndicator from "./components/loading-indicator/LoadingIndicator";
import { useAppContext } from "./Contexts/AppContext";

export default function App() {
const { loading, setLoading } = useAppContext();
return (
<div id="app" className="column">
{loading ? <LoadingIndicator /> : null}
<ConfigureSceneMenu />
<ThreeCanvas />
</div>
);
}
38 changes: 38 additions & 0 deletions tools/Python/mcdisplay/webgl/Contexts/AppContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { createContext, useContext, ReactNode, useState } from "react";

type AppContextType = {
loading: boolean;
setLoading: React.Dispatch<React.SetStateAction<boolean>>;
backgroundColor: boolean;
toggleBackgroundColor: () => void;
};

const AppContext = createContext<AppContextType>({
loading: true,
setLoading: () => {},
backgroundColor: true,
toggleBackgroundColor: () => {},
});

interface AppProviderProps {
children: ReactNode;
}

export const AppProvider: React.FC<AppProviderProps> = ({ children }) => {
const [loading, setLoading] = useState<boolean>(true);
const [backgroundColor, setBackgroundColor] = useState<boolean>(true);

const toggleBackgroundColor = () => {
setBackgroundColor((prevDarkBackground) => !prevDarkBackground);
};

return (
<AppContext.Provider
value={{ loading, setLoading, backgroundColor, toggleBackgroundColor }}
>
{children}
</AppContext.Provider>
);
};

export const useAppContext = () => useContext(AppContext);
44 changes: 44 additions & 0 deletions tools/Python/mcdisplay/webgl/Contexts/CameraContext.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { createContext, useContext, useState } from "react";
import { Vector3 } from "three";

const CameraContext = createContext({
camPos: new Vector3(10, 20, 30),
camPosHome: new Vector3(10, 20, 30),
camPosSide: new Vector3(0, 20, 0),
camPosTop: new Vector3(0, 0, 30),
setCamPos: () => {},
setCamPosHome: () => {},
setCamPosSide: () => {},
setCamPosTop: () => {},
logMessage: () => {},
});

export const CameraProvider = ({ children }) => {
const [camPos, setCamPos] = useState(new Vector3(10, 20, 30));
const [camPosHome, setCamPosHome] = useState(new Vector3(10, 20, 30));
const [camPosSide, setCamPosSide] = useState(new Vector3(0, 0, 30));
const [camPosTop, setCamPosTop] = useState(new Vector3(0, 30, 0));

const handleSetCamPos = (position) => {
setCamPos(position);
};

return (
<CameraContext.Provider
value={{
camPos,
setCamPos: handleSetCamPos,
camPosHome,
setCamPosHome,
camPosSide,
setCamPosSide,
camPosTop,
setCamPosTop,
}}
>
{children}
</CameraContext.Provider>
);
};

export const useCameraContext = () => useContext(CameraContext);
53 changes: 53 additions & 0 deletions tools/Python/mcdisplay/webgl/Contexts/ComponentsContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, {
ReactNode,
createContext,
useContext,
useState,
useEffect,
} from "react";
import { Component } from "../model/Component";
import { fetchJSON } from "../utils/fetch";
import { initializeInstrument } from "../data-utils/initInstrument";

type ComponentsContextType = {
components: Component[];
setComponents: React.Dispatch<React.SetStateAction<Component[]>>;
};

const ComponentsContext = createContext<ComponentsContextType>({
components: [],
setComponents: () => {},
});

interface ComponentsProviderProps {
children: ReactNode;
}

export const ComponentsProvider: React.FC<ComponentsProviderProps> = ({
children,
}) => {
const [components, _setComponents] = useState<Component[]>([]);

useEffect(() => {
fetchJSON("../instrument.json").then((data) => {
if (data) {
const instrument = initializeInstrument(data);
_setComponents(instrument.components);
} else {
console.warn("Instrument data is missing");
}
});
}, []);

const setComponents = (newComponents: React.SetStateAction<Component[]>) => {
_setComponents(newComponents);
};

return (
<ComponentsContext.Provider value={{ components, setComponents }}>
{children}
</ComponentsContext.Provider>
);
};

export const useComponentsContext = () => useContext(ComponentsContext);
51 changes: 51 additions & 0 deletions tools/Python/mcdisplay/webgl/Contexts/GridContext.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { createContext, useContext, useState } from "react";

const GridContext = createContext({
gridSize: 100,
gridDivisions: 100,
setGridSize: (size, divisions) => {},

showXY: false,
showXZ: true,
showYZ: false,
toggleXY: () => {},
toggleXZ: () => {},
toggleYZ: () => {},
});

export const GridProvider = ({ children }) => {
const [gridSize, setGridSize] = useState(100);
const [gridDivisions, setGridDivisions] = useState(100);
const updateGridSize = (size, divisions) => {
setGridSize(size);
setGridDivisions(divisions);
};

const [showXY, setShowXY] = useState(false);
const [showXZ, setShowXZ] = useState(true);
const [showYZ, setShowYZ] = useState(false);

const toggleXY = () => setShowXY(!showXY);
const toggleXZ = () => setShowXZ(!showXZ);
const toggleYZ = () => setShowYZ(!showYZ);

return (
<GridContext.Provider
value={{
gridSize,
gridDivisions,
setGridSize: updateGridSize,
showXY,
showXZ,
showYZ,
toggleXY,
toggleXZ,
toggleYZ,
}}
>
{children}
</GridContext.Provider>
);
};

export const useGridContext = () => useContext(GridContext);
133 changes: 133 additions & 0 deletions tools/Python/mcdisplay/webgl/Contexts/RaysContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import React, { ReactNode, createContext, useContext, useState } from "react";
import { RayData } from "../model/Rays";

type RaysContextType = {
showAllRays: boolean;
toggleShowAllRays: () => void;
play: boolean;
setPlay: React.Dispatch<React.SetStateAction<boolean>>;
prevRayIndex: number;
currentRayIndex: number;
setCurrentRayIndex: (index: number) => void;
showScatterPoints: boolean;
toggleScatterPoints: () => void;
showRays: boolean;
toggleRays: () => void;
rays: RayData;
setRays: React.Dispatch<React.SetStateAction<RayData>>;
handleNextClick: () => void;
handlePreviousClick: () => void;
};

const RaysContext = createContext<RaysContextType>({
showAllRays: false,
toggleShowAllRays: () => {},
play: false,
setPlay: () => {},
prevRayIndex: 0,
currentRayIndex: 0,
setCurrentRayIndex: () => {},
showScatterPoints: true,
toggleScatterPoints: () => {},
showRays: false,
toggleRays: () => {},
rays: { rays: [], numrays: 0, vmin: 0, vmax: 0 },
setRays: () => {},
handleNextClick: () => {},
handlePreviousClick: () => {},
});

interface RaysProviderProps {
children: ReactNode;
}

export const RaysProvider: React.FC<RaysProviderProps> = ({ children }) => {
const [showScatterPoints, setShowScatterPoints] = useState(true);
const [rays, setRays] = useState<RayData>({
rays: [],
numrays: 0,
vmin: 0,
vmax: 0,
});
const [showRays, setShowRays] = useState(false);
const [currentRayIndex, _setCurrentRayIndex] = useState(0);
const [prevRayIndex, setPrevRayIndex] = useState(0);
const [play, setPlay] = useState(false);
const [showAllRays, setShowAllRays] = useState(false);

const toggleShowAllRays = () => {
setShowAllRays((prevShowAllRays) => !prevShowAllRays);
};

const setCurrentRayIndex = (
indexOrUpdater: number | ((prevIndex: number) => number)
) => {
if (typeof indexOrUpdater === "function") {
_setCurrentRayIndex((prevIndex) => {
const newIndex = indexOrUpdater(prevIndex);
setPrevRayIndex(prevIndex);
return newIndex;
});
} else {
setPrevRayIndex(currentRayIndex);
_setCurrentRayIndex(indexOrUpdater);
}
};

const toggleScatterPoints = () => {
setShowScatterPoints((prevShowScatterPoints) => !prevShowScatterPoints);
};

const toggleRays = () => {
setPlay(false);
setShowRays((prevShowRays) => !prevShowRays);
};

const handleNextClick = () => {
setCurrentRayIndex((prevIndex) => {
const numRays = rays.rays.length - 1;
if (prevIndex >= numRays) {
return 0; // Start from the beginning
} else {
return prevIndex + 1;
}
});
};

const handlePreviousClick = () => {
setCurrentRayIndex((prevIndex) => {
const numRays = rays.rays.length - 1;
if (prevIndex <= 0) {
return numRays; // Go to the last ray
} else {
return prevIndex - 1;
}
});
};

return (
<RaysContext.Provider
value={{
showAllRays,
toggleShowAllRays,
play,
setPlay,
prevRayIndex,
currentRayIndex,
setCurrentRayIndex,
showScatterPoints,
toggleScatterPoints,
showRays,
toggleRays,
rays,
setRays,
handleNextClick,
handlePreviousClick,
}}
>
{children}
</RaysContext.Provider>
);
};

export const useRaysContext = () => useContext(RaysContext);
Loading