mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 20:32:02 +08:00
38 lines
882 B
TypeScript
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',
|
|
})
|