1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-25 04:42:01 +08:00
trois/src/materials/StandardMaterial.js

29 lines
844 B
JavaScript
Raw Normal View History

2020-09-20 00:54:50 +08:00
import { Color, MeshStandardMaterial } from 'three';
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-09-17 03:11:23 +08:00
props: {
2020-10-02 00:22:01 +08:00
emissive: { type: [Number, String], default: 0 },
emissiveIntensity: { type: Number, default: 1 },
metalness: { type: Number, default: 0 },
roughness: { type: Number, default: 1 },
2020-09-17 03:11:23 +08:00
},
2020-10-02 00:22:01 +08:00
setup(props) {
const material = new MeshStandardMaterial(propsValues(props, ['id']));
2020-09-20 00:54:50 +08:00
['emissive', 'emissiveIntensity', 'metalness', 'roughness'].forEach(p => {
2020-10-02 00:22:01 +08:00
watch(() => props[p], (value) => {
2020-09-20 00:54:50 +08:00
if (p === 'emissive') {
2020-10-02 00:22:01 +08:00
material.emissive = new Color(value);
2020-09-20 00:54:50 +08:00
} else {
2020-10-02 00:22:01 +08:00
material[p] = value;
2020-09-20 00:54:50 +08:00
}
});
});
2020-10-02 00:22:01 +08:00
return { material };
2020-09-14 22:57:11 +08:00
},
2020-09-19 23:00:29 +08:00
__hmrId: 'StandardMaterial',
2020-09-14 22:57:11 +08:00
};