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

34 lines
1008 B
JavaScript

import { MeshPhongMaterial } from 'three';
import { watch } from 'vue';
import { propsValues } from '../tools.js';
import Material from './Material';
export default {
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 },
},
methods: {
createMaterial() {
console.log(this.$props);
this.material = new MeshPhongMaterial(propsValues(this.$props, ['id']));
},
addWatchers() {
['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;
}
});
});
},
},
__hmrId: 'PhongMaterial',
};