mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
add PlaneGeometry
This commit is contained in:
parent
17d5a03d8b
commit
11f83fb766
23
src/geometries/PlaneGeometry.js
Normal file
23
src/geometries/PlaneGeometry.js
Normal 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);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
@ -1,28 +1,16 @@
|
|||||||
import { PlaneGeometry } from 'three';
|
|
||||||
import { watch } from 'vue';
|
|
||||||
import Mesh from './Mesh.js';
|
import Mesh from './Mesh.js';
|
||||||
|
import { props, createGeometry } from '../geometries/PlaneGeometry.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
extends: Mesh,
|
extends: Mesh,
|
||||||
props: {
|
props,
|
||||||
width: { type: Number, default: 1 },
|
|
||||||
height: { type: Number, default: 1 },
|
|
||||||
widthSegments: { type: Number, default: 1 },
|
|
||||||
heightSegments: { type: Number, default: 1 },
|
|
||||||
},
|
|
||||||
created() {
|
created() {
|
||||||
this.createGeometry();
|
this.createGeometry();
|
||||||
|
this.addGeometryWatchers(props);
|
||||||
const watchProps = ['width', 'height', 'widthSegments', 'heightSegments'];
|
|
||||||
watchProps.forEach(prop => {
|
|
||||||
watch(() => this[prop], () => {
|
|
||||||
this.refreshGeometry();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
createGeometry() {
|
createGeometry() {
|
||||||
this.geometry = new PlaneGeometry(this.width, this.height, this.widthSegments, this.heightSegments);
|
this.geometry = createGeometry(this);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
__hmrId: 'Plane',
|
__hmrId: 'Plane',
|
||||||
|
Loading…
Reference in New Issue
Block a user