1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 12:22:03 +08:00
trois/src/materials/PhysicalMaterial.js

23 lines
655 B
JavaScript
Raw Normal View History

2020-10-02 00:22:01 +08:00
import { Color, MeshPhysicalMaterial } from 'three';
import { watch } from 'vue';
import { propsValues } from '../tools.js';
import StandardMaterial from './StandardMaterial';
2020-09-14 22:57:11 +08:00
export default {
2020-10-02 00:22:01 +08:00
extends: StandardMaterial,
setup(props) {
const material = new MeshPhysicalMaterial(propsValues(props, ['id']));
['emissive', 'emissiveIntensity', 'metalness', 'roughness'].forEach(p => {
watch(() => props[p], (value) => {
if (p === 'emissive') {
material.emissive = new Color(value);
} else {
material[p] = value;
}
});
2020-09-14 22:57:11 +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: 'PhysicalMaterial',
2020-09-14 22:57:11 +08:00
};