From c900286de8b90724181c3951b854e249e4699218 Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Sat, 3 Apr 2021 23:12:38 +0200 Subject: [PATCH] simplify geometries --- src/geometries/BoxGeometry.js | 13 ++----------- src/geometries/CircleGeometry.js | 13 ++----------- src/geometries/ConeGeometry.js | 13 ++----------- src/geometries/CylinderGeometry.js | 13 ++----------- src/geometries/DodecahedronGeometry.js | 13 ++----------- src/geometries/Geometry.js | 17 ++++++++++++++++- src/geometries/IcosahedronGeometry.js | 13 ++----------- src/geometries/LatheGeometry.js | 13 ++----------- src/geometries/OctahedronGeometry.js | 13 ++----------- src/geometries/PlaneGeometry.js | 13 ++----------- src/geometries/PolyhedronGeometry.js | 13 ++----------- src/geometries/RingGeometry.js | 13 ++----------- src/geometries/SphereGeometry.js | 13 ++----------- src/geometries/TetrahedronGeometry.js | 13 ++----------- src/geometries/TorusGeometry.js | 13 ++----------- src/geometries/TorusKnotGeometry.js | 13 ++----------- 16 files changed, 46 insertions(+), 166 deletions(-) diff --git a/src/geometries/BoxGeometry.js b/src/geometries/BoxGeometry.js index e002b76..f6b6c6e 100644 --- a/src/geometries/BoxGeometry.js +++ b/src/geometries/BoxGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { BoxGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { size: Number, @@ -20,12 +19,4 @@ export function createGeometry(comp) { } }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('BoxGeometry', props, createGeometry); diff --git a/src/geometries/CircleGeometry.js b/src/geometries/CircleGeometry.js index 7049bf5..7b1071a 100644 --- a/src/geometries/CircleGeometry.js +++ b/src/geometries/CircleGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { CircleGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { radius: { type: Number, default: 1 }, @@ -13,12 +12,4 @@ export function createGeometry(comp) { return new CircleGeometry(comp.radius, comp.segments, comp.thetaStart, comp.thetaLength); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('CircleGeometry', props, createGeometry); diff --git a/src/geometries/ConeGeometry.js b/src/geometries/ConeGeometry.js index 106e787..aa49e9c 100644 --- a/src/geometries/ConeGeometry.js +++ b/src/geometries/ConeGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { ConeGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { radius: { type: Number, default: 1 }, @@ -16,12 +15,4 @@ export function createGeometry(comp) { return new ConeGeometry(comp.radius, comp.height, comp.radialSegments, comp.heightSegments, comp.openEnded, comp.thetaStart, comp.thetaLength); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('ConeGeometry', props, createGeometry); diff --git a/src/geometries/CylinderGeometry.js b/src/geometries/CylinderGeometry.js index 1748eab..b411897 100644 --- a/src/geometries/CylinderGeometry.js +++ b/src/geometries/CylinderGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { CylinderGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { radiusTop: { type: Number, default: 1 }, @@ -17,12 +16,4 @@ export function createGeometry(comp) { return new CylinderGeometry(comp.radiusTop, comp.radiusBottom, comp.height, comp.radialSegments, comp.heightSegments, comp.openEnded, comp.thetaStart, comp.thetaLength); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('CylinderGeometry', props, createGeometry); diff --git a/src/geometries/DodecahedronGeometry.js b/src/geometries/DodecahedronGeometry.js index 3eb16c9..8034afc 100644 --- a/src/geometries/DodecahedronGeometry.js +++ b/src/geometries/DodecahedronGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { DodecahedronGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { radius: { type: Number, default: 1 }, @@ -11,12 +10,4 @@ export function createGeometry(comp) { return new DodecahedronGeometry(comp.radius, comp.detail); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('DodecahedronGeometry', props, createGeometry); diff --git a/src/geometries/Geometry.js b/src/geometries/Geometry.js index 2bf608b..d8d8777 100644 --- a/src/geometries/Geometry.js +++ b/src/geometries/Geometry.js @@ -1,6 +1,6 @@ import { defineComponent, watch } from 'vue'; -export default defineComponent({ +const Geometry = defineComponent({ inject: ['mesh'], props: { rotateX: Number, @@ -47,3 +47,18 @@ export default defineComponent({ }, render() { return []; }, }); + +export default Geometry; + +export function geometryComponent(name, props, createGeometry) { + return defineComponent({ + name, + extends: Geometry, + props, + methods: { + createGeometry() { + this.geometry = createGeometry(this); + }, + }, + }); +}; diff --git a/src/geometries/IcosahedronGeometry.js b/src/geometries/IcosahedronGeometry.js index 3c532fe..69156bd 100644 --- a/src/geometries/IcosahedronGeometry.js +++ b/src/geometries/IcosahedronGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { IcosahedronGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { radius: { type: Number, default: 1 }, @@ -11,12 +10,4 @@ export function createGeometry(comp) { return new IcosahedronGeometry(comp.radius, comp.detail); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('IcosahedronGeometry', props, createGeometry); diff --git a/src/geometries/LatheGeometry.js b/src/geometries/LatheGeometry.js index 5d5127e..b041cf1 100644 --- a/src/geometries/LatheGeometry.js +++ b/src/geometries/LatheGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { LatheGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { points: Array, @@ -13,12 +12,4 @@ export function createGeometry(comp) { return new LatheGeometry(comp.points, comp.segments, comp.phiStart, comp.phiLength); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('LatheGeometry', props, createGeometry); diff --git a/src/geometries/OctahedronGeometry.js b/src/geometries/OctahedronGeometry.js index 07bcf1e..077b904 100644 --- a/src/geometries/OctahedronGeometry.js +++ b/src/geometries/OctahedronGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { OctahedronGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { radius: { type: Number, default: 1 }, @@ -11,12 +10,4 @@ export function createGeometry(comp) { return new OctahedronGeometry(comp.radius, comp.detail); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('OctahedronGeometry', props, createGeometry); diff --git a/src/geometries/PlaneGeometry.js b/src/geometries/PlaneGeometry.js index 7acdd8d..7a78818 100644 --- a/src/geometries/PlaneGeometry.js +++ b/src/geometries/PlaneGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { PlaneGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { width: { type: Number, default: 1 }, @@ -13,12 +12,4 @@ export function createGeometry(comp) { return new PlaneGeometry(comp.width, comp.height, comp.widthSegments, comp.heightSegments); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('PlaneGeometry', props, createGeometry); diff --git a/src/geometries/PolyhedronGeometry.js b/src/geometries/PolyhedronGeometry.js index 4be4798..b030139 100644 --- a/src/geometries/PolyhedronGeometry.js +++ b/src/geometries/PolyhedronGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { PolyhedronGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { vertices: Array, @@ -13,12 +12,4 @@ export function createGeometry(comp) { return new PolyhedronGeometry(comp.vertices, comp.indices, comp.radius, comp.detail); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('PolyhedronGeometry', props, createGeometry); diff --git a/src/geometries/RingGeometry.js b/src/geometries/RingGeometry.js index b418b25..5eb7b72 100644 --- a/src/geometries/RingGeometry.js +++ b/src/geometries/RingGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { RingGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { innerRadius: { type: Number, default: 0.5 }, @@ -15,12 +14,4 @@ export function createGeometry(comp) { return new RingGeometry(comp.innerRadius, comp.outerRadius, comp.thetaSegments, comp.phiSegments, comp.thetaStart, comp.thetaLength); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('RingGeometry', props, createGeometry); diff --git a/src/geometries/SphereGeometry.js b/src/geometries/SphereGeometry.js index 05f623b..5293877 100644 --- a/src/geometries/SphereGeometry.js +++ b/src/geometries/SphereGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { SphereGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { radius: { type: Number, default: 1 }, @@ -12,12 +11,4 @@ export function createGeometry(comp) { return new SphereGeometry(comp.radius, comp.widthSegments, comp.heightSegments); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('SphereGeometry', props, createGeometry); diff --git a/src/geometries/TetrahedronGeometry.js b/src/geometries/TetrahedronGeometry.js index d91d2aa..733ff5c 100644 --- a/src/geometries/TetrahedronGeometry.js +++ b/src/geometries/TetrahedronGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { TetrahedronGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { radius: { type: Number, default: 1 }, @@ -11,12 +10,4 @@ export function createGeometry(comp) { return new TetrahedronGeometry(comp.radius, comp.detail); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('TetrahedronGeometry', props, createGeometry); diff --git a/src/geometries/TorusGeometry.js b/src/geometries/TorusGeometry.js index df20a40..6cd501d 100644 --- a/src/geometries/TorusGeometry.js +++ b/src/geometries/TorusGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { TorusGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { radius: { type: Number, default: 1 }, @@ -14,12 +13,4 @@ export function createGeometry(comp) { return new TorusGeometry(comp.radius, comp.tube, comp.radialSegments, comp.tubularSegments, comp.arc); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('TorusGeometry', props, createGeometry); diff --git a/src/geometries/TorusKnotGeometry.js b/src/geometries/TorusKnotGeometry.js index 4a20b54..f02ed14 100644 --- a/src/geometries/TorusKnotGeometry.js +++ b/src/geometries/TorusKnotGeometry.js @@ -1,6 +1,5 @@ -import { defineComponent } from 'vue'; +import { geometryComponent } from './Geometry.js'; import { TorusKnotGeometry } from 'three'; -import Geometry from './Geometry.js'; export const props = { radius: { type: Number, default: 1 }, @@ -15,12 +14,4 @@ export function createGeometry(comp) { return new TorusKnotGeometry(comp.radius, comp.tube, comp.tubularSegments, comp.radialSegments, comp.p, comp.q); }; -export default defineComponent({ - extends: Geometry, - props, - methods: { - createGeometry() { - this.geometry = createGeometry(this); - }, - }, -}); +export default geometryComponent('TorusKnotGeometry', props, createGeometry);