-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to use custom font on startup, often shows the browser's default font #15
Comments
document.fonts.load (used in THREE.TextTexture): Libs to wait for font loading: Libs to get font metrics: Metrics explanation: TextMetrics: Another way: |
Possible solution from https://stackoverflow.com/a/64192936: export async function waitForFontLoad(
font: string,
timeout = 1000,
interval = 10
) {
return new Promise((resolve, reject) => {
// repeatedly poll check
const poller = setInterval(async () => {
try {
await document.fonts.load(font);
} catch (err) {
reject(err);
}
if (document.fonts.check(font)) {
clearInterval(poller);
resolve(true);
}
}, interval);
setTimeout(() => clearInterval(poller), timeout);
});
} |
Recommendation to use document.fonts.onloadingdone instead. |
I am loading the
Roboto
font inindex.html
:Then trying to use it in a
TextSprite
:Sometimes, the
TextSprite
renders the browser's default font instead ofRoboto
. Any idea to safely wait forRoboto
?The text was updated successfully, but these errors were encountered: