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

add text mesh

This commit is contained in:
Kevin Levron 2020-09-17 22:37:19 +02:00
parent 885cb21f8e
commit 8a5040e9f6
4 changed files with 55 additions and 8 deletions

View File

@ -33,7 +33,9 @@ I started from scratch... I don't know if I will have time to maintain this, but
- [ ] ... - [ ] ...
- [ ] Meshes - [ ] Meshes
- [x] Box - [x] Box
- [x] Plane
- [x] Sphere - [x] Sphere
- [x] Text
- [x] InstancedMesh - [x] InstancedMesh
- [ ] ... - [ ] ...
- [ ] Post Processing - [ ] Post Processing
@ -41,6 +43,7 @@ I started from scratch... I don't know if I will have time to maintain this, but
- [x] Renderpass - [x] Renderpass
- [x] UnrealBloomPass - [x] UnrealBloomPass
- [ ] ... - [ ] ...
- [ ] Watch props
- [ ] Improve HMR - [ ] Improve HMR
## Installation ## Installation

View File

@ -18,6 +18,13 @@ export default {
}, },
}, },
mounted() { mounted() {
if (this.geometry) this.initMesh();
},
unmounted() {
if (this.geometry) this.geometry.dispose();
},
methods: {
initMesh() {
this.mesh = new Mesh(this.geometry, this.three.materials[this.material]); this.mesh = new Mesh(this.geometry, this.three.materials[this.material]);
setFromProp(this.mesh.position, this.position); setFromProp(this.mesh.position, this.position);
setFromProp(this.mesh.rotation, this.rotation); setFromProp(this.mesh.rotation, this.rotation);
@ -26,8 +33,6 @@ export default {
this.mesh.receiveShadow = this.receiveShadow; this.mesh.receiveShadow = this.receiveShadow;
this.scene.add(this.mesh); this.scene.add(this.mesh);
}, },
unmounted() {
this.geometry.dispose();
}, },
render() { render() {
return []; return [];

38
src/meshes/Text.js Normal file
View File

@ -0,0 +1,38 @@
import { FontLoader, TextBufferGeometry } from 'three';
import Mesh from './Mesh.js';
export default {
extends: Mesh,
props: {
text: String,
fontSrc: String,
size: { type: Number, default: 80 },
height: { type: Number, default: 5 },
depth: { type: Number, default: 1 },
curveSegments: { type: Number, default: 12 },
bevelEnabled: { type: Boolean, default: false },
bevelThickness: { type: Number, default: 10 },
bevelSize: { type: Number, default: 8 },
bevelOffset: { type: Number, default: 0 },
bevelSegments: { type: Number, default: 5 },
},
created() {
const loader = new FontLoader();
loader.load(this.fontSrc, (font) => {
this.font = font;
this.geometry = new TextBufferGeometry(this.text, {
font,
size: this.size,
height: this.height,
depth: this.depth,
curveSegments: this.curveSegments,
bevelEnabled: this.bevelEnabled,
bevelThickness: this.bevelThickness,
bevelSize: this.bevelSize,
bevelOffset: this.bevelOffset,
bevelSegments: this.bevelSegments,
});
this.initMesh();
});
},
};

View File

@ -1,5 +1,6 @@
export { default as Box } from './Box.js'; export { default as Box } from './Box.js';
export { default as Plane } from './Plane.js'; export { default as Plane } from './Plane.js';
export { default as Sphere } from './Sphere.js'; export { default as Sphere } from './Sphere.js';
export { default as Text } from './Text.js';
export { default as InstancedMesh } from './InstancedMesh.js'; export { default as InstancedMesh } from './InstancedMesh.js';