From 395337f4396684bd4c6752281da8ed6c94bb0398 Mon Sep 17 00:00:00 2001 From: afonso Date: Fri, 26 Apr 2024 16:44:40 +0100 Subject: [PATCH] CELE-20 feat: Keep meshes consistent --- .../visualizer/frontend/settings/threeDSettings.ts | 3 +-- .../src/components/viewers/ThreeD/STLMesh.tsx | 14 +++++++++++--- .../src/components/viewers/ThreeD/STLViewer.tsx | 7 +++++-- .../src/components/viewers/ThreeD/ThreeDViewer.tsx | 5 +++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/applications/visualizer/frontend/settings/threeDSettings.ts b/applications/visualizer/frontend/settings/threeDSettings.ts index 3edd893b..80aa3a4f 100644 --- a/applications/visualizer/frontend/settings/threeDSettings.ts +++ b/applications/visualizer/frontend/settings/threeDSettings.ts @@ -3,8 +3,7 @@ export const CAMERA_POSITION = [0, 0, 50] export const CAMERA_NEAR = 0.1 export const CAMERA_FAR = 2000 -export const LIGHT_1_COLOR = 0xeb4634 -export const LIGHT_1_POSITION = [5, 5, 5] +export const LIGHT_1_COLOR = 0x404040 export const LIGHT_2_COLOR = 0xccccff export const LIGHT_2_POSITION = [-1, 0.75, -0.5] diff --git a/applications/visualizer/frontend/src/components/viewers/ThreeD/STLMesh.tsx b/applications/visualizer/frontend/src/components/viewers/ThreeD/STLMesh.tsx index a136f43b..928ba4dd 100644 --- a/applications/visualizer/frontend/src/components/viewers/ThreeD/STLMesh.tsx +++ b/applications/visualizer/frontend/src/components/viewers/ThreeD/STLMesh.tsx @@ -3,15 +3,17 @@ import {useGlobalContext} from "../../../contexts/GlobalContext.tsx"; import {useSelector} from "react-redux"; import {Workspace} from "../../../models/workspace.ts"; import {RootState} from "../../../layout-manager/layoutManagerFactory.ts"; +import {DoubleSide, NormalBlending} from "three"; interface Props { stl: any; id: string; color: string; opacity: number; + renderOrder: number; } -const STLMesh: FC = ({id, color, opacity, stl}) => { +const STLMesh: FC = ({id, color, opacity, renderOrder, stl}) => { const {workspaces} = useGlobalContext(); const workspaceId = useSelector((state:RootState) => state.workspaceId); const workspace: Workspace = workspaces[workspaceId]; @@ -24,9 +26,15 @@ const STLMesh: FC = ({id, color, opacity, stl}) => { // TODO: Add outlines for selected // TODO: Test wireframe return ( - + - + ); }; diff --git a/applications/visualizer/frontend/src/components/viewers/ThreeD/STLViewer.tsx b/applications/visualizer/frontend/src/components/viewers/ThreeD/STLViewer.tsx index d3ff1c6a..72ba3cdf 100644 --- a/applications/visualizer/frontend/src/components/viewers/ThreeD/STLViewer.tsx +++ b/applications/visualizer/frontend/src/components/viewers/ThreeD/STLViewer.tsx @@ -1,6 +1,6 @@ import React, {FC} from "react"; import {Center, Select} from "@react-three/drei"; -import {useLoader} from "@react-three/fiber"; +import {useLoader, useThree} from "@react-three/fiber"; import {STLLoader} from "three/examples/jsm/loaders/STLLoader"; import {BufferGeometry} from 'three'; import {Instance} from "./ThreeDViewer.tsx"; @@ -14,10 +14,12 @@ const STLViewer: FC = ({instances}) => { // Todo: Fix typescript warning // Check if useLoader caches or do we need to do it ourselves const stlObjects = useLoader(STLLoader, instances.map(i => i.url)); + const {scene} = useThree(); + window.myScene = scene; return (
- + {stlObjects.map((stl, idx) => ( = ({instances}) => { id={instances[idx].id} opacity={instances[idx].opacity} color={instances[idx].color} + renderOrder={idx} /> ))} diff --git a/applications/visualizer/frontend/src/components/viewers/ThreeD/ThreeDViewer.tsx b/applications/visualizer/frontend/src/components/viewers/ThreeD/ThreeDViewer.tsx index 333a62ff..1777d4c6 100644 --- a/applications/visualizer/frontend/src/components/viewers/ThreeD/ThreeDViewer.tsx +++ b/applications/visualizer/frontend/src/components/viewers/ThreeD/ThreeDViewer.tsx @@ -25,8 +25,9 @@ function ThreeDViewer() { const [showSynapses, setShowSynapses] = useState(true); const [instances, setInstances] = useState([]) + + useEffect(() => { - // TODO: Understand why adal disappears if (showNeurons) { setInstances([ { @@ -57,7 +58,7 @@ function ThreeDViewer() { far={CAMERA_FAR} /> - +