在three中導入字體文件需要先將ttf文件轉成json
轉換地址: http://gero3.github.io/facetype.js/
轉換后的字體json文件太大了, 處理成3500常用漢字的json
const keys = require('./3500.json'); // 3500漢字+ 其他字符的集合
const fs = require('fs');
const fileName = 'HYXiaoBoZheZhiTiJ_Regular';
(() => {
try {
const data = fs.readFileSync(`./${fileName}.json`, "utf-8")
let fontAll = JSON.parse(data);
const glyphs = {}
keys.map(key => {
if (fontAll.glyphs[key] === undefined) return
glyphs[key] = fontAll.glyphs[key]
})
fontAll.glyphs = glyphs
// let str = JSON.stringify(fontAll, "", "\t");
let str = JSON.stringify(fontAll);
const err = fs.writeFileSync(`./${fileName}_3500.json`, str)
if (err) {console.error(err);}
} catch (error) { console.log(error) }
})()