在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) }
})()