mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
refactor circle
This commit is contained in:
parent
98a8c01ef1
commit
606dcfa9c9
@ -1,17 +1,23 @@
|
|||||||
import { CircleGeometry } from 'three';
|
import { CircleGeometry } from 'three';
|
||||||
import Geometry from './Geometry.js';
|
import Geometry from './Geometry.js';
|
||||||
|
|
||||||
|
export const props = {
|
||||||
|
radius: { type: Number, default: 1 },
|
||||||
|
segments: { type: Number, default: 8 },
|
||||||
|
thetaStart: { type: Number, default: 0 },
|
||||||
|
thetaLength: { type: Number, default: Math.PI * 2 },
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createGeometry(comp) {
|
||||||
|
return new CircleGeometry(comp.radius, comp.segments, comp.thetaStart, comp.thetaLength);
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
extends: Geometry,
|
extends: Geometry,
|
||||||
props: {
|
props,
|
||||||
radius: { type: Number, default: 1 },
|
|
||||||
segments: { type: Number, default: 8 },
|
|
||||||
thetaStart: { type: Number, default: 0 },
|
|
||||||
thetaLength: { type: Number, default: Math.PI * 2 },
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
createGeometry() {
|
createGeometry() {
|
||||||
this.geometry = new CircleGeometry(this.radius, this.segments, this.thetaStart, this.thetaLength);
|
this.geometry = createGeometry(this);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,28 +1,16 @@
|
|||||||
import { CircleBufferGeometry } from 'three';
|
|
||||||
import { watch } from 'vue';
|
|
||||||
import Mesh from './Mesh.js';
|
import Mesh from './Mesh.js';
|
||||||
|
import { props, createGeometry } from '../geometries/CircleGeometry.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
extends: Mesh,
|
extends: Mesh,
|
||||||
props: {
|
props,
|
||||||
radius: { type: Number, default: 1 },
|
|
||||||
segments: { type: Number, default: 8 },
|
|
||||||
thetaStart: { type: Number, default: 0 },
|
|
||||||
thetaLength: { type: Number, default: Math.PI * 2 },
|
|
||||||
},
|
|
||||||
created() {
|
created() {
|
||||||
this.createGeometry();
|
this.createGeometry();
|
||||||
|
this.addGeometryWatchers(props);
|
||||||
const watchProps = ['radius', 'segments', 'thetaStart', 'thetaLength'];
|
|
||||||
watchProps.forEach(prop => {
|
|
||||||
watch(() => this[prop], () => {
|
|
||||||
this.refreshGeometry();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
createGeometry() {
|
createGeometry() {
|
||||||
this.geometry = new CircleBufferGeometry(this.radius, this.segments, this.thetaStart, this.thetaLength);
|
this.geometry = createGeometry(this);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
__hmrId: 'Circle',
|
__hmrId: 'Circle',
|
||||||
|
Loading…
Reference in New Issue
Block a user