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

improve materials

This commit is contained in:
Kevin Levron 2021-04-29 19:26:53 +02:00
parent 73425177e5
commit e174da23c6
2 changed files with 5 additions and 12 deletions

View File

@ -67,7 +67,7 @@ export default defineComponent({
this.setProp(key, texture, true)
},
addWatchers() {
['color', 'alphaTest', 'depthTest', 'depthWrite', 'fog', 'opacity', 'side', 'transparent'].forEach(p => {
['color', 'alphaTest', 'blending', 'depthTest', 'depthWrite', 'fog', 'opacity', 'side', 'transparent'].forEach(p => {
// @ts-ignore
watch(() => this[p], (value) => {
if (p === 'color') {

View File

@ -1,6 +1,7 @@
import { defineComponent, watch } from 'vue'
import { ShaderMaterial } from 'three'
import Material from './Material'
import { propsValues } from '../tools'
const defaultVertexShader = `
varying vec2 vUv;
@ -26,23 +27,15 @@ export default defineComponent({
},
methods: {
createMaterial() {
const material = new ShaderMaterial({
uniforms: this.uniforms,
vertexShader: this.vertexShader,
fragmentShader: this.fragmentShader,
})
const material = new ShaderMaterial(propsValues(this.$props, ['color']));
const watchProps = ['vertexShader', 'fragmentShader']
watchProps.forEach(p => {
['vertexShader', 'fragmentShader'].forEach(p => {
// @ts-ignore
watch(() => this[p], (value) => {
this.setProp(p, value, true)
})
watch(() => this[p], (value) => { material[p] = value; material.needsUpdate = true })
})
return material
},
addWatchers() {},
},
__hmrId: 'ShaderMaterial',
})