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',