2021-03-12 22:29:10 +08:00
|
|
|
import { ShaderMaterial } from 'three'
|
|
|
|
import { propsValues, defaultFragmentShader, defaultVertexShader } from '../tools.js';
|
|
|
|
|
2020-09-17 16:16:02 +08:00
|
|
|
export default {
|
2020-10-03 18:34:14 +08:00
|
|
|
inject: ['three', 'mesh'],
|
2020-09-17 16:16:02 +08:00
|
|
|
props: {
|
|
|
|
uniforms: Object,
|
2021-03-12 22:29:10 +08:00
|
|
|
vertexShader: { type: String, default: defaultVertexShader },
|
|
|
|
fragmentShader: { type: String, default: defaultFragmentShader },
|
2020-09-17 16:16:02 +08:00
|
|
|
},
|
2021-03-07 06:14:22 +08:00
|
|
|
created() {
|
2020-10-03 18:34:14 +08:00
|
|
|
this.createMaterial();
|
|
|
|
this.mesh.setMaterial(this.material);
|
|
|
|
if (this.addWatchers) this.addWatchers();
|
2020-09-17 16:16:02 +08:00
|
|
|
},
|
|
|
|
unmounted() {
|
|
|
|
this.material.dispose();
|
|
|
|
},
|
2021-03-12 22:29:10 +08:00
|
|
|
methods: {
|
|
|
|
createMaterial() {
|
|
|
|
this.material = new ShaderMaterial(propsValues(this.$props));
|
|
|
|
},
|
|
|
|
},
|
2020-09-17 16:16:02 +08:00
|
|
|
render() {
|
|
|
|
return [];
|
|
|
|
},
|
2020-09-19 23:00:29 +08:00
|
|
|
__hmrId: 'ShaderMaterial',
|
2020-09-17 16:16:02 +08:00
|
|
|
};
|