From 11f83fb766ed78bedc3bd4e1f20a4acb33ecd098 Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Mon, 15 Mar 2021 22:20:30 +0100 Subject: [PATCH] add PlaneGeometry --- src/geometries/PlaneGeometry.js | 23 +++++++++++++++++++++++ src/meshes/Plane.js | 20 ++++---------------- 2 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 src/geometries/PlaneGeometry.js diff --git a/src/geometries/PlaneGeometry.js b/src/geometries/PlaneGeometry.js new file mode 100644 index 0000000..70c4285 --- /dev/null +++ b/src/geometries/PlaneGeometry.js @@ -0,0 +1,23 @@ +import { PlaneGeometry } from 'three'; +import Geometry from './Geometry.js'; + +export const props = { + width: { type: Number, default: 1 }, + height: { type: Number, default: 1 }, + widthSegments: { type: Number, default: 1 }, + heightSegments: { type: Number, default: 1 }, +}; + +export function createGeometry(comp) { + return new PlaneGeometry(comp.width, comp.height, comp.widthSegments, comp.heightSegments); +}; + +export default { + extends: Geometry, + props, + methods: { + createGeometry() { + this.geometry = createGeometry(this); + }, + }, +}; diff --git a/src/meshes/Plane.js b/src/meshes/Plane.js index 3f201bc..fdb27e7 100644 --- a/src/meshes/Plane.js +++ b/src/meshes/Plane.js @@ -1,28 +1,16 @@ -import { PlaneGeometry } from 'three'; -import { watch } from 'vue'; import Mesh from './Mesh.js'; +import { props, createGeometry } from '../geometries/PlaneGeometry.js'; export default { extends: Mesh, - props: { - width: { type: Number, default: 1 }, - height: { type: Number, default: 1 }, - widthSegments: { type: Number, default: 1 }, - heightSegments: { type: Number, default: 1 }, - }, + props, created() { this.createGeometry(); - - const watchProps = ['width', 'height', 'widthSegments', 'heightSegments']; - watchProps.forEach(prop => { - watch(() => this[prop], () => { - this.refreshGeometry(); - }); - }); + this.addGeometryWatchers(props); }, methods: { createGeometry() { - this.geometry = new PlaneGeometry(this.width, this.height, this.widthSegments, this.heightSegments); + this.geometry = createGeometry(this); }, }, __hmrId: 'Plane',