mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
geometries refactor
This commit is contained in:
parent
f2229aa757
commit
726087cc3c
31
src/geometries/BoxGeometry.js
Normal file
31
src/geometries/BoxGeometry.js
Normal file
@ -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);
|
||||
}
|
||||
},
|
||||
};
|
11
src/geometries/Geometry.js
Normal file
11
src/geometries/Geometry.js
Normal file
@ -0,0 +1,11 @@
|
||||
export default {
|
||||
inject: ['parent'],
|
||||
created() {
|
||||
if (!this.parent) {
|
||||
console.error('Missing parent Mesh');
|
||||
}
|
||||
},
|
||||
render() {
|
||||
return [];
|
||||
},
|
||||
};
|
21
src/geometries/SphereGeometry.js
Normal file
21
src/geometries/SphereGeometry.js
Normal file
@ -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);
|
||||
},
|
||||
};
|
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user