2020-09-28 20:48:39 +08:00
|
|
|
import { TorusKnotBufferGeometry } from 'three';
|
|
|
|
import { watch } from 'vue';
|
|
|
|
import Mesh from './Mesh.js';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
extends: Mesh,
|
|
|
|
props: {
|
2020-10-03 20:41:08 +08:00
|
|
|
radius: { type: Number, default: 0.5 },
|
2020-09-28 20:48:39 +08:00
|
|
|
tube: { type: Number, default: 0.4 },
|
2021-03-02 01:47:53 +08:00
|
|
|
tubularSegments: { type: Number, default: 64 },
|
|
|
|
radialSegments: { type: Number, default: 8 },
|
2020-09-28 20:48:39 +08:00
|
|
|
p: { type: Number, default: 2 },
|
|
|
|
q: { type: Number, default: 3 },
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.createGeometry();
|
|
|
|
|
|
|
|
const watchProps = ['radius', 'tube', 'radialSegments', 'tubularSegments', 'p', 'q'];
|
|
|
|
watchProps.forEach(prop => {
|
|
|
|
watch(() => this[prop], () => {
|
|
|
|
this.refreshGeometry();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
createGeometry() {
|
2021-03-01 04:44:06 +08:00
|
|
|
this.geometry = new TorusKnotBufferGeometry(this.radius, this.tube, this.tubularSegments, this.radialSegments, this.p, this.q);
|
2020-09-28 20:48:39 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
__hmrId: 'TorusKnot',
|
|
|
|
};
|