Skip to content

Commit

Permalink
split settings (#737)
Browse files Browse the repository at this point in the history
* split settings

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* rename settings

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* configure selection and hover opactiy

* remove unused code

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix tests

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
PythonFZ and pre-commit-ci[bot] authored Nov 18, 2024
1 parent 7c7286b commit dc6153e
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 233 deletions.
Binary file modified app/bun.lockb
Binary file not shown.
90 changes: 46 additions & 44 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,25 +106,28 @@ export default function App() {
scale_vector_thickness: false,
opacity: 1.0,
},
scene: {
fps: 30,
material: "MeshStandardMaterial",
Particle: {
particle_size: 1.0,
bond_size: 1.0,
animation_loop: false,
simulation_box: true,
vectorfield: true,
controls: "OrbitControls",
vectors: [],
vector_scale: 1.0,
material: "MeshStandardMaterial",
selection_color: "#ffa500",
hover_opacity: 0.8,
selection_opacity: 0.5,
},
Visualization: {
simulation_box: true,
floor: false,
frame_update: true,
animation_loop: false,
},
Camera: {
camera: "PerspectiveCamera",
camera_near: 0.1,
camera_far: 300,
frame_update: true,
crosshair: false,
floor: false,
synchronize_camera: true,
fps: 30,
controls: "OrbitControls",
},
PathTracer: {
enabled: false,
Expand All @@ -134,6 +137,11 @@ export default function App() {
clearcoat: 0.0,
clearcoatRoughness: 0.0,
},
VectorDisplay: {
vectorfield: true,
vectors: "",
vector_scale: 1.0,
},
});

const [isAuthenticated, setIsAuthenticated] = useState<boolean>(true);
Expand All @@ -143,12 +151,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 +172,7 @@ export default function App() {
token,
cameraAndControls,
setCameraAndControls,
roomConfig.scene.synchronize_camera,
roomConfig.Camera.synchronize_camera,
);
setupFrames(
token,
Expand All @@ -179,7 +181,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 +450,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 +463,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 +502,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 +518,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 +531,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 +544,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 +556,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 +576,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 +610,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 dc6153e

Please sign in to comment.