-
Notifications
You must be signed in to change notification settings - Fork 50
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
Showing
12 changed files
with
323 additions
and
82 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
38 changes: 38 additions & 0 deletions
38
src/components/Universe/Graph/Connections/LineInstance.tsx/index.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,38 @@ | ||
// LineInstance.tsx | ||
import { Segment as DreiSegment, SegmentObject } from '@react-three/drei' | ||
import { useFrame } from '@react-three/fiber' | ||
import { memo, useRef } from 'react' | ||
import { Vector3 } from 'three' | ||
|
||
type LineComponentProps = { | ||
sourceX: number | ||
sourceY: number | ||
sourceZ: number | ||
targetX: number | ||
targetY: number | ||
targetZ: number | ||
color: string | ||
} | ||
|
||
const vec = new Vector3(0, 0, 0) | ||
|
||
export const LineInstance = memo((props: LineComponentProps) => { | ||
const { sourceX, sourceY, sourceZ, targetX, targetY, targetZ, color } = props | ||
|
||
const ref = useRef<SegmentObject | null>(null) | ||
|
||
useFrame(() => { | ||
if (ref.current) { | ||
ref.current.start.set(sourceX || 0, sourceY || 0, sourceZ || 0) | ||
ref.current.end.set(targetX, targetY, targetZ) | ||
} | ||
}) | ||
|
||
return ( | ||
<> | ||
<DreiSegment ref={ref} color={color} end={vec} start={vec} /> | ||
</> | ||
) | ||
}) | ||
|
||
LineInstance.displayName = 'LineInstance' |
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
37 changes: 32 additions & 5 deletions
37
src/components/Universe/Graph/Cubes/NodePoints/Point/index.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 |
---|---|---|
@@ -1,12 +1,39 @@ | ||
import { Billboard, Instance } from '@react-three/drei' | ||
import { useFrame } from '@react-three/fiber' | ||
import { memo, useRef } from 'react' | ||
import { Group } from 'three' | ||
import { useGraphStore } from '~/stores/useGraphStore' | ||
|
||
type Props = { | ||
color: string | ||
scale: number | ||
name: string | ||
} | ||
|
||
export const Point = ({ color, scale }: Props) => ( | ||
<Billboard follow lockX={false} lockY={false} lockZ={false}> | ||
<Instance color={color} scale={scale} /> | ||
</Billboard> | ||
) | ||
export const Point = memo(({ color, scale, name }: Props) => { | ||
const nodeRef = useRef<Group | null>(null) | ||
|
||
useFrame(() => { | ||
const { searchQuery } = useGraphStore.getState() | ||
|
||
if (!nodeRef.current) { | ||
return | ||
} | ||
|
||
if (searchQuery) { | ||
const dynamicScale = name.toLowerCase().includes(searchQuery.toLowerCase()) ? 1 : 0.1 | ||
|
||
nodeRef.current.scale.set(dynamicScale, dynamicScale, dynamicScale) | ||
} else { | ||
nodeRef.current.scale.set(1, 1, 1) | ||
} | ||
}) | ||
|
||
return ( | ||
<Billboard ref={nodeRef} follow lockX={false} lockY={false} lockZ={false}> | ||
<Instance color={color} scale={scale} /> | ||
</Billboard> | ||
) | ||
}) | ||
|
||
Point.displayName = 'Point' |
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
Oops, something went wrong.