1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00
This commit is contained in:
Kevin Levron 2020-09-19 21:42:33 +02:00
parent 10a11e152d
commit 1611539d63
8 changed files with 71 additions and 12 deletions

View File

@ -28,6 +28,10 @@ Thanks to VueJS/ViteJS, **TroisJS use watchers and HMR to update ThreeJS objects
- [x] Material : color, depthTest, depthWrite, fog, opacity, transparent
- [x] StandardMaterial : emissive, emissiveIntensity, metalness, roughness
- [x] Mesh : position, rotation, scale, castShadow, receiveShadow
- [x] Box (geometry replace) : size, width, height, depth
- [x] Plane (geometry replace) : width, height, widthSegments, heightSegments
- [x] Sphere (geometry replace) : radius, widthSegments, heightSegments
- [x] Text (geometry replace) : all props except fontSrc (wip)
- [ ] ...
## Features

View File

@ -1,4 +1,5 @@
export { default as EffectComposer } from './EffectComposer.js';
export { default as RenderPass } from './RenderPass.js';
export { default as BokehPass } from './BokehPass.js';
export { default as FilmPass } from './FilmPass.js';
export { default as UnrealBloomPass } from './UnrealBloomPass.js';

View File

@ -20,12 +20,23 @@ export default {
default: 1,
},
},
watch: {
size() { this.refreshGeometry(); },
width() { this.refreshGeometry(); },
height() { this.refreshGeometry(); },
depth() { this.refreshGeometry(); },
},
created() {
this.createGeometry();
},
methods: {
createGeometry() {
if (this.size) {
this.geometry = new BoxBufferGeometry(this.size, this.size, this.size);
} else {
this.geometry = new BoxBufferGeometry(this.width, this.height, this.depth);
}
},
},
__hmrId: 'Box',
};

View File

@ -46,6 +46,12 @@ export default {
this.scene.add(this.mesh);
this.$emit('ready');
},
refreshGeometry() {
const oldGeo = this.geometry;
this.createGeometry();
this.mesh.geometry = this.geometry;
oldGeo.dispose();
},
},
render() {
return [];

View File

@ -21,8 +21,19 @@ export default {
default: 1,
},
},
watch: {
width() { this.refreshGeometry(); },
height() { this.refreshGeometry(); },
widthSegments() { this.refreshGeometry(); },
heightSegments() { this.refreshGeometry(); },
},
created() {
this.createGeometry();
},
methods: {
createGeometry() {
this.geometry = new PlaneBufferGeometry(this.width, this.height, this.widthSegments, this.heightSegments);
},
},
__hmrId: 'Plane',
};

View File

@ -14,8 +14,18 @@ export default {
default: 12,
},
},
watch: {
radius() { this.refreshGeometry(); },
widthSegments() { this.refreshGeometry(); },
heightSegments() { this.refreshGeometry(); },
},
created() {
this.createGeometry();
},
methods: {
createGeometry() {
this.geometry = new SphereBufferGeometry(this.radius, this.widthSegments, this.heightSegments);
},
},
__hmrId: 'Sphere',
};

View File

@ -31,7 +31,6 @@ export default {
this.$emit('loaded');
},
updateUV() {
// console.log(this.texture);
this.iWidth = this.texture.image.width;
this.iHeight = this.texture.image.height;
this.iRatio = this.iWidth / this.iHeight;

View File

@ -1,5 +1,6 @@
import { FontLoader, TextBufferGeometry } from 'three';
import Mesh from './Mesh.js';
import { watch } from 'vue';
export default {
extends: Mesh,
@ -18,11 +19,29 @@ export default {
align: { type: [Boolean, String], default: false },
},
created() {
// add watchers
const watchProps = [
'text', 'size', 'height', 'curveSegments',
'bevelEnabled', 'bevelThickness', 'bevelSize', 'bevelOffset', 'bevelSegments',
'align',
];
watchProps.forEach(p => {
watch(() => this[p], () => {
if (this.font) this.refreshGeometry();
});
});
const loader = new FontLoader();
loader.load(this.fontSrc, (font) => {
this.font = font;
this.createGeometry();
this.initMesh();
});
},
methods: {
createGeometry() {
this.geometry = new TextBufferGeometry(this.text, {
font,
font: this.font,
size: this.size,
height: this.height,
depth: this.depth,
@ -37,8 +56,6 @@ export default {
if (this.align === 'center') {
this.geometry.center();
}
this.initMesh();
});
},
},
};