Skip to content

Commit

Permalink
Dreamview: checkpoint.js (#10419)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlin17 authored and unacao committed Dec 5, 2019
1 parent 0f5930f commit 0865a5a
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions modules/dreamview/frontend/src/renderer/check_points.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { drawSegmentsFromPoints, disposeMesh } from "utils/draw";

const DELTA_Z_OFFSET = 0.1;

const COLOR_MAPPING = {
MIDWAY: 0xFF7F50,
END: 0xFFDAB9,
};

export default class CheckPoints {
constructor(coordinates, scene) {
this.coordinates = coordinates;
this.scene = scene;

this.mesh = [];
}

dispose() {
this.mesh.forEach((point) => {
disposeMesh(point);
this.scene.remove(point);
});

this.mesh = [];
}

update(checkpoints) {
if (!this.coordinates.isInitialized()) {
return;
}

if (!checkpoints || !Array.isArray(checkpoints)) {
return;
}

this.dispose();

checkpoints.forEach((checkpoint) => {
const color = checkpoint.isMidway ? COLOR_MAPPING.MIDWAY : COLOR_MAPPING.END;
const points = checkpoint.region.map(point => {
return this.coordinates.applyOffset({ ...point, z: DELTA_Z_OFFSET });
});
points.push(points[0]);

const region = drawSegmentsFromPoints(points, color, 3);
this.scene.add(region);

this.mesh.push(region);
});
}
}

0 comments on commit 0865a5a

Please sign in to comment.