1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 12:22:03 +08:00
trois/src/materials/PhongMaterial.js
2021-04-04 20:42:35 +02:00

37 lines
1.2 KiB
JavaScript

import { defineComponent, watch } from 'vue';
import { MeshPhongMaterial } from 'three';
import { bindProps, propsValues } from '../tools';
import Material, { wireframeProps } from './Material';
export default defineComponent({
extends: Material,
props: {
emissive: { type: [Number, String], default: 0 },
emissiveIntensity: { type: Number, default: 1 },
reflectivity: { type: Number, default: 1 },
shininess: { type: Number, default: 30 },
specular: { type: [String, Number], default: 0x111111 },
flatShading: Boolean,
...wireframeProps,
},
methods: {
createMaterial() {
this.material = new MeshPhongMaterial(propsValues(this.$props));
},
addWatchers() {
// TODO : handle flatShading ?
['emissive', 'emissiveIntensity', 'reflectivity', 'shininess', 'specular'].forEach(p => {
watch(() => this[p], (value) => {
if (p === 'emissive' || p === 'specular') {
this.material[p].set(value);
} else {
this.material[p] = value;
}
});
});
bindProps(this, Object.keys(wireframeProps), this.material);
},
},
__hmrId: 'PhongMaterial',
});