TextObjects - set default font family + make loading asynchronous

This commit is contained in:
2026-02-02 17:59:32 +02:00
parent 73fa7bb8d3
commit 04aa57be38
@@ -4,6 +4,7 @@ import { assignParams } from "@/lib/MeshUtils";
class TextObject { class TextObject {
constructor(engine, obj) { constructor(engine, obj) {
return new Promise((resolve, reject)=>{
const txt = new Text(); const txt = new Text();
// Set properties to configure: // Set properties to configure:
txt.text = obj.text; txt.text = obj.text;
@@ -11,7 +12,7 @@ class TextObject {
txt.lineHeight = 1.1; txt.lineHeight = 1.1;
//txt.maxWidth = obj.width; //txt.maxWidth = obj.width;
txt.textAlign = 'center'; txt.textAlign = 'center';
txt.font = obj.fontPath; txt.font = obj.fontPath || '/static/fonts/Montserrat-Regular.ttf';
txt.anchorX = 'center'; txt.anchorX = 'center';
txt.anchorY = 'bottom'; txt.anchorY = 'bottom';
txt.curveRadius = 0; txt.curveRadius = 0;
@@ -29,9 +30,11 @@ class TextObject {
txt.material = m; txt.material = m;
txt.sync(()=>{ txt.sync(()=>{
txt.material[1].opacity = 1; txt.material[1].opacity = 1;
resolve(this);
}); });
this.txt = txt; this.txt = txt;
this.object = txt; this.object = txt;
})
} }
} }