2020-09-14 22:57:11 +08:00
|
|
|
import { MeshPhongMaterial } from 'three';
|
2020-10-04 16:22:26 +08:00
|
|
|
import { watch } from 'vue';
|
2020-10-02 00:22:01 +08:00
|
|
|
import { propsValues } from '../tools.js';
|
2020-09-14 22:57:11 +08:00
|
|
|
import Material from './Material';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
extends: Material,
|
2020-10-04 16:22:26 +08:00
|
|
|
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 },
|
|
|
|
},
|
2020-10-03 18:34:14 +08:00
|
|
|
methods: {
|
|
|
|
createMaterial() {
|
|
|
|
this.material = new MeshPhongMaterial(propsValues(this.$props, ['id']));
|
|
|
|
},
|
2020-10-04 16:22:26 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2020-09-14 22:57:11 +08:00
|
|
|
},
|
2020-09-19 23:00:29 +08:00
|
|
|
__hmrId: 'PhongMaterial',
|
2020-09-14 22:57:11 +08:00
|
|
|
};
|