-
Notifications
You must be signed in to change notification settings - Fork 9
fix(ui): Add triangular meshes and line support [FLOW-DEV-18] #1969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
billcookie
wants to merge
7
commits into
main
Choose a base branch
from
FLOW-FE-417
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fcf6e72
fix(ui): add support for FlowGeometry3D and integrate proj4 for coord…
billcookie aa7f842
fix(ui): add FlowGeometry3DData component and separate out triangular…
billcookie f81a927
fix(ui): prettier
billcookie ba2446d
Merge branch 'main' into FLOW-FE-417
billcookie 3bf1ca1
fix(ui): refactor
billcookie 06d84ad
Merge branch 'main' into FLOW-FE-417
billcookie 51c5c13
Merge branch 'main' into FLOW-FE-417
billcookie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
113 changes: 113 additions & 0 deletions
113
ui/src/components/visualizations/Cesium/FlowGeometry3DData.tsx
This file contains hidden or 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,113 @@ | ||
| import { | ||
| BoundingSphere, | ||
| Primitive, | ||
| ShowGeometryInstanceAttribute, | ||
| } from "cesium"; | ||
| import { memo, useEffect, useRef } from "react"; | ||
| import { useCesium } from "resium"; | ||
|
|
||
| import { | ||
| convertFlowGeometry3DCollectionToPrimitives, | ||
| type FlowGeometry3DFeature, | ||
| type FlowGeometry3DFeatureInstanceData, | ||
| } from "./utils/flowGeometry3DToPrimitives"; | ||
|
|
||
| type Props = { | ||
| flowGeometry3DData: { | ||
| type: "FeatureCollection"; | ||
| features: FlowGeometry3DFeature[]; | ||
| } | null; | ||
| selectedFeatureId?: string | null; | ||
| showSelectedFeatureOnly: boolean; | ||
| setBoundingSphere: (value: BoundingSphere | null) => void; | ||
| }; | ||
|
|
||
| const FlowGeometry3DData: React.FC<Props> = ({ | ||
| flowGeometry3DData, | ||
| selectedFeatureId, | ||
| showSelectedFeatureOnly, | ||
| setBoundingSphere, | ||
| }) => { | ||
| const { viewer } = useCesium(); | ||
| const meshPrimitiveRef = useRef<Primitive | null>(null); | ||
| const linePrimitiveRef = useRef<Primitive | null>(null); | ||
| const featureMapRef = useRef<Map<string, FlowGeometry3DFeatureInstanceData>>( | ||
| new Map(), | ||
| ); | ||
|
|
||
| // Build primitives from data | ||
| useEffect(() => { | ||
| if (!flowGeometry3DData || !viewer) return; | ||
|
|
||
| if (meshPrimitiveRef.current) { | ||
| viewer.scene.primitives.remove(meshPrimitiveRef.current); | ||
| meshPrimitiveRef.current = null; | ||
| } | ||
| if (linePrimitiveRef.current) { | ||
| viewer.scene.primitives.remove(linePrimitiveRef.current); | ||
| linePrimitiveRef.current = null; | ||
| } | ||
| featureMapRef.current.clear(); | ||
|
|
||
| const { meshPrimitive, linePrimitive, featureMap, boundingSphere } = | ||
| convertFlowGeometry3DCollectionToPrimitives(flowGeometry3DData.features); | ||
|
|
||
| meshPrimitiveRef.current = meshPrimitive; | ||
| linePrimitiveRef.current = linePrimitive; | ||
| featureMapRef.current = featureMap; | ||
|
|
||
| if (meshPrimitive) viewer.scene.primitives.add(meshPrimitive); | ||
| if (linePrimitive) viewer.scene.primitives.add(linePrimitive); | ||
|
|
||
| if (boundingSphere) { | ||
| viewer.camera.flyToBoundingSphere(boundingSphere, { duration: 1.5 }); | ||
| setBoundingSphere(boundingSphere); | ||
| } | ||
| }, [flowGeometry3DData, viewer, setBoundingSphere]); | ||
|
|
||
| // Handle show/hide based on selection | ||
| useEffect(() => { | ||
| if (!viewer) return; | ||
|
|
||
| const applyVisibility = (primitive: Primitive | null) => { | ||
| if (!primitive || !(primitive as any).ready) return; | ||
| featureMapRef.current.forEach((entry, id) => { | ||
| const isSelected = id === selectedFeatureId; | ||
| const shouldShow = !showSelectedFeatureOnly || isSelected; | ||
|
|
||
| entry.meshInstanceIds.forEach((instanceId) => { | ||
| const attrs = | ||
| meshPrimitiveRef.current?.getGeometryInstanceAttributes(instanceId); | ||
| if (attrs) | ||
| attrs.show = ShowGeometryInstanceAttribute.toValue(shouldShow); | ||
| }); | ||
| entry.lineInstanceIds.forEach((instanceId) => { | ||
| const attrs = | ||
| linePrimitiveRef.current?.getGeometryInstanceAttributes(instanceId); | ||
| if (attrs) | ||
| attrs.show = ShowGeometryInstanceAttribute.toValue(shouldShow); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| // Primitives are synchronous (asynchronous: false), so they're ready immediately | ||
| applyVisibility(meshPrimitiveRef.current); | ||
| applyVisibility(linePrimitiveRef.current); | ||
| }, [viewer, showSelectedFeatureOnly, selectedFeatureId]); | ||
|
|
||
| // Cleanup on unmount | ||
| useEffect(() => { | ||
| return () => { | ||
| if (viewer) { | ||
| if (meshPrimitiveRef.current) | ||
| viewer.scene.primitives.remove(meshPrimitiveRef.current); | ||
| if (linePrimitiveRef.current) | ||
| viewer.scene.primitives.remove(linePrimitiveRef.current); | ||
| } | ||
| }; | ||
| }, [viewer]); | ||
|
|
||
| return null; | ||
| }; | ||
|
|
||
| export default memo(FlowGeometry3DData); | ||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.