mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 20:32:02 +08:00
26 lines
660 B
JavaScript
26 lines
660 B
JavaScript
|
import { Sprite, SpriteMaterial, TextureLoader } from 'three';
|
||
|
import useBindProp from '../use/useBindProp.js';
|
||
|
|
||
|
export default {
|
||
|
emits: ['ready', 'loaded'],
|
||
|
inject: ['three', 'scene'],
|
||
|
props: {
|
||
|
src: String,
|
||
|
position: Object,
|
||
|
},
|
||
|
mounted() {
|
||
|
this.texture = new TextureLoader().load(this.src, () => { this.$emit('loaded'); });
|
||
|
this.material = new SpriteMaterial({ map: this.texture });
|
||
|
this.sprite = new Sprite(this.material);
|
||
|
useBindProp(this, 'position', this.sprite.position);
|
||
|
this.scene.add(this.sprite);
|
||
|
this.$emit('ready');
|
||
|
},
|
||
|
unmounted() {
|
||
|
this.texture.dispose();
|
||
|
},
|
||
|
render() {
|
||
|
return [];
|
||
|
},
|
||
|
};
|