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

improve material hmr

This commit is contained in:
Kevin Levron 2020-09-19 18:06:09 +02:00
parent 0a0e495e2c
commit 9250eca910
2 changed files with 13 additions and 6 deletions

View File

@ -21,10 +21,10 @@ I will try to rewrite some of my [WebGL demos](https://codepen.io/collection/AGZ
Thanks to VueJS/ViteJS, **TroisJS use watchers and HMR to update ThreeJS objects when you update a template**. This means the result in your browser will be automatically updated without reloading all the stuff. **This is really helpful when you are creating a TroisJS Scene**.
- [ ] HMR
- [x] Camera : position
- [x] PerspectiveCamera : aspect, far, fov, near, position
- [x] Light : position
- [x] Material : color
- [x] Mesh : position, rotation ,scale
- [x] Material : color, depthTest, depthWrite, fog, opacity, transparent
- [x] Mesh : position, rotation, scale
- [ ] ...
## Features

View File

@ -19,7 +19,7 @@ export default {
},
fog: {
type: Boolean,
default: false,
default: true,
},
opacity: {
type: Number,
@ -40,8 +40,15 @@ export default {
},
mounted() {
this.three.materials[this.id] = this.material;
watch(() => this.color, () => {
this.material.color = new Color(this.color);
['color', 'depthTest', 'depthWrite', 'fog', 'opacity', 'transparent'].forEach(p => {
watch(() => this[p], () => {
if (p === 'color') {
this.material.color = new Color(this.color);
} else {
this.material[p] = this[p];
}
});
});
},
unmounted() {