1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00

wireframe props, fix #20, close #22

This commit is contained in:
Kevin Levron 2021-03-13 16:41:01 +01:00
parent e5c2b3f947
commit 444060b91d
7 changed files with 49 additions and 12 deletions

View File

@ -1,13 +1,19 @@
import { MeshBasicMaterial } from 'three'; import { MeshBasicMaterial } from 'three';
import { propsValues } from '../tools.js'; import { bindProps, propsValues } from '../tools.js';
import Material from './Material'; import Material, { wireframeProps } from './Material';
export default { export default {
extends: Material, extends: Material,
props: {
...wireframeProps,
},
methods: { methods: {
createMaterial() { createMaterial() {
this.material = new MeshBasicMaterial(propsValues(this.$props)); this.material = new MeshBasicMaterial(propsValues(this.$props));
}, },
addWatchers() {
bindProps(this, Object.keys(wireframeProps), this.material);
},
}, },
__hmrId: 'BasicMaterial', __hmrId: 'BasicMaterial',
}; };

View File

@ -1,13 +1,19 @@
import { MeshLambertMaterial } from 'three'; import { MeshLambertMaterial } from 'three';
import { propsValues } from '../tools.js'; import { bindProps, propsValues } from '../tools.js';
import Material from './Material'; import Material, { wireframeProps } from './Material';
export default { export default {
extends: Material, extends: Material,
props: {
...wireframeProps,
},
methods: { methods: {
createMaterial() { createMaterial() {
this.material = new MeshLambertMaterial(propsValues(this.$props)); this.material = new MeshLambertMaterial(propsValues(this.$props));
}, },
addWatchers() {
bindProps(this, Object.keys(wireframeProps), this.material);
},
}, },
__hmrId: 'LambertMaterial', __hmrId: 'LambertMaterial',
}; };

View File

@ -53,3 +53,11 @@ export default {
}, },
__hmrId: 'Material', __hmrId: 'Material',
}; };
export const wireframeProps = {
wireframe: { type: Boolean, default: false },
// not needed for WebGL
// wireframeLinecap: { type: String, default: 'round' },
// wireframeLinejoin: { type: String, default: 'round' },
wireframeLinewidth: { type: Number, default: 1 }, // not really useful
};

View File

@ -1,7 +1,7 @@
import { MeshPhongMaterial } from 'three'; import { MeshPhongMaterial } from 'three';
import { watch } from 'vue'; import { watch } from 'vue';
import { propsValues } from '../tools.js'; import { bindProps, propsValues } from '../tools.js';
import Material from './Material'; import Material, { wireframeProps } from './Material';
export default { export default {
extends: Material, extends: Material,
@ -12,6 +12,7 @@ export default {
shininess: { type: Number, default: 30 }, shininess: { type: Number, default: 30 },
specular: { type: [String, Number], default: 0x111111 }, specular: { type: [String, Number], default: 0x111111 },
flatShading: Boolean, flatShading: Boolean,
...wireframeProps,
}, },
methods: { methods: {
createMaterial() { createMaterial() {
@ -28,6 +29,7 @@ export default {
} }
}); });
}); });
bindProps(this, Object.keys(wireframeProps), this.material);
}, },
}, },
__hmrId: 'PhongMaterial', __hmrId: 'PhongMaterial',

View File

@ -1,7 +1,7 @@
import { MeshStandardMaterial } from 'three'; import { MeshStandardMaterial } from 'three';
import { watch } from 'vue'; import { watch } from 'vue';
import { bindProp, propsValues } from '../tools.js'; import { bindProp, bindProps, propsValues } from '../tools.js';
import Material from './Material'; import Material, { wireframeProps } from './Material';
const props = { const props = {
aoMapIntensity: { type: Number, default: 1 }, aoMapIntensity: { type: Number, default: 1 },
@ -17,12 +17,14 @@ const props = {
roughness: { type: Number, default: 1 }, roughness: { type: Number, default: 1 },
refractionRatio: { type: Number, default: 0.98 }, refractionRatio: { type: Number, default: 0.98 },
flatShading: Boolean, flatShading: Boolean,
wireframe: Boolean,
}; };
export default { export default {
extends: Material, extends: Material,
props, props: {
...props,
...wireframeProps,
},
methods: { methods: {
createMaterial() { createMaterial() {
this.material = new MeshStandardMaterial(propsValues(this.$props, ['normalScale'])); this.material = new MeshStandardMaterial(propsValues(this.$props, ['normalScale']));
@ -40,6 +42,7 @@ export default {
}); });
}); });
bindProp(this, 'normalScale', this.material); bindProp(this, 'normalScale', this.material);
bindProps(this, Object.keys(wireframeProps), this.material);
}, },
}, },
__hmrId: 'StandardMaterial', __hmrId: 'StandardMaterial',

View File

@ -1,13 +1,19 @@
import { MeshToonMaterial } from 'three'; import { MeshToonMaterial } from 'three';
import { propsValues } from '../tools.js'; import { bindProps, propsValues } from '../tools.js';
import Material from './Material'; import Material, { wireframeProps } from './Material';
export default { export default {
extends: Material, extends: Material,
props: {
...wireframeProps,
},
methods: { methods: {
createMaterial() { createMaterial() {
this.material = new MeshToonMaterial(propsValues(this.$props)); this.material = new MeshToonMaterial(propsValues(this.$props));
}, },
addWatchers() {
bindProps(this, Object.keys(wireframeProps), this.material);
},
}, },
__hmrId: 'ToonMaterial', __hmrId: 'ToonMaterial',
}; };

View File

@ -8,6 +8,12 @@ export function setFromProp(o, prop) {
} }
}; };
export function bindProps(src, props, dst) {
props.forEach(prop => {
bindProp(src, prop, dst);
});
};
export function bindProp(src, srcProp, dst, dstProp) { export function bindProp(src, srcProp, dst, dstProp) {
if (!dstProp) dstProp = srcProp; if (!dstProp) dstProp = srcProp;
const ref = toRef(src, srcProp); const ref = toRef(src, srcProp);