forked from Luc16/SpaceVisionaries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trail.js
29 lines (24 loc) · 784 Bytes
/
trail.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import * as THREE from "https://cdn.skypack.dev/three@0.129.0/build/three.module.js";
export class Trail {
constructor(scene, size, color) {
this.size = 100
this.points = [];
this.lineGeometry = new THREE.BufferGeometry().setFromPoints( this.points );
const lineMaterial = new THREE.LineBasicMaterial({
color: color
});
const line = new THREE.Line( this.lineGeometry, lineMaterial );
scene.add( line );
}
reset() {
this.points = []
this.lineGeometry.setFromPoints( this.points );
}
add(pos) {
if (this.points.length >= this.size) {
this.points.splice(0, 1)
}
this.points.push(pos)
this.lineGeometry.setFromPoints( this.points );
}
}