-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee05ada
commit 2b3188f
Showing
13 changed files
with
575 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
11 changes: 11 additions & 0 deletions
11
applications/visualizer/frontend/settings/threeDSettings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const CAMERA_FOV = 60 | ||
export const CAMERA_POSITION = [3, 0.15, 3] | ||
export const CAMERA_NEAR = 1 | ||
export const CAMERA_FAR = 5000 | ||
|
||
export const LIGHT_1_COLOR = 0xeb4634 | ||
export const LIGHT_1_POSITION = [1, 0.75, 0.5] | ||
export const LIGHT_2_COLOR = 0xccccff | ||
export const LIGHT_2_POSITION = [-1, 0.75, -0.5] | ||
|
||
export const SCENE_BACKGROUND = 'grey' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
applications/visualizer/frontend/src/components/viewers/ThreeD/Loader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Html, useProgress } from "@react-three/drei"; | ||
|
||
const Loader = () => { | ||
const { progress } = useProgress(); | ||
|
||
return ( | ||
<Html center> | ||
<span style={{ color: "white" }}>{Math.floor(progress)} % loaded</span> | ||
</Html> | ||
); | ||
}; | ||
|
||
export default Loader; |
18 changes: 18 additions & 0 deletions
18
applications/visualizer/frontend/src/components/viewers/ThreeD/STLMesh.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React, {FC} from "react"; | ||
|
||
interface Props { | ||
stl: any; | ||
color: string; | ||
opacity: number; | ||
} | ||
|
||
const STLMesh: FC<Props> = ({color, opacity, stl}) => { | ||
return ( | ||
<mesh castShadow receiveShadow> | ||
<primitive attach="geometry" object={stl}/> | ||
<meshStandardMaterial color={color} opacity={opacity} transparent/> | ||
</mesh> | ||
); | ||
}; | ||
|
||
export default STLMesh; |
32 changes: 32 additions & 0 deletions
32
applications/visualizer/frontend/src/components/viewers/ThreeD/STLViewer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, {FC, Suspense} from "react"; | ||
import {Center, Loader} from "@react-three/drei"; | ||
import {useLoader} from "@react-three/fiber"; | ||
import {STLLoader} from "three/examples/jsm/loaders/STLLoader"; | ||
import {BufferGeometry} from 'three'; | ||
import {Instance} from "./ThreeDViewer.tsx"; | ||
import STLMesh from "./STLMesh.tsx"; | ||
|
||
interface Props { | ||
instances: Instance[]; | ||
} | ||
|
||
const STLViewer: FC<Props> = ({instances}) => { | ||
const stl = useLoader<STLLoader, BufferGeometry[]>(STLLoader, instances.map(i => i.url)); | ||
|
||
return ( | ||
<Center> | ||
<group rotation={[-Math.PI / 2, 0, 0]}> | ||
{stl.map((stl, idx) => ( | ||
<STLMesh | ||
key={idx} | ||
stl={stl} | ||
opacity={instances[idx].opacity} | ||
color={instances[idx].color} | ||
/> | ||
))} | ||
</group> | ||
</Center> | ||
); | ||
}; | ||
|
||
export default STLViewer; |
67 changes: 67 additions & 0 deletions
67
applications/visualizer/frontend/src/components/viewers/ThreeD/ThreeDViewer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import {Suspense, useEffect, useState} from "react"; | ||
import {CameraControls, PerspectiveCamera} from "@react-three/drei"; | ||
import { | ||
CAMERA_FAR, | ||
CAMERA_FOV, | ||
CAMERA_NEAR, | ||
CAMERA_POSITION, LIGHT_1_COLOR, LIGHT_1_POSITION, LIGHT_2_COLOR, LIGHT_2_POSITION, | ||
SCENE_BACKGROUND | ||
} from "../../../../settings/threeDSettings.ts"; | ||
import {useGlobalContext} from "../../../contexts/GlobalContext.tsx"; | ||
import {useSelector} from "react-redux"; | ||
import STLViewer from "./STLViewer.tsx"; | ||
import {Canvas} from "@react-three/fiber"; | ||
import Loader from "./Loader.tsx"; | ||
|
||
export interface Instance { | ||
id: string; | ||
url: string; | ||
color: string; | ||
opacity: number; | ||
} | ||
|
||
function ThreeDViewer() { | ||
|
||
const [showNeurons, setShowNeurons] = useState<boolean>(true); | ||
const [showSynapses, setShowSynapses] = useState<boolean>(true); | ||
const [instances, setInstances] = useState<Instance[]>([]) | ||
|
||
const {workspaces} = useGlobalContext(); | ||
const workspaceId = useSelector(state => state.workspaceId); | ||
const workspace = workspaces[workspaceId]; | ||
|
||
useEffect(() => { | ||
// TODO: Implement | ||
if (showNeurons) { | ||
setInstances([ | ||
{ | ||
id: 'bone', | ||
url: 'bone.stl', | ||
color: 'white', | ||
opacity: 1 | ||
} | ||
]) | ||
} | ||
}, [showNeurons, showSynapses]); | ||
|
||
return ( | ||
<Canvas style={{backgroundColor: SCENE_BACKGROUND}} frameloop="demand"> | ||
<Suspense fallback={<Loader/>}> | ||
<PerspectiveCamera | ||
makeDefault | ||
fov={CAMERA_FOV} | ||
aspect={window.innerWidth / window.innerHeight} | ||
position={CAMERA_POSITION} | ||
near={CAMERA_NEAR} | ||
far={CAMERA_FAR} | ||
/> | ||
<CameraControls makeDefault/> | ||
<directionalLight color={LIGHT_1_COLOR} position={LIGHT_1_POSITION}/> | ||
<directionalLight color={LIGHT_2_COLOR} position={LIGHT_2_POSITION}/> | ||
<STLViewer instances={instances}/> | ||
</Suspense> | ||
</Canvas> | ||
); | ||
} | ||
|
||
export default ThreeDViewer; |
9 changes: 0 additions & 9 deletions
9
applications/visualizer/frontend/src/components/viewers/ThreeDViewer.tsx
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
applications/visualizer/frontend/src/layout-manager/componentMap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.