1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00
This commit is contained in:
Kevin Levron 2021-03-15 19:58:28 +01:00
parent 3ed539553a
commit 680e5a7d49
2 changed files with 21 additions and 29 deletions

View File

@ -1,9 +1,7 @@
import { ConeGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
export const props = {
radius: { type: Number, default: 1 },
height: { type: Number, default: 1 },
radialSegments: { type: Number, default: 8 },
@ -11,10 +9,19 @@ export default {
openEnded: { type: Boolean, default: false },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
};
export function createGeometry(comp) {
return new ConeGeometry(comp.radius, comp.height, comp.radialSegments, comp.heightSegments, comp.openEnded, comp.thetaStart, comp.thetaLength);
};
export default {
extends: Geometry,
props,
methods: {
createGeometry() {
this.geometry = new ConeGeometry(this.radius, this.height, this.radialSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength);
this.geometry = createGeometry(this);
},
},
};

View File

@ -1,31 +1,16 @@
import { ConeBufferGeometry } from 'three';
import { watch } from 'vue';
import Mesh from './Mesh.js';
import { props, createGeometry } from '../geometries/ConeGeometry.js';
export default {
extends: Mesh,
props: {
radius: { type: Number, default: 1 },
height: { type: Number, default: 1 },
radialSegments: { type: Number, default: 8 },
heightSegments: { type: Number, default: 1 },
openEnded: { type: Boolean, default: false },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
props,
created() {
this.createGeometry();
const watchProps = ['radius', 'height', 'radialSegments', 'heightSegments', 'openEnded', 'thetaStart', 'thetaLength'];
watchProps.forEach(prop => {
watch(() => this[prop], () => {
this.refreshGeometry();
});
});
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = new ConeBufferGeometry(this.radius, this.height, this.radialSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength);
this.geometry = createGeometry(this);
},
},
__hmrId: 'Cone',