From 680e5a7d49a05f5d2f8b936d1d8582e1e119baf9 Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Mon, 15 Mar 2021 19:58:28 +0100 Subject: [PATCH] cone --- src/geometries/ConeGeometry.js | 27 +++++++++++++++++---------- src/meshes/Cone.js | 23 ++++------------------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/geometries/ConeGeometry.js b/src/geometries/ConeGeometry.js index a4e451d..99d8ed2 100644 --- a/src/geometries/ConeGeometry.js +++ b/src/geometries/ConeGeometry.js @@ -1,20 +1,27 @@ import { ConeGeometry } from 'three'; import Geometry from './Geometry.js'; +export const 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 }, +}; + +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: { - 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, methods: { createGeometry() { - this.geometry = new ConeGeometry(this.radius, this.height, this.radialSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength); + this.geometry = createGeometry(this); }, }, }; + diff --git a/src/meshes/Cone.js b/src/meshes/Cone.js index 7adf5ed..8c8e692 100644 --- a/src/meshes/Cone.js +++ b/src/meshes/Cone.js @@ -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',