Skip to content

Commit

Permalink
Make obstacle coloring declarative (viamrobotics#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanlookpotts authored Nov 28, 2023
1 parent 5b8b68c commit f4f9622
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/blocks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viamrobotics/prime-blocks",
"version": "0.0.17",
"version": "0.0.18",
"publishConfig": {
"access": "public"
},
Expand Down
1 change: 1 addition & 0 deletions packages/blocks/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export type {
BoxGeometry,
Geometry,
Obstacle,
Plans,
} from './navigation-map/types';
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from 'maplibre-gl';
import { view } from '../stores';
import * as math from '../lib/math';
import { theme } from '@viamrobotics/prime-core/theme';
interface $$Events extends Record<string, unknown> {
/** Fires when a rectangle is drawn. */
Expand Down Expand Up @@ -128,6 +129,6 @@ $: if (drawing) {
on:create={handleGeometryCreate}
/>
{/if}
<T.MeshPhongMaterial color="red" />
<T.MeshPhongMaterial color={theme.extend.colors.cyberpunk} />
</T.Mesh>
</T.Group>
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<script lang="ts">
import { IconButton, Label, TextInput } from '@viamrobotics/prime-core';
import {
IconButton,
Label,
TextInput,
Tooltip,
} from '@viamrobotics/prime-core';
import { LngLat, LngLatBounds } from 'maplibre-gl';
import {
type LngLat as LngLatInternal,
Expand Down Expand Up @@ -103,7 +108,7 @@ $: debugMode = $environment === 'debug';
</li>
{/if}

{#each $obstacles as { name, location, geometries }, index (index)}
{#each $obstacles as { name, location, geometries, color, label }, index (index)}
<li
class="group flex min-h-[30px] items-center border-b border-b-medium pl-2 leading-[1] last:border-b-0"
class:pb-3={debugMode}
Expand All @@ -113,7 +118,9 @@ $: debugMode = $environment === 'debug';
>
<button
class="w-full text-left"
on:click={() => ($selected = name)}
on:click={() => {
$selected = $selected === name ? null : name;
}}
>
<div class="flex items-center justify-between gap-1.5">
<small>{name}</small>
Expand All @@ -137,6 +144,17 @@ $: debugMode = $environment === 'debug';
handleSelect({ name, location });
}}
/>
<Tooltip
let:tooltipID
location="right"
>
<div
aria-describedby={tooltipID}
class="m-2 h-3.5 w-3.5"
style:background-color={color}
/>
<p slot="description">{label}</p>
</Tooltip>
</div>
</div>
{#if debugMode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ useMapLibreEvent('mousedown', handleMapPointerDown);
{/if}

<T.MeshPhongMaterial
color={active
? theme.extend.colors['solar-power']
: theme.extend.colors['power-wire']}
color={active ? theme.extend.colors['solar-power'] : obstacle.color}
/>
</T.Mesh>
{/each}
3 changes: 3 additions & 0 deletions packages/blocks/src/lib/navigation-map/lib/create-obstacle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Obstacle, Shapes, LngLat } from '$lib';
import { theme } from '@viamrobotics/prime-core/theme';
import { createGeometry } from './create-geometry';

export const createObstacle = (
Expand All @@ -10,5 +11,7 @@ export const createObstacle = (
name,
location: { lng: lngLat.lng, lat: lngLat.lat },
geometries: [createGeometry(type)],
label: 'static',
color: theme.extend.colors.cyberpunk,
};
};
2 changes: 2 additions & 0 deletions packages/blocks/src/lib/navigation-map/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface Obstacle {
name: string;
location: LngLat;
geometries: Geometry[];
color: string;
label: string;
}

export interface Plans {
Expand Down
38 changes: 34 additions & 4 deletions packages/blocks/src/routes/navigation-map.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ import {
type CapsuleGeometry,
type SphereGeometry,
type BoxGeometry,
type Obstacle,
type Waypoint,
type Plans,
} from '$lib';
import type { Map } from 'maplibre-gl';
import { Label, SliderInput } from '@viamrobotics/prime-core';
import { ViamObject3D } from '@viamrobotics/three';
import { theme } from '@viamrobotics/prime-core/theme';
const waypoints = [
const waypoints: Waypoint[] = [
{ lng: -73.968_899_054_033_95, lat: 40.663_071_086_044, id: '0' },
{ lng: -73.972_162_444_595_26, lat: 40.661_759_669_002_69, id: '1' },
{ lng: -73.969_889_726_168_73, lat: 40.659_372_529_105_895, id: '2' },
];
const obstacles = [
const obstacles: Obstacle[] = [
{
name: 'obstacle 1',
location: {
Expand All @@ -31,6 +35,8 @@ const obstacles = [
radius: 20,
} as SphereGeometry,
],
color: theme.extend.colors.cyberpunk,
label: 'static',
},
{
name: 'obstacle 2',
Expand All @@ -45,6 +51,8 @@ const obstacles = [
radius: 200,
} as SphereGeometry,
],
color: theme.extend.colors.cyberpunk,
label: 'static',
},
{
name: 'obstacle 3',
Expand All @@ -64,9 +72,11 @@ const obstacles = [
})(),
} as CapsuleGeometry,
],
color: theme.extend.colors.cyberpunk,
label: 'static',
},
{
name: 'obstacle 4',
name: 'transient obstacle 4',
location: {
lng: -74.7,
lat: 40,
Expand All @@ -80,10 +90,30 @@ const obstacles = [
pose: new ViamObject3D(),
} as BoxGeometry,
],
color: theme.extend.colors.hologram,
label: 'transient',
},
{
name: 'obstacle 5',
location: {
lng: -74.701,
lat: 40.001,
},
geometries: [
{
type: 'box',
length: 50,
width: 50,
height: 50,
pose: new ViamObject3D(),
} as BoxGeometry,
],
color: theme.extend.colors.cyberpunk,
label: 'static',
},
];
const plans = {
const plans: Plans = {
current: [
{ lng: -73.968, lat: 40.663 },
{ lng: -73.9681, lat: 40.6631 },
Expand Down

0 comments on commit f4f9622

Please sign in to comment.