mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
add refraction mesh
This commit is contained in:
parent
2cf084f0bb
commit
ff2da62e4b
46
src/meshes/RefractionMesh.js
Normal file
46
src/meshes/RefractionMesh.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import {
|
||||||
|
CubeCamera,
|
||||||
|
CubeRefractionMapping,
|
||||||
|
LinearMipmapLinearFilter,
|
||||||
|
RGBFormat,
|
||||||
|
WebGLCubeRenderTarget,
|
||||||
|
} from 'three';
|
||||||
|
// import { watch } from 'vue';
|
||||||
|
import Mesh from './Mesh.js';
|
||||||
|
import useBindProp from '../use/useBindProp.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: Mesh,
|
||||||
|
props: {
|
||||||
|
cubeRTSize: { type: Number, default: 512 },
|
||||||
|
cubeCameraNear: { type: Number, default: 0.1 },
|
||||||
|
cubeCameraFar: { type: Number, default: 2000 },
|
||||||
|
cubeRTAutoUpdate: Boolean,
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.initMirrorMesh();
|
||||||
|
if (this.cubeRTAutoUpdate) this.three.onBeforeRender(this.updateCubeRT);
|
||||||
|
else this.rendererComponent.onMounted(this.updateCubeRT);
|
||||||
|
},
|
||||||
|
unmounted() {
|
||||||
|
this.three.offBeforeRender(this.updateCubeRT);
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
initMirrorMesh() {
|
||||||
|
const cubeRT = new WebGLCubeRenderTarget(this.cubeRTSize, { mapping: CubeRefractionMapping, format: RGBFormat, generateMipmaps: true, minFilter: LinearMipmapLinearFilter });
|
||||||
|
this.cubeCamera = new CubeCamera(this.cubeCameraNear, this.cubeCameraFar, cubeRT);
|
||||||
|
useBindProp(this, 'position', this.cubeCamera.position);
|
||||||
|
this.scene.add(this.cubeCamera);
|
||||||
|
|
||||||
|
this.material.envMap = cubeRT.texture;
|
||||||
|
this.material.refractionRatio = 0.95;
|
||||||
|
this.material.needsUpdate = true;
|
||||||
|
},
|
||||||
|
updateCubeRT() {
|
||||||
|
this.mesh.visible = false;
|
||||||
|
this.cubeCamera.update(this.three.renderer, this.scene);
|
||||||
|
this.mesh.visible = true;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
__hmrId: 'RefractionMesh',
|
||||||
|
};
|
@ -22,4 +22,5 @@ export { default as Gem } from './Gem.js';
|
|||||||
export { default as Image } from './Image.js';
|
export { default as Image } from './Image.js';
|
||||||
export { default as InstancedMesh } from './InstancedMesh.js';
|
export { default as InstancedMesh } from './InstancedMesh.js';
|
||||||
export { default as MirrorMesh } from './MirrorMesh.js';
|
export { default as MirrorMesh } from './MirrorMesh.js';
|
||||||
|
export { default as RefractionMesh } from './RefractionMesh.js';
|
||||||
export { default as Sprite } from './Sprite.js';
|
export { default as Sprite } from './Sprite.js';
|
||||||
|
@ -60,6 +60,7 @@ export const TroisJSVuePlugin = {
|
|||||||
'Image',
|
'Image',
|
||||||
'InstancedMesh',
|
'InstancedMesh',
|
||||||
'MirrorMesh',
|
'MirrorMesh',
|
||||||
|
'RefractionMesh',
|
||||||
'Sprite',
|
'Sprite',
|
||||||
|
|
||||||
'BokehPass',
|
'BokehPass',
|
||||||
|
Loading…
Reference in New Issue
Block a user