diff --git a/src/geometries/BoxGeometry.js b/src/geometries/BoxGeometry.js new file mode 100644 index 0000000..b135feb --- /dev/null +++ b/src/geometries/BoxGeometry.js @@ -0,0 +1,31 @@ +import { BoxBufferGeometry } from 'three'; +import Geometry from './Geometry.js'; + +export default { + extends: Geometry, + inject: ['parent'], + props: { + size: { + type: Number, + }, + width: { + type: Number, + default: 1, + }, + height: { + type: Number, + default: 1, + }, + depth: { + type: Number, + default: 1, + }, + }, + mounted() { + if (this.size) { + this.parent.geometry = new BoxBufferGeometry(this.size, this.size, this.size); + } else { + this.parent.geometry = new BoxBufferGeometry(this.width, this.height, this.depth); + } + }, +}; diff --git a/src/geometries/Geometry.js b/src/geometries/Geometry.js new file mode 100644 index 0000000..ef891dd --- /dev/null +++ b/src/geometries/Geometry.js @@ -0,0 +1,11 @@ +export default { + inject: ['parent'], + created() { + if (!this.parent) { + console.error('Missing parent Mesh'); + } + }, + render() { + return []; + }, +}; diff --git a/src/geometries/SphereGeometry.js b/src/geometries/SphereGeometry.js new file mode 100644 index 0000000..f79dcfc --- /dev/null +++ b/src/geometries/SphereGeometry.js @@ -0,0 +1,21 @@ +import { SphereBufferGeometry } from 'three'; +import Geometry from './Geometry.js'; + +export default { + extends: Geometry, + inject: ['parent'], + props: { + radius: Number, + widthSegments: { + type: Number, + default: 12, + }, + heightSegments: { + type: Number, + default: 12, + }, + }, + mounted() { + this.geometry = new SphereBufferGeometry(this.radius, this.widthSegments, this.heightSegments); + }, +}; diff --git a/src/geometries/index.js b/src/geometries/index.js index 4e9dc5a..3d58ea3 100644 --- a/src/geometries/index.js +++ b/src/geometries/index.js @@ -1,37 +1,2 @@ -import { BoxBufferGeometry } from 'three'; - -export const BoxGeometry = { - inject: ['parent'], - props: { - size: { - type: Number, - }, - width: { - type: Number, - default: 1, - }, - height: { - type: Number, - default: 1, - }, - depth: { - type: Number, - default: 1, - }, - }, - mounted() { - if (!this.parent) { - console.error('Missing parent Mesh'); - return; - } - - if (this.size) { - this.parent.geometry = new BoxBufferGeometry(this.size, this.size, this.size); - } else { - this.parent.geometry = new BoxBufferGeometry(this.width, this.height, this.depth); - } - }, - render() { - return []; - }, -}; +export { default as BoxGeometry } from './BoxGeometry.js'; +export { default as SphereGeometry } from './SphereGeometry.js';