mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
wip
This commit is contained in:
parent
998f945a77
commit
10a11e152d
@ -27,7 +27,7 @@ Thanks to VueJS/ViteJS, **TroisJS use watchers and HMR to update ThreeJS objects
|
|||||||
- [x] SpotLight : angle, decay, distance, penumbra
|
- [x] SpotLight : angle, decay, distance, penumbra
|
||||||
- [x] Material : color, depthTest, depthWrite, fog, opacity, transparent
|
- [x] Material : color, depthTest, depthWrite, fog, opacity, transparent
|
||||||
- [x] StandardMaterial : emissive, emissiveIntensity, metalness, roughness
|
- [x] StandardMaterial : emissive, emissiveIntensity, metalness, roughness
|
||||||
- [x] Mesh : position, rotation, scale
|
- [x] Mesh : position, rotation, scale, castShadow, receiveShadow
|
||||||
- [ ] ...
|
- [ ] ...
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
@ -11,6 +11,10 @@ export default {
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
autoClear: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
shadow: {
|
shadow: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
@ -50,6 +54,7 @@ export default {
|
|||||||
canvas: this.$refs.canvas,
|
canvas: this.$refs.canvas,
|
||||||
antialias: this.antialias,
|
antialias: this.antialias,
|
||||||
alpha: this.alpha,
|
alpha: this.alpha,
|
||||||
|
autoClear: this.autoClear,
|
||||||
orbit_ctrl: this.orbitCtrl,
|
orbit_ctrl: this.orbitCtrl,
|
||||||
mouse_move: this.mouseMove,
|
mouse_move: this.mouseMove,
|
||||||
mouse_raycast: this.mouseRaycast,
|
mouse_raycast: this.mouseRaycast,
|
||||||
|
@ -17,6 +17,7 @@ export default function useThree() {
|
|||||||
canvas: null,
|
canvas: null,
|
||||||
antialias: true,
|
antialias: true,
|
||||||
alpha: false,
|
alpha: false,
|
||||||
|
autoClear: true,
|
||||||
orbit_ctrl: false,
|
orbit_ctrl: false,
|
||||||
mouse_move: false,
|
mouse_move: false,
|
||||||
mouse_raycast: false,
|
mouse_raycast: false,
|
||||||
@ -84,6 +85,7 @@ export default function useThree() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
obj.renderer = new WebGLRenderer({ canvas: conf.canvas, antialias: conf.antialias, alpha: conf.alpha });
|
obj.renderer = new WebGLRenderer({ canvas: conf.canvas, antialias: conf.antialias, alpha: conf.alpha });
|
||||||
|
obj.renderer.autoClear = conf.autoClear;
|
||||||
|
|
||||||
if (conf.orbit_ctrl) {
|
if (conf.orbit_ctrl) {
|
||||||
obj.orbitCtrl = new OrbitControls(obj.camera, obj.renderer.domElement);
|
obj.orbitCtrl = new OrbitControls(obj.camera, obj.renderer.domElement);
|
||||||
|
@ -46,4 +46,5 @@ export default {
|
|||||||
this.passes.push(pass);
|
this.passes.push(pass);
|
||||||
this.pass = pass;
|
this.pass = pass;
|
||||||
},
|
},
|
||||||
|
__hmrId: 'BokehPass',
|
||||||
};
|
};
|
||||||
|
@ -24,4 +24,5 @@ export default {
|
|||||||
render() {
|
render() {
|
||||||
return this.$slots.default();
|
return this.$slots.default();
|
||||||
},
|
},
|
||||||
|
__hmrId: 'EffectComposer',
|
||||||
};
|
};
|
||||||
|
@ -8,4 +8,5 @@ export default {
|
|||||||
render() {
|
render() {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
__hmrId: 'EffectPass',
|
||||||
};
|
};
|
||||||
|
36
src/effects/FilmPass.js
Normal file
36
src/effects/FilmPass.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { FilmPass } from 'three/examples/jsm/postprocessing/FilmPass.js';
|
||||||
|
import EffectPass from './EffectPass.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: EffectPass,
|
||||||
|
props: {
|
||||||
|
noiseIntensity: {
|
||||||
|
type: Number,
|
||||||
|
default: 0.5,
|
||||||
|
},
|
||||||
|
scanlinesIntensity: {
|
||||||
|
type: Number,
|
||||||
|
default: 0.05,
|
||||||
|
},
|
||||||
|
scanlinesCount: {
|
||||||
|
type: Number,
|
||||||
|
default: 4096,
|
||||||
|
},
|
||||||
|
grayscale: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
noiseIntensity() { this.pass.uniforms.nIntensity.value = this.noiseIntensity; },
|
||||||
|
scanlinesIntensity() { this.pass.uniforms.sIntensity.value = this.scanlinesIntensity; },
|
||||||
|
scanlinesCount() { this.pass.uniforms.sCount.value = this.scanlinesCount; },
|
||||||
|
grayscale() { this.pass.uniforms.grayscale.value = this.grayscale; },
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
const pass = new FilmPass(this.noiseIntensity, this.scanlinesIntensity, this.scanlinesCount, this.grayscale);
|
||||||
|
this.passes.push(pass);
|
||||||
|
this.pass = pass;
|
||||||
|
},
|
||||||
|
__hmrId: 'FilmPass',
|
||||||
|
};
|
@ -14,4 +14,5 @@ export default {
|
|||||||
this.passes.push(pass);
|
this.passes.push(pass);
|
||||||
this.pass = pass;
|
this.pass = pass;
|
||||||
},
|
},
|
||||||
|
__hmrId: 'RenderPass',
|
||||||
};
|
};
|
||||||
|
@ -35,4 +35,5 @@ export default {
|
|||||||
this.passes.push(pass);
|
this.passes.push(pass);
|
||||||
this.pass = pass;
|
this.pass = pass;
|
||||||
},
|
},
|
||||||
|
__hmrId: 'UnrealBloomPass',
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { InstancedMesh } from 'three';
|
import { InstancedMesh } from 'three';
|
||||||
import { setFromProp } from '../tools.js';
|
import { watch } from 'vue';
|
||||||
|
import useBindProp from '../use/useBindProp.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
inject: ['three', 'scene'],
|
inject: ['three', 'scene'],
|
||||||
@ -33,9 +34,17 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.mesh = new InstancedMesh(this.conf.geometry, this.three.materials[this.materialId], this.count);
|
this.mesh = new InstancedMesh(this.conf.geometry, this.three.materials[this.materialId], this.count);
|
||||||
setFromProp(this.mesh.position, this.position);
|
|
||||||
|
useBindProp(this, 'position', this.mesh.position);
|
||||||
|
useBindProp(this, 'rotation', this.mesh.rotation);
|
||||||
|
useBindProp(this, 'scale', this.mesh.scale);
|
||||||
|
|
||||||
this.mesh.castShadow = this.castShadow;
|
this.mesh.castShadow = this.castShadow;
|
||||||
this.mesh.receiveShadow = this.receiveShadow;
|
this.mesh.receiveShadow = this.receiveShadow;
|
||||||
|
['castShadow', 'receiveShadow'].forEach(p => {
|
||||||
|
watch(() => this[p], () => { this.mesh[p] = this[p]; });
|
||||||
|
});
|
||||||
|
|
||||||
this.scene.add(this.mesh);
|
this.scene.add(this.mesh);
|
||||||
},
|
},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Mesh } from 'three';
|
import { Mesh } from 'three';
|
||||||
|
import { watch } from 'vue';
|
||||||
import useBindProp from '../use/useBindProp.js';
|
import useBindProp from '../use/useBindProp.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -38,6 +39,9 @@ export default {
|
|||||||
|
|
||||||
this.mesh.castShadow = this.castShadow;
|
this.mesh.castShadow = this.castShadow;
|
||||||
this.mesh.receiveShadow = this.receiveShadow;
|
this.mesh.receiveShadow = this.receiveShadow;
|
||||||
|
['castShadow', 'receiveShadow'].forEach(p => {
|
||||||
|
watch(() => this[p], () => { this.mesh[p] = this[p]; });
|
||||||
|
});
|
||||||
|
|
||||||
this.scene.add(this.mesh);
|
this.scene.add(this.mesh);
|
||||||
this.$emit('ready');
|
this.$emit('ready');
|
||||||
|
@ -33,8 +33,10 @@ export const TroisJSVuePlugin = {
|
|||||||
'InstancedMesh',
|
'InstancedMesh',
|
||||||
'Sprite',
|
'Sprite',
|
||||||
|
|
||||||
|
// 'BloomPass',
|
||||||
'BokehPass',
|
'BokehPass',
|
||||||
'EffectComposer',
|
'EffectComposer',
|
||||||
|
'FilmPass',
|
||||||
'RenderPass',
|
'RenderPass',
|
||||||
'UnrealBloomPass',
|
'UnrealBloomPass',
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user