mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
improve materials
This commit is contained in:
parent
73425177e5
commit
e174da23c6
@ -67,7 +67,7 @@ export default defineComponent({
|
|||||||
this.setProp(key, texture, true)
|
this.setProp(key, texture, true)
|
||||||
},
|
},
|
||||||
addWatchers() {
|
addWatchers() {
|
||||||
['color', 'alphaTest', 'depthTest', 'depthWrite', 'fog', 'opacity', 'side', 'transparent'].forEach(p => {
|
['color', 'alphaTest', 'blending', 'depthTest', 'depthWrite', 'fog', 'opacity', 'side', 'transparent'].forEach(p => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
watch(() => this[p], (value) => {
|
watch(() => this[p], (value) => {
|
||||||
if (p === 'color') {
|
if (p === 'color') {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { defineComponent, watch } from 'vue'
|
import { defineComponent, watch } from 'vue'
|
||||||
import { ShaderMaterial } from 'three'
|
import { ShaderMaterial } from 'three'
|
||||||
import Material from './Material'
|
import Material from './Material'
|
||||||
|
import { propsValues } from '../tools'
|
||||||
|
|
||||||
const defaultVertexShader = `
|
const defaultVertexShader = `
|
||||||
varying vec2 vUv;
|
varying vec2 vUv;
|
||||||
@ -26,23 +27,15 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
createMaterial() {
|
createMaterial() {
|
||||||
const material = new ShaderMaterial({
|
const material = new ShaderMaterial(propsValues(this.$props, ['color']));
|
||||||
uniforms: this.uniforms,
|
|
||||||
vertexShader: this.vertexShader,
|
|
||||||
fragmentShader: this.fragmentShader,
|
|
||||||
})
|
|
||||||
|
|
||||||
const watchProps = ['vertexShader', 'fragmentShader']
|
['vertexShader', 'fragmentShader'].forEach(p => {
|
||||||
watchProps.forEach(p => {
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
watch(() => this[p], (value) => {
|
watch(() => this[p], (value) => { material[p] = value; material.needsUpdate = true })
|
||||||
this.setProp(p, value, true)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return material
|
return material
|
||||||
},
|
},
|
||||||
addWatchers() {},
|
|
||||||
},
|
},
|
||||||
__hmrId: 'ShaderMaterial',
|
__hmrId: 'ShaderMaterial',
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user