forked from GreggJuanEduardoPH/vue-gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vgl-line.js
64 lines (62 loc) · 1.98 KB
/
vgl-line.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Line } from 'three';
import { VglObject3dWithMatarialAndGeometry } from '../mixins';
import { name } from '../types';
import { validateName } from '../validators';
/**
* A continuous line component,
* corresponding [THREE.Line](https://threejs.org/docs/index.html#api/objects/Line).
*
* Properties of [VglObject3d](../core/vgl-object3d) are also available as mixin.
*/
export default {
mixins: [VglObject3dWithMatarialAndGeometry],
props: {
/** Name of the geometry, representing the line segment(s). */
geometry: { type: name, validator: validateName },
/** Name of the material for the line. */
material: { type: name, validator: validateName },
},
computed: {
/** The THREE.Line instance. */
inst: () => new Line(),
},
methods: {
computeLineDistances() {
if (this.inst.material.isLineDashedMaterial) this.inst.computeLineDistances();
},
},
beforeDestroy() {
if (this.geometry !== undefined) {
this.vglNamespace.geometries.unlisten(this.geometry, this.computeLineDistances);
}
if (this.material !== undefined) {
this.vglNamespace.materials.unlisten(this.material, this.computeLineDistances);
}
},
watch: {
geometry: {
handler(geometry, oldGeometry) {
if (oldGeometry !== undefined) {
this.vglNamespace.geometries.unlisten(oldGeometry, this.computeLineDistances);
}
if (geometry !== undefined) {
this.vglNamespace.geometries.listen(geometry, this.computeLineDistances);
this.computeLineDistances();
}
},
immediate: true,
},
material: {
handler(material, oldMaterial) {
if (oldMaterial !== undefined) {
this.vglNamespace.materials.unlisten(oldMaterial, this.computeLineDistances);
}
if (material !== undefined) {
this.vglNamespace.materials.listen(material, this.computeLineDistances);
this.computeLineDistances();
}
},
immediate: true,
},
},
};