2021-04-19 06:10:00 +08:00
|
|
|
import { defineComponent, watch } from 'vue'
|
|
|
|
import { MeshPhongMaterial } from 'three'
|
|
|
|
import { bindProps, propsValues } from '../tools'
|
|
|
|
import Material, { wireframeProps } from './Material'
|
2020-09-14 22:57:11 +08:00
|
|
|
|
2021-04-05 02:42:35 +08:00
|
|
|
export default defineComponent({
|
2020-09-14 22:57:11 +08:00
|
|
|
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 },
|
2021-03-13 06:54:55 +08:00
|
|
|
flatShading: Boolean,
|
2021-03-13 23:41:01 +08:00
|
|
|
...wireframeProps,
|
2020-10-04 16:22:26 +08:00
|
|
|
},
|
2020-10-03 18:34:14 +08:00
|
|
|
methods: {
|
|
|
|
createMaterial() {
|
2021-04-19 06:10:00 +08:00
|
|
|
const material = new MeshPhongMaterial(propsValues(this.$props))
|
|
|
|
|
2021-03-13 06:54:55 +08:00
|
|
|
// TODO : handle flatShading ?
|
2021-04-19 06:10:00 +08:00
|
|
|
const watchProps = ['emissive', 'emissiveIntensity', 'reflectivity', 'shininess', 'specular']
|
|
|
|
watchProps.forEach(p => {
|
2020-10-04 16:22:26 +08:00
|
|
|
watch(() => this[p], (value) => {
|
|
|
|
if (p === 'emissive' || p === 'specular') {
|
2021-04-19 06:10:00 +08:00
|
|
|
material[p].set(value)
|
2020-10-04 16:22:26 +08:00
|
|
|
} else {
|
2021-04-19 06:10:00 +08:00
|
|
|
material[p] = value
|
2020-10-04 16:22:26 +08:00
|
|
|
}
|
2021-04-19 06:10:00 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
bindProps(this, Object.keys(wireframeProps), material)
|
|
|
|
|
|
|
|
return material
|
2020-10-04 16:22:26 +08:00
|
|
|
},
|
2020-09-14 22:57:11 +08:00
|
|
|
},
|
2020-09-19 23:00:29 +08:00
|
|
|
__hmrId: 'PhongMaterial',
|
2021-04-19 06:10:00 +08:00
|
|
|
})
|