1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 20:32:02 +08:00
trois/src/core/Scene.ts
Kevin Levron b5ab6567e3 wip: core
2021-04-18 22:27:53 +02:00

38 lines
882 B
TypeScript

import { defineComponent, watch } from 'vue'
import { Scene, Color, Object3D } from 'three'
export default defineComponent({
name: 'Scene',
inject: ['three'],
props: {
id: String,
background: [String, Number],
},
setup(props) {
const scene = new Scene()
if (props.background) {
scene.background = new Color(props.background)
}
watch(() => props.background, (value) => { if (scene.background instanceof Color && value) scene.background.set(value) })
return { scene }
},
provide() {
return {
scene: this.scene,
}
},
created() {
if (!this.three.scene) {
this.three.scene = this.scene
}
},
methods: {
add(o: Object3D) { this.scene.add(o) },
remove(o: Object3D) { this.scene.remove(o) },
},
render() {
return this.$slots.default ? this.$slots.default() : []
},
__hmrId: 'Scene',
})