1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 20:32:02 +08:00
trois/src/meshes/Sprite.js

26 lines
660 B
JavaScript
Raw Normal View History

2020-09-19 18:16:16 +08:00
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 [];
},
};