@@ -4,6 +4,8 @@ import { vertexShader, fragmentShader, fragOpt, orthoVertex } from '@/components
44import { useGlobalStore , usePlotStore } from '@/GlobalStates' ;
55import { useShallow } from 'zustand/shallow' ;
66import { invalidate , useFrame } from '@react-three/fiber' ;
7+ import { deg2rad } from '@/utils/HelperFuncs' ;
8+ import { useCoordBounds } from '@/hooks/useCoordBounds' ;
79
810interface DataCubeProps {
911 volTexture : THREE . Data3DTexture [ ] | THREE . DataTexture [ ] | null ,
@@ -18,19 +20,16 @@ export const DataCube = ({ volTexture }: DataCubeProps ) => {
1820 } ) ) ) //We have to useShallow when returning an object instead of a state. I don't fully know the logic yet
1921 const {
2022 valueRange, xRange, yRange, zRange, quality, useOrtho,
21- animProg, cScale, cOffset, useFragOpt, transparency,
23+ animProg, cScale, cOffset, useFragOpt, transparency, maskTexture , maskValue ,
2224 nanTransparency, nanColor, vTransferRange, vTransferScale, fillValue} = usePlotStore ( useShallow ( state => ( {
23- valueRange : state . valueRange ,
24- xRange : state . xRange ,
25- yRange : state . yRange ,
26- zRange : state . zRange ,
27- quality : state . quality ,
28- useOrtho : state . useOrtho ,
29- animProg : state . animProg ,
30- cScale : state . cScale ,
31- cOffset : state . cOffset ,
32- useFragOpt : state . useFragOpt ,
25+ valueRange : state . valueRange , xRange : state . xRange ,
26+ yRange : state . yRange , zRange : state . zRange ,
27+ quality : state . quality , useOrtho : state . useOrtho ,
28+ animProg : state . animProg , cScale : state . cScale ,
29+ cOffset : state . cOffset , useFragOpt : state . useFragOpt ,
3330 transparency : state . transparency ,
31+ maskTexture : state . maskTexture ,
32+ maskValue : state . maskValue ,
3433 nanTransparency : state . nanTransparency ,
3534 nanColor : state . nanColor ,
3635 vTransferRange : state . vTransferRange ,
@@ -40,11 +39,15 @@ export const DataCube = ({ volTexture }: DataCubeProps ) => {
4039 const meshRef = useRef < THREE . Mesh > ( null ! ) ;
4140 const aspectRatio = shape . y / shape . x
4241 const timeRatio = shape . z / shape . x ;
42+ const { lonBounds, latBounds} = useCoordBounds ( )
43+
4344 const shaderMaterial = useMemo ( ( ) => new THREE . ShaderMaterial ( {
4445 glslVersion : THREE . GLSL3 ,
4546 uniforms : {
4647 modelViewMatrixInverse : { value : new THREE . Matrix4 ( ) } , // Used for Orthographic RayMarcher
4748 map : { value : volTexture } ,
49+ maskTexture : { value : maskTexture } ,
50+ maskValue : { value : maskValue } ,
4851 textureDepths : { value : new THREE . Vector3 ( textureArrayDepths [ 2 ] , textureArrayDepths [ 1 ] , textureArrayDepths [ 0 ] ) } ,
4952 cmap :{ value : colormap } ,
5053 cOffset :{ value : cOffset } ,
@@ -53,6 +56,8 @@ export const DataCube = ({ volTexture }: DataCubeProps ) => {
5356 scale : { value : shape } ,
5457 flatBounds :{ value : new THREE . Vector4 ( - xRange [ 1 ] , - xRange [ 0 ] , zRange [ 0 ] * timeRatio , zRange [ 1 ] * timeRatio ) } ,
5558 vertBounds :{ value : new THREE . Vector2 ( yRange [ 0 ] * aspectRatio , yRange [ 1 ] * aspectRatio ) } ,
59+ latBounds : { value : new THREE . Vector2 ( deg2rad ( latBounds [ 0 ] ) , deg2rad ( latBounds [ 1 ] ) ) } ,
60+ lonBounds : { value : new THREE . Vector2 ( deg2rad ( lonBounds [ 0 ] ) , deg2rad ( lonBounds [ 1 ] ) ) } ,
5661 steps : { value : quality } ,
5762 animateProg : { value : animProg } ,
5863 transparency : { value : transparency } ,
@@ -82,6 +87,8 @@ export const DataCube = ({ volTexture }: DataCubeProps ) => {
8287 uniforms . scale . value = shape ;
8388 uniforms . flatBounds . value . set ( - xRange [ 1 ] , - xRange [ 0 ] , zRange [ 0 ] * timeRatio , zRange [ 1 ] * timeRatio ) ;
8489 uniforms . vertBounds . value . set ( yRange [ 0 ] * aspectRatio , yRange [ 1 ] * aspectRatio ) ;
90+ uniforms . latBounds . value = new THREE . Vector2 ( deg2rad ( latBounds [ 0 ] ) , deg2rad ( latBounds [ 1 ] ) )
91+ uniforms . lonBounds . value = new THREE . Vector2 ( deg2rad ( lonBounds [ 0 ] ) , deg2rad ( lonBounds [ 1 ] ) )
8592 uniforms . steps . value = quality ;
8693 uniforms . animateProg . value = animProg ;
8794 uniforms . transparency . value = transparency ;
@@ -90,9 +97,10 @@ export const DataCube = ({ volTexture }: DataCubeProps ) => {
9097 uniforms . opacityMag . value = vTransferScale ;
9198 uniforms . useClipScale . value = vTransferRange ;
9299 uniforms . fillValue . value = fillValue ;
100+ uniforms . maskValue . value = maskValue
93101 invalidate ( ) // Needed because Won't trigger re-render if camera is stationary.
94102 }
95- } , [ volTexture , shape , colormap , cOffset , cScale , valueRange , xRange , yRange , zRange , aspectRatio , quality , animProg , transparency , nanTransparency , nanColor , fillValue , vTransferScale , vTransferRange ] ) ;
103+ } , [ volTexture , shape , colormap , cOffset , cScale , valueRange , xRange , yRange , zRange , aspectRatio , latBounds , lonBounds , quality , animProg , transparency , nanTransparency , nanColor , maskValue , fillValue , vTransferScale , vTransferRange ] ) ;
96104 useFrame ( ( { camera} ) => { // This calculates InverseModel matrix for the orthographic raymarcher
97105 if ( ! useOrtho || ! meshRef . current || ! shaderMaterial ) return ;
98106 meshRef . current . modelViewMatrix . multiplyMatrices ( camera . matrixWorldInverse , meshRef . current . matrixWorld ) ;
0 commit comments