1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 12:22:03 +08:00
trois/src/core/Group.js

48 lines
1016 B
JavaScript
Raw Normal View History

2021-02-22 04:39:35 +08:00
import { Group } from 'three';
2021-03-07 02:22:01 +08:00
import { bindProp } from '../tools.js';
2021-02-22 04:39:35 +08:00
export default {
2021-03-04 06:21:53 +08:00
inject: {
three: 'three',
scene: 'scene',
group: { default: null },
},
2021-02-22 04:39:35 +08:00
props: {
position: Object,
rotation: Object,
scale: Object,
},
provide() {
return {
group: this.group,
};
},
created() {
2021-03-07 02:22:01 +08:00
if (!this.$parent) {
console.error('Missing parent');
} else if (!this.$parent.add || !this.$parent.remove) {
}
2021-03-04 06:21:53 +08:00
this.parent = this.group ? this.group : this.scene;
this.group = new Group();
2021-03-07 02:22:01 +08:00
bindProp(this, 'position', this.group.position);
bindProp(this, 'rotation', this.group.rotation);
bindProp(this, 'scale', this.group.scale);
2021-03-04 06:21:53 +08:00
2021-02-22 04:39:35 +08:00
this.parent.add(this.group);
},
unmounted() {
2021-03-07 02:22:01 +08:00
if (this.$parent) this.$parent.remove(this.group);
},
methods: {
add(o) { this.group.add(o); },
remove(o) { this.group.remove(o); },
2021-02-22 04:39:35 +08:00
},
render() {
2021-03-07 02:22:01 +08:00
return this.$slots.default ? this.$slots.default() : [];
2021-02-22 04:39:35 +08:00
},
__hmrId: 'Group',
};