From 864adc13794ed6a45404f8c91e02b9b97fdc4c03 Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Sun, 4 Oct 2020 01:44:47 +0200 Subject: [PATCH] wip --- src/materials/Material.js | 4 ++++ src/materials/RefractionMap.js | 24 ++++++++++++++++++++++++ src/materials/index.js | 1 + src/meshes/Gem.js | 2 +- src/meshes/MirrorMesh.js | 2 +- src/meshes/RefractionMesh.js | 5 +++-- 6 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/materials/RefractionMap.js diff --git a/src/materials/Material.js b/src/materials/Material.js index ed47dba..9cbaaed 100644 --- a/src/materials/Material.js +++ b/src/materials/Material.js @@ -42,6 +42,10 @@ export default { this.material.envMap = texture; this.material.needsUpdate = true; }, + setRefractionMap(texture, ratio) { + this.material.refractionRatio = ratio; + this.setEnvMap(texture); + }, _addWatchers() { // don't work for flatShading ['color', 'depthTest', 'depthWrite', 'fog', 'opacity', 'side', 'transparent'].forEach(p => { diff --git a/src/materials/RefractionMap.js b/src/materials/RefractionMap.js new file mode 100644 index 0000000..02a0be1 --- /dev/null +++ b/src/materials/RefractionMap.js @@ -0,0 +1,24 @@ +import { CubeRefractionMapping } from 'three'; +import CubeTexture from '../core/CubeTexture'; + +export default { + extends: CubeTexture, + inject: ['material'], + props: { + refractionRatio: { type: Number, default: 0.98 }, + }, + created() { + this.texture.mapping = CubeRefractionMapping; + this.material.setRefractionMap(this.texture, this.refractionRatio); + }, + unmounted() { + this.material.setEnvMap(null); + }, + methods: { + refreshTexture() { + this.createTexture(); + this.material.setRefractionMap(this.texture, this.refractionRatio); + }, + }, + __hmrId: 'RefractionMap', +}; diff --git a/src/materials/index.js b/src/materials/index.js index 77e7d60..afe3eba 100644 --- a/src/materials/index.js +++ b/src/materials/index.js @@ -8,3 +8,4 @@ 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'; diff --git a/src/meshes/Gem.js b/src/meshes/Gem.js index 9ae507c..0438320 100644 --- a/src/meshes/Gem.js +++ b/src/meshes/Gem.js @@ -14,7 +14,7 @@ import useBindProp from '../use/useBindProp.js'; export default { extends: Mesh, props: { - cubeRTSize: { type: Number, default: 512 }, + cubeRTSize: { type: Number, default: 256 }, cubeCameraNear: { type: Number, default: 0.1 }, cubeCameraFar: { type: Number, default: 2000 }, autoUpdate: Boolean, diff --git a/src/meshes/MirrorMesh.js b/src/meshes/MirrorMesh.js index 2a1c55d..4601228 100644 --- a/src/meshes/MirrorMesh.js +++ b/src/meshes/MirrorMesh.js @@ -11,7 +11,7 @@ import useBindProp from '../use/useBindProp.js'; export default { extends: Mesh, props: { - cubeRTSize: { type: Number, default: 512 }, + cubeRTSize: { type: Number, default: 256 }, cubeCameraNear: { type: Number, default: 0.1 }, cubeCameraFar: { type: Number, default: 2000 }, autoUpdate: Boolean, diff --git a/src/meshes/RefractionMesh.js b/src/meshes/RefractionMesh.js index 16541bf..edc3ec2 100644 --- a/src/meshes/RefractionMesh.js +++ b/src/meshes/RefractionMesh.js @@ -12,9 +12,10 @@ import useBindProp from '../use/useBindProp.js'; export default { extends: Mesh, props: { - cubeRTSize: { type: Number, default: 512 }, + cubeRTSize: { type: Number, default: 256 }, cubeCameraNear: { type: Number, default: 0.1 }, cubeCameraFar: { type: Number, default: 2000 }, + refractionRatio: { type: Number, default: 0.98 }, autoUpdate: Boolean, }, mounted() { @@ -33,7 +34,7 @@ export default { this.scene.add(this.cubeCamera); this.material.envMap = cubeRT.texture; - this.material.refractionRatio = 0.95; + this.material.refractionRatio = this.refractionRatio; this.material.needsUpdate = true; }, updateCubeRT() {