2020-09-16 01:50:51 +08:00
|
|
|
import { Scene, Color } from 'three';
|
2020-10-03 18:35:29 +08:00
|
|
|
import { watch } from 'vue';
|
2020-09-14 22:57:11 +08:00
|
|
|
|
|
|
|
export default {
|
2021-03-07 20:22:54 +08:00
|
|
|
name: 'Scene',
|
2020-09-16 01:50:51 +08:00
|
|
|
inject: ['three'],
|
2020-09-15 04:53:30 +08:00
|
|
|
props: {
|
|
|
|
id: String,
|
2020-09-16 01:50:51 +08:00
|
|
|
background: [String, Number],
|
2020-09-15 04:53:30 +08:00
|
|
|
},
|
2020-10-03 21:57:32 +08:00
|
|
|
setup(props) {
|
2020-09-14 22:57:11 +08:00
|
|
|
const scene = new Scene();
|
2020-09-16 01:50:51 +08:00
|
|
|
if (props.background) scene.background = new Color(props.background);
|
2020-10-03 18:35:29 +08:00
|
|
|
watch(() => props.background, (value) => { scene.background = new Color(value); });
|
2020-09-14 22:57:11 +08:00
|
|
|
return { scene };
|
|
|
|
},
|
|
|
|
provide() {
|
|
|
|
return {
|
|
|
|
scene: this.scene,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
2020-09-16 21:30:39 +08:00
|
|
|
if (!this.three.scene) {
|
|
|
|
this.three.scene = this.scene;
|
|
|
|
}
|
2020-09-14 22:57:11 +08:00
|
|
|
},
|
2020-10-03 21:57:32 +08:00
|
|
|
methods: {
|
2021-03-07 02:22:01 +08:00
|
|
|
add(o) { this.scene.add(o); },
|
|
|
|
remove(o) { this.scene.remove(o); },
|
2020-10-03 21:57:32 +08:00
|
|
|
},
|
2020-09-14 22:57:11 +08:00
|
|
|
render() {
|
2021-03-07 06:14:22 +08:00
|
|
|
return this.$slots.default ? this.$slots.default() : [];
|
2020-09-14 22:57:11 +08:00
|
|
|
},
|
|
|
|
};
|