1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00

add PlaneGeometry

This commit is contained in:
Kevin Levron 2021-03-15 22:20:30 +01:00
parent 17d5a03d8b
commit 11f83fb766
2 changed files with 27 additions and 16 deletions

View File

@ -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);
},
},
};

View File

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