Skip to content

Commit

Permalink
split settings
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonFZ committed Nov 18, 2024
1 parent 7c7286b commit 073a82d
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 220 deletions.
Binary file modified app/bun.lockb
Binary file not shown.
122 changes: 61 additions & 61 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default function App() {
const [hoveredId, setHoveredId] = useState<number>(-1);
// UPDATE THESE using `vis.config` on the Python side
const [roomConfig, setRoomConfig] = useState({
arrows: {
Arrows: {
colormap: [
[-0.5, 0.9, 0.5],
[0.0, 0.9, 0.5],
Expand All @@ -106,34 +106,40 @@ export default function App() {
scale_vector_thickness: false,
opacity: 1.0,
},
scene: {
fps: 30,
material: "MeshStandardMaterial",
particle_size: 1.0,
bond_size: 1.0,
animation_loop: false,
simulation_box: true,
vectorfield: true,
controls: "OrbitControls",
vectors: [],
vector_scale: 1.0,
selection_color: "#ffa500",
camera: "PerspectiveCamera",
camera_near: 0.1,
camera_far: 300,
frame_update: true,
crosshair: false,
floor: false,
synchronize_camera: true,
},
PathTracer: {
enabled: false,
environment: "studio",
metalness: 0.7,
roughness: 0.2,
clearcoat: 0.0,
clearcoatRoughness: 0.0,
},
"Particle": {
"particle_size": 1.0,
"bond_size": 1.0,
"material": "MeshStandardMaterial",
"selection_color": "#ffa500"
},
"Visualization": {
"simulation_box": true,
"floor": false,
"frame_update": true,
"animation_loop": false
},
"Camera": {
"camera": "PerspectiveCamera",
"camera_near": 0.1,
"camera_far": 300,
"crosshair": false,
"synchronize_camera": true,
"fps": 30,
"controls": "OrbitControls"
},
"PathTracer": {
"enabled": false,
"environment": "studio",
"metalness": 0.7,
"roughness": 0.2,
"clearcoat": 0.0,
"clearcoatRoughness": 0.0
},
"VectorDisplay": {
"vectorfield": true,
"vectors": "",
"vector_scale": 1.0
},
});

const [isAuthenticated, setIsAuthenticated] = useState<boolean>(true);
Expand All @@ -143,12 +149,6 @@ export default function App() {
// TODO: fix
const [modifierQueue, setModifierQueue] = useState<number>(-1);

const cameraLightRef = useRef<THREE.PointLight>(null);
const controlsRef = useRef<TransformControls>(null);
const cameraRef = useRef<THREE.Camera>(null);

const [cameraRoll, setCameraRoll] = useState<number>(0); // or undefined

// extension UI elements
const [tutorialURL, setTutorialURL] = useState<string>("");
const [showSiMGen, setShowSiMGen] = useState<boolean>(false);
Expand All @@ -170,7 +170,7 @@ export default function App() {
token,
cameraAndControls,
setCameraAndControls,
roomConfig.scene.synchronize_camera,
roomConfig.Camera.synchronize_camera,
);
setupFrames(
token,
Expand All @@ -179,7 +179,7 @@ export default function App() {
currentFrame,
setLength,
setStep,
roomConfig.scene.frame_update,
roomConfig.Visualization.frame_update,
);
setupFigures(token, setUpdatedPlotsList);
setupGeometries(token, setGeometries, geometries);
Expand Down Expand Up @@ -448,7 +448,7 @@ export default function App() {
<div className="canvas-container" onDragOver={onDragOver} onDrop={onDrop}>
<Canvas onPointerMissed={onPointerMissed} shadows>
<CameraAndControls
roomConfig={roomConfig}
cameraConfig={roomConfig.Camera}
cameraAndControls={cameraAndControls}
setCameraAndControls={setCameraAndControls}
currentFrame={currentFrame}
Expand All @@ -461,35 +461,35 @@ export default function App() {
<Environment preset={roomConfig.PathTracer.environment} />
)}

{roomConfig.scene.floor ? (
{roomConfig.Visualization.floor ? (
<>
<Floor colorMode={colorMode} roomConfig={roomConfig} />
<directionalLight
position={[0, 100, 0]}
intensity={1.0}
castShadow
shadow-mapSize-width={roomConfig.scene.camera_far * 10} // Adjust the width of the shadow map
shadow-mapSize-height={roomConfig.scene.camera_far * 10} // Adjust the height of the shadow map
shadow-mapSize-width={roomConfig.Camera.camera_far * 10} // Adjust the width of the shadow map
shadow-mapSize-height={roomConfig.Camera.camera_far * 10} // Adjust the height of the shadow map
shadow-camera-near={10} // Adjust the near clipping plane of the shadow camera
shadow-camera-far={800} // Adjust the far clipping plane of the shadow camera
shadow-camera-left={-1 * roomConfig.scene.camera_far} // Set the left boundary for the shadow camera frustum
shadow-camera-right={roomConfig.scene.camera_far} // Set the right boundary for the shadow camera frustum
shadow-camera-top={roomConfig.scene.camera_far} // Set the top boundary for the shadow camera frustum
shadow-camera-bottom={-1 * roomConfig.scene.camera_far} // Set the bottom boundary for the shadow camera frustum
shadow-camera-left={-1 * roomConfig.Camera.camera_far} // Set the left boundary for the shadow camera frustum
shadow-camera-right={roomConfig.Camera.camera_far} // Set the right boundary for the shadow camera frustum
shadow-camera-top={roomConfig.Camera.camera_far} // Set the top boundary for the shadow camera frustum
shadow-camera-bottom={-1 * roomConfig.Camera.camera_far} // Set the bottom boundary for the shadow camera frustum
/>
</>
) : (
<directionalLight position={[0, 100, 0]} intensity={1.0} />
)}

{roomConfig.scene.vectorfield &&
{roomConfig.VectorDisplay.vectorfield &&
currentFrame.vectors !== undefined && (
<VectorField
vectors={currentFrame.vectors}
pathTracingSettings={roomConfig.PathTracer}
arrowsConfig={{
rescale: roomConfig.scene.vector_scale,
...roomConfig.arrows,
rescale: roomConfig.VectorDisplay.vector_scale,
...roomConfig.Arrows,
}}
/>
)}
Expand All @@ -500,7 +500,7 @@ export default function App() {
isDrawing={isDrawing}
setPoints={setPoints}
setHoveredId={setHoveredId}
sceneSettings={roomConfig.scene}
sceneSettings={roomConfig.Particle}
token={token}
highlight=""
visibleIndices={undefined}
Expand All @@ -516,7 +516,7 @@ export default function App() {
isDrawing={isDrawing}
setPoints={setPoints}
setHoveredId={setHoveredId}
sceneSettings={roomConfig.scene}
sceneSettings={roomConfig.Particle}
token={token}
visibleIndices={hoveredId}
highlight={"backside"}
Expand All @@ -529,7 +529,7 @@ export default function App() {
isDrawing={isDrawing}
setPoints={setPoints}
setHoveredId={setHoveredId}
sceneSettings={roomConfig.scene}
sceneSettings={roomConfig.Particle}
token={token}
visibleIndices={selectedIds}
highlight={"selection"}
Expand All @@ -542,7 +542,7 @@ export default function App() {
isDrawing={isDrawing}
setPoints={setPoints}
setHoveredId={setHoveredId}
sceneSettings={roomConfig.scene}
sceneSettings={roomConfig.Particle}
token={token}
visibleIndices={
new Set(currentFrame.constraints?.[0]?.indices)
Expand All @@ -554,18 +554,18 @@ export default function App() {
frame={currentFrame}
visibleIndices={selectedIds}
highlight="selection"
sceneSettings={roomConfig.scene}
sceneSettings={roomConfig.Particle}
/>
</>
)}
<BondInstances
frame={currentFrame}
visibleIndices={undefined}
highlight=""
sceneSettings={roomConfig.scene}
sceneSettings={roomConfig.Particle}
pathTracingSettings={roomConfig.PathTracer}
/>
{roomConfig.scene.simulation_box &&
{roomConfig.Visualization.simulation_box &&
!roomConfig.PathTracer.enabled && (
<SimulationCell frame={currentFrame} colorMode={colorMode} />
)}
Expand All @@ -574,8 +574,8 @@ export default function App() {
togglePlaying={setPlaying}
step={step}
setStep={setStep}
fps={roomConfig.scene.fps}
loop={roomConfig.scene.animation_loop}
fps={roomConfig.Camera.fps}
loop={roomConfig.Visualization.animation_loop}
length={length}
selectedFrames={selectedFrames}
/>
Expand Down Expand Up @@ -608,15 +608,15 @@ export default function App() {
hoveredId={hoveredId}
setHoveredId={setHoveredId}
/>
{roomConfig.scene.vectors[0] &&
roomConfig.scene.vectors.map((vector) => (
{roomConfig.VectorDisplay.vectors[0] &&
roomConfig.VectorDisplay.vectors.map((vector) => (
<PerParticleVectors
frame={currentFrame}
property={vector}
colorMode={colorMode}
arrowsConfig={{
rescale: roomConfig.scene.vector_scale,
...roomConfig.arrows,
rescale: roomConfig.VectorDisplay.vector_scale,
...roomConfig.Arrows,
}}
pathTracingSettings={roomConfig.PathTracer}
key={vector}
Expand Down
24 changes: 12 additions & 12 deletions app/src/components/cameraAndControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type CameraAndControls = {
};

type CameraAndControlsProps = {
roomConfig: any;
cameraConfig: any;
cameraAndControls: CameraAndControls;
setCameraAndControls: React.Dispatch<React.SetStateAction<CameraAndControls>>;
currentFrame: any;
Expand All @@ -67,7 +67,7 @@ type CameraAndControlsProps = {
};

const CameraAndControls: React.FC<CameraAndControlsProps> = ({
roomConfig,
cameraConfig,
cameraAndControls,
setCameraAndControls,
currentFrame,
Expand Down Expand Up @@ -180,7 +180,7 @@ const CameraAndControls: React.FC<CameraAndControlsProps> = ({
if (resetCamera) {
setCameraAndControls(resetCamera);
}
}, [roomConfig.scene.camera]);
}, [cameraConfig.camera]);

useEffect(() => {
if (!cameraRef.current || !controlsRef.current) {
Expand Down Expand Up @@ -239,28 +239,28 @@ const CameraAndControls: React.FC<CameraAndControlsProps> = ({

return (
<>
{roomConfig.scene.camera === "OrthographicCamera" && (
{cameraConfig.camera === "OrthographicCamera" && (
<OrthographicCamera
makeDefault
ref={cameraRef}
zoom={10}
near={roomConfig.scene.camera_near}
far={roomConfig.scene.camera_far}
near={cameraConfig.camera_near}
far={cameraConfig.camera_far}
>
<pointLight decay={0} intensity={Math.PI / 2} />
</OrthographicCamera>
)}
{roomConfig.scene.camera === "PerspectiveCamera" && (
{cameraConfig.camera === "PerspectiveCamera" && (
<PerspectiveCamera
makeDefault
ref={cameraRef}
near={roomConfig.scene.camera_near}
far={roomConfig.scene.camera_far}
near={cameraConfig.camera_near}
far={cameraConfig.camera_far}
>
<pointLight decay={0} intensity={Math.PI / 2} />
</PerspectiveCamera>
)}
{roomConfig.scene.controls === "OrbitControls" && (
{cameraConfig.controls === "OrbitControls" && (
<OrbitControls
makeDefault
onEnd={controlsOnEndFn}
Expand All @@ -269,15 +269,15 @@ const CameraAndControls: React.FC<CameraAndControlsProps> = ({
ref={controlsRef}
/>
)}
{roomConfig.scene.controls === "TrackballControls" && (
{cameraConfig.controls === "TrackballControls" && (
<TrackballControls
makeDefault
onEnd={controlsOnEndFn}
onChange={controlsOnChangeFn}
ref={controlsRef}
/>
)}
{roomConfig.scene.crosshair && controlsRef.current.target && (
{cameraConfig.crosshair && controlsRef.current.target && (
<MoveCameraTarget colorMode={colorMode} ref={crossHairRef} />
)}
</>
Expand Down
12 changes: 6 additions & 6 deletions app/src/components/floor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ export const Floor: any = ({ colorMode, roomConfig }: any) => {
<fog
attach="fog"
color={bsColor["--bs-body-bg"]}
near={roomConfig.scene.camera_far * 0.8}
far={roomConfig.scene.camera_far}
near={roomConfig.Camera.camera_far * 0.8}
far={roomConfig.Camera.camera_far}
/>
<Plane
args={[
roomConfig.scene.camera_far * 2,
roomConfig.scene.camera_far * 2,
roomConfig.Camera.camera_far * 2,
roomConfig.Camera.camera_far * 2,
1,
1,
]}
Expand All @@ -87,8 +87,8 @@ export const Floor: any = ({ colorMode, roomConfig }: any) => {
<Grid
position={[0, -4.95, 0]}
gridSpacing={10}
sizeX={roomConfig.scene.camera_far * 2}
sizeY={roomConfig.scene.camera_far * 2}
sizeX={roomConfig.Camera.camera_far * 2}
sizeY={roomConfig.Camera.camera_far * 2}
color={bsColor["--bs-secondary"]}
/>
</>
Expand Down
Loading

0 comments on commit 073a82d

Please sign in to comment.