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

textures refactoring

This commit is contained in:
Kevin Levron 2020-10-04 14:00:07 +02:00
parent 1c66a946d5
commit 7b7524d1dd
7 changed files with 25 additions and 45 deletions

View File

@ -2,6 +2,3 @@ export { default as Renderer } from './Renderer.js';
export { default as PerspectiveCamera } from './PerspectiveCamera.js';
export { default as Camera } from './PerspectiveCamera.js';
export { default as Scene } from './Scene.js';
export { default as Texture } from './Texture.js';
export { default as CubeTexture } from './CubeTexture.js';

View File

@ -1,8 +1,8 @@
import { CubeTextureLoader } from 'three';
import { CubeTextureLoader, CubeRefractionMapping } from 'three';
import { watch } from 'vue';
export default {
inject: ['three'],
inject: ['material'],
emits: ['loaded'],
props: {
path: String,
@ -13,9 +13,12 @@ export default {
onLoad: Function,
onProgress: Function,
onError: Function,
id: { type: String, default: 'envMap' },
refraction: Boolean,
refractionRatio: { type: Number, default: 0.98 },
},
created() {
this.createTexture();
this.refreshTexture();
watch(() => this.path, this.refreshTexture);
watch(() => this.urls, this.refreshTexture);
},
@ -30,6 +33,11 @@ export default {
},
refreshTexture() {
this.createTexture();
this.material.setTexture(this.texture, this.id);
if (this.refraction) {
this.texture.mapping = CubeRefractionMapping;
this.material.setProp('refractionRatio', this.refractionRatio);
}
},
onLoaded() {
if (this.onLoad) this.onLoad();

View File

@ -1,19 +0,0 @@
import CubeTexture from '../core/CubeTexture';
export default {
extends: CubeTexture,
inject: ['material'],
created() {
this.material.setEnvMap(this.texture);
},
unmounted() {
this.material.setEnvMap(null);
},
methods: {
refreshTexture() {
this.createTexture();
this.material.setEnvMap(this.texture);
},
},
__hmrId: 'EnvMap',
};

View File

@ -34,17 +34,12 @@ export default {
if (this.id) delete this.three.materials[this.id];
},
methods: {
setMap(texture) {
this.material.map = texture;
this.material.needsUpdate = true;
setProp(key, value, needsUpdate = false) {
this.material[key] = value;
this.material.needsUpdate = needsUpdate;
},
setEnvMap(texture) {
this.material.envMap = texture;
this.material.needsUpdate = true;
},
setRefractionMap(texture, ratio) {
this.material.refractionRatio = ratio;
this.setEnvMap(texture);
setTexture(texture, key = 'map') {
this.setProp(key, texture, true);
},
_addWatchers() {
// don't work for flatShading

View File

@ -2,16 +2,17 @@ import { TextureLoader } from 'three';
import { watch } from 'vue';
export default {
inject: ['three'],
inject: ['material'],
emits: ['loaded'],
props: {
src: String,
onLoad: Function,
onProgress: Function,
onError: Function,
id: { type: String, default: 'map' },
},
created() {
this.createTexture();
this.refreshTexture();
watch(() => this.src, this.refreshTexture);
},
unmounted() {
@ -23,6 +24,7 @@ export default {
},
refreshTexture() {
this.createTexture();
this.material.setTexture(this.texture, this.id);
},
onLoaded() {
if (this.onLoad) this.onLoad();

View File

@ -7,6 +7,6 @@ export { default as StandardMaterial } from './StandardMaterial.js';
export { default as SubSurfaceMaterial } from './SubSurfaceMaterial.js';
export { default as ToonMaterial } from './ToonMaterial.js';
export { default as Map } from './Map.js';
export { default as EnvMap } from './EnvMap.js';
export { default as RefractionMap } from './RefractionMap.js';
export { default as Texture } from './Texture.js';
export { default as CubeTexture } from './CubeTexture.js';

View File

@ -7,8 +7,6 @@ export const TroisJSVuePlugin = {
'PerspectiveCamera',
'Renderer',
'Scene',
// 'Texture',
// 'CubeTexture',
'BoxGeometry',
'CircleGeometry',
@ -41,9 +39,8 @@ export const TroisJSVuePlugin = {
'SubSurfaceMaterial',
'ToonMaterial',
'Map',
'EnvMap',
'RefractionMap',
'Texture',
'CubeTexture',
'Box',
'Circle',