Skip to content

Commit a395caa

Browse files
committed
add waypoint max distance
1 parent f16ca74 commit a395caa

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

renderer/viewer/three/waypoints.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface Waypoint {
88
y: number
99
z: number
1010
minDistance: number
11+
maxDistance: number
1112
color: number
1213
label?: string
1314
sprite: WaypointSprite
@@ -17,6 +18,7 @@ interface WaypointOptions {
1718
color?: number
1819
label?: string
1920
minDistance?: number
21+
maxDistance?: number
2022
metadata?: any
2123
}
2224

@@ -54,7 +56,8 @@ export class WaypointsRenderer {
5456
for (const waypoint of this.waypoints.values()) {
5557
const waypointPos = new THREE.Vector3(waypoint.x, waypoint.y, waypoint.z)
5658
const distance = playerPos.distanceTo(waypointPos)
57-
const visible = !waypoint.minDistance || distance >= waypoint.minDistance
59+
const visible = (!waypoint.minDistance || distance >= waypoint.minDistance) &&
60+
(waypoint.maxDistance === Infinity || distance <= waypoint.maxDistance)
5861

5962
waypoint.sprite.setVisible(visible)
6063

@@ -92,6 +95,7 @@ export class WaypointsRenderer {
9295
const color = options.color ?? 0xFF_00_00
9396
const { label, metadata } = options
9497
const minDistance = options.minDistance ?? 0
98+
const maxDistance = options.maxDistance ?? Infinity
9599

96100
const sprite = createWaypointSprite({
97101
position: new THREE.Vector3(x, y, z),
@@ -105,7 +109,7 @@ export class WaypointsRenderer {
105109
this.waypointScene.add(sprite.group)
106110

107111
this.waypoints.set(id, {
108-
id, x: x + 0.5, y: y + 0.5, z: z + 0.5, minDistance,
112+
id, x: x + 0.5, y: y + 0.5, z: z + 0.5, minDistance, maxDistance,
109113
color, label,
110114
sprite,
111115
})

src/customChannels.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const registerWaypointChannels = () => {
159159

160160
getThreeJsRendererMethods()?.addWaypoint(data.id, data.x, data.y, data.z, {
161161
minDistance: data.minDistance,
162+
maxDistance: metadata.maxDistance,
162163
label: data.label || undefined,
163164
color: data.color || undefined,
164165
metadata

0 commit comments

Comments
 (0)