mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 20:32:02 +08:00
32 lines
906 B
JavaScript
32 lines
906 B
JavaScript
import { Color, MeshStandardMaterial } 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 },
|
|
metalness: { type: Number, default: 0 },
|
|
roughness: { type: Number, default: 1 },
|
|
},
|
|
methods: {
|
|
createMaterial() {
|
|
this.material = new MeshStandardMaterial(propsValues(this.$props, ['id']));
|
|
},
|
|
addWatchers() {
|
|
['emissive', 'emissiveIntensity', 'metalness', 'roughness'].forEach(p => {
|
|
watch(() => this[p], (value) => {
|
|
if (p === 'emissive') {
|
|
this.material.emissive = new Color(value);
|
|
} else {
|
|
this.material[p] = value;
|
|
}
|
|
});
|
|
});
|
|
},
|
|
},
|
|
__hmrId: 'StandardMaterial',
|
|
};
|