mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
update phong & standard
This commit is contained in:
parent
864adc1379
commit
92c419040e
@ -1,13 +1,33 @@
|
|||||||
import { MeshPhongMaterial } from 'three';
|
import { MeshPhongMaterial } from 'three';
|
||||||
|
import { watch } from 'vue';
|
||||||
import { propsValues } from '../tools.js';
|
import { propsValues } from '../tools.js';
|
||||||
import Material from './Material';
|
import Material from './Material';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
extends: Material,
|
extends: Material,
|
||||||
|
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 },
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
createMaterial() {
|
createMaterial() {
|
||||||
|
console.log(this.$props);
|
||||||
this.material = new MeshPhongMaterial(propsValues(this.$props, ['id']));
|
this.material = new MeshPhongMaterial(propsValues(this.$props, ['id']));
|
||||||
},
|
},
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
__hmrId: 'PhongMaterial',
|
__hmrId: 'PhongMaterial',
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Color, MeshStandardMaterial } from 'three';
|
import { MeshStandardMaterial } from 'three';
|
||||||
import { watch } from 'vue';
|
import { watch } from 'vue';
|
||||||
import { propsValues } from '../tools.js';
|
import { propsValues } from '../tools.js';
|
||||||
import Material from './Material';
|
import Material from './Material';
|
||||||
@ -19,7 +19,7 @@ export default {
|
|||||||
['emissive', 'emissiveIntensity', 'metalness', 'roughness'].forEach(p => {
|
['emissive', 'emissiveIntensity', 'metalness', 'roughness'].forEach(p => {
|
||||||
watch(() => this[p], (value) => {
|
watch(() => this[p], (value) => {
|
||||||
if (p === 'emissive') {
|
if (p === 'emissive') {
|
||||||
this.material.emissive = new Color(value);
|
this.material[p].set(value);
|
||||||
} else {
|
} else {
|
||||||
this.material[p] = value;
|
this.material[p] = value;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user