-
Notifications
You must be signed in to change notification settings - Fork 1
App 15105 create entity relationships #379
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
bba2d8d
feat: hover link relationship
mattmacf98 422fb44
allow specifying index mapping in ui
mattmacf98 2d0bfa7
move link hovers to a context
mattmacf98 874b1a9
clean up hover updater types
mattmacf98 7756b30
move hover components to their own folder
mattmacf98 a75bc32
update to use the useTrait hook
mattmacf98 30480fa
lint
mattmacf98 9e4265c
Merge branch 'main' into APP-15105-create-entity-relationships
mattmacf98 8d5af6d
stop prop on indexMapping keypress
mattmacf98 59f3cba
pull AddRelationship secion out of Details
mattmacf98 1dbc1d3
cleanup
mattmacf98 a9ba0a7
Merge branch 'main' into APP-15105-create-entity-relationships
mattmacf98 c92896d
revert package.json removals, pnpm i
mattmacf98 7167a87
format check
mattmacf98 690c224
only show relationship button for pcds and arrows for now
mattmacf98 4969a0a
changeset
mattmacf98 d2236fe
init
micheal-parks 5c46a77
fix imports
mattmacf98 8e73598
Merge branch 'main' into APP-15105-create-entity-relationships
mattmacf98 001e983
use pooled vec3
mattmacf98 9a16051
address comments
mattmacf98 56194c7
add hover trait in and add prop for link type
mattmacf98 4bfe470
clean
mattmacf98 36e95ea
rename ox -> oX
mattmacf98 a0f1f64
Merge branch 'main' into APP-15105-create-entity-relationships
mattmacf98 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@viamrobotics/motion-tools': minor | ||
| --- | ||
|
|
||
| enable hoverlinking for pcds and poses |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,159 @@ | ||
| import { Vector3 } from 'three' | ||
| import type { Entity } from 'koota' | ||
| import { traits } from '$lib/ecs' | ||
| import type { IntersectionEvent } from '@threlte/extras' | ||
|
|
||
| export interface HoverInfo { | ||
| index: number | ||
| position: { | ||
| x: number | ||
| y: number | ||
| z: number | ||
| } | ||
| orientation?: { | ||
| x: number | ||
| y: number | ||
| z: number | ||
| } | ||
| } | ||
|
|
||
| export const getClosestArrow = (positions: Float32Array, point: Vector3): HoverInfo => { | ||
| let smallestDistance = Infinity | ||
| let index = -1 | ||
|
|
||
| for (let i = 0; i < positions.length; i += 6) { | ||
| const x = positions[i] / 1000 | ||
| const y = positions[i + 1] / 1000 | ||
| const z = positions[i + 2] / 1000 | ||
|
|
||
| const distance = point.distanceToSquared(new Vector3(x, y, z)) | ||
mattmacf98 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (distance < smallestDistance) { | ||
| smallestDistance = distance | ||
| index = i | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| index: Math.floor(index / 6), | ||
| position: { | ||
| x: positions[index] / 1000, | ||
| y: positions[index + 1] / 1000, | ||
| z: positions[index + 2] / 1000, | ||
| }, | ||
| orientation: { | ||
| x: positions[index + 3], | ||
| y: positions[index + 4], | ||
| z: positions[index + 5], | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| export const getClosestPoint = (positions: Float32Array, point: Vector3): HoverInfo => { | ||
| let smallestDistance = Infinity | ||
| let index = -1 | ||
|
|
||
| for (let i = 0; i < positions.length; i += 3) { | ||
| const x = positions[i] | ||
| const y = positions[i + 1] | ||
| const z = positions[i + 2] | ||
|
|
||
| const distance = point.distanceToSquared(new Vector3(x, y, z)) | ||
|
|
||
| if (distance < smallestDistance) { | ||
| smallestDistance = distance | ||
| index = i | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| index: Math.floor(index / 3), | ||
| position: { | ||
| x: positions[index], | ||
| y: positions[index + 1], | ||
| z: positions[index + 2], | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| export const getPointAtIndex = (positions: Float32Array, index: number): HoverInfo | null => { | ||
| if (index < 0 || index >= positions.length / 3) { | ||
| return null | ||
| } | ||
| return { | ||
| index, | ||
| position: { | ||
| x: positions[index * 3], | ||
| y: positions[index * 3 + 1], | ||
| z: positions[index * 3 + 2], | ||
| }, | ||
| } | ||
| } | ||
| export const getArrowAtIndex = (positions: Float32Array, index: number): HoverInfo | null => { | ||
| if (index < 0 || index >= positions.length / 6) { | ||
| return null | ||
| } | ||
| return { | ||
| index, | ||
| position: { | ||
| x: positions[index * 6] / 1000, | ||
| y: positions[index * 6 + 1] / 1000, | ||
| z: positions[index * 6 + 2] / 1000, | ||
| }, | ||
| orientation: { | ||
| x: positions[index * 6 + 3], | ||
| y: positions[index * 6 + 4], | ||
| z: positions[index * 6 + 5], | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| export const updateHoverInfo = ( | ||
| entity: Entity, | ||
| hoverEvent: IntersectionEvent<MouseEvent> | ||
| ): HoverInfo | null => { | ||
| const { index, point } = hoverEvent | ||
| if (index === -1) { | ||
| return null | ||
| } | ||
|
|
||
| const hoverPosition = new Vector3(point.x, point.y, point.z) | ||
|
|
||
| let hoverInfo: HoverInfo | null = null | ||
|
|
||
| if (entity.has(traits.Arrows)) { | ||
| const closestArrow = getClosestArrow( | ||
| entity.get(traits.Positions) as Float32Array, | ||
| hoverPosition | ||
| ) | ||
| if (closestArrow) { | ||
| hoverInfo = closestArrow | ||
| } | ||
| } else if (entity.has(traits.Points)) { | ||
| const positions = entity.get(traits.BufferGeometry)?.attributes.position.array as Float32Array | ||
| const closestPoint = getClosestPoint(positions, hoverPosition) | ||
| if (closestPoint) { | ||
| hoverInfo = closestPoint | ||
| } | ||
| } | ||
|
|
||
| return hoverInfo | ||
| } | ||
|
|
||
| export const getLinkedHoverInfo = (index: number, linkedEntity: Entity): HoverInfo | null => { | ||
| if (linkedEntity.has(traits.Arrows)) { | ||
| const closestArrow = getArrowAtIndex(linkedEntity.get(traits.Positions) as Float32Array, index) | ||
| if (closestArrow) { | ||
| return closestArrow | ||
| } | ||
| } else if (linkedEntity.has(traits.Points)) { | ||
| const positions = linkedEntity.get(traits.BufferGeometry)?.attributes.position | ||
| .array as Float32Array | ||
| const closestPoint = getPointAtIndex(positions, index) | ||
| if (closestPoint) { | ||
| return closestPoint | ||
| } | ||
| } | ||
|
|
||
| return null | ||
| } | ||
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.