1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00

feat: add texture props

This commit is contained in:
Kevin Levron 2021-03-07 11:46:35 +01:00
parent 9438b79b56
commit 9f65387068

View File

@ -1,15 +1,24 @@
import { TextureLoader } from 'three';
import { ClampToEdgeWrapping, LinearFilter, LinearMipmapLinearFilter, TextureLoader, UVMapping } from 'three';
import { watch } from 'vue';
import { bindProp } from '../tools.js';
export default {
inject: ['material'],
emits: ['loaded'],
props: {
id: { type: String, default: 'map' },
src: String,
onLoad: Function,
onProgress: Function,
onError: Function,
id: { type: String, default: 'map' },
mapping: { type: Number, default: UVMapping },
wrapS: { type: Number, default: ClampToEdgeWrapping },
wrapT: { type: Number, default: ClampToEdgeWrapping },
magFilter: { type: Number, default: LinearFilter },
minFilter: { type: Number, default: LinearMipmapLinearFilter },
repeat: { type: Object, default: { x: 1, y: 1 } },
rotation: { type: Number, default: 0 },
center: { type: Object, default: { x: 0, y: 0 } },
},
created() {
this.refreshTexture();
@ -22,6 +31,10 @@ export default {
methods: {
createTexture() {
this.texture = new TextureLoader().load(this.src, this.onLoaded, this.onProgress, this.onError);
const wathProps = ['mapping', 'wrapS', 'wrapT', 'magFilter', 'minFilter', 'repeat', 'rotation', 'rotation', 'center'];
wathProps.forEach(prop => {
bindProp(this, prop, this.texture);
});
},
refreshTexture() {
this.createTexture();