javascript - Using fonts different than default in Three.js - Stack Overflow

So I am using three.js for a project and would like to be able to use a font other than the default &qu

So I am using three.js for a project and would like to be able to use a font other than the default "helvetiker". I've done some digging and discovered that you need to convert the font using typeface.js to get a font file, and have already done that, I just can't figure out how to "plug" this font into threejs. I've dug through the mrdoob three.js examples and can't find anything, Ive also dug around in the three.js source file and have found a loadFace function in THREE.FontUtils, but i'm not sure how to use this. This is my first project using Three.js so any help would be greatly appreciated. Thanks!

Greg

So I am using three.js for a project and would like to be able to use a font other than the default "helvetiker". I've done some digging and discovered that you need to convert the font using typeface.js to get a font file, and have already done that, I just can't figure out how to "plug" this font into threejs. I've dug through the mrdoob three.js examples and can't find anything, Ive also dug around in the three.js source file and have found a loadFace function in THREE.FontUtils, but i'm not sure how to use this. This is my first project using Three.js so any help would be greatly appreciated. Thanks!

Greg

Share Improve this question edited Feb 5, 2014 at 17:30 VividD 10.5k8 gold badges66 silver badges112 bronze badges asked Mar 4, 2013 at 18:59 user1518911user1518911 411 silver badge4 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

I see this question unanswered exactly. The exact font name that is necessary for threejs should be found at the end of the typeface (js) file. It is:

"familyName":"fontname"

threejs needs the name inside the quotes BUT in LOWERCASE. So Example for e.g. font: Old English Text MT

You should find at the end of the (js) typeface file...,"familyName":"Old English Text MT",... so you fill in threejs this:

font: "old english text mt"

(or whatever is exactly after familyName in quotes but in lowercase. If you edit the text after familyName in the (js) typeface file e.g. "familyName":"cAt aNd DOg" you have to use it then. So threejs declare should look then:

var text3d = new THREE.TextGeometry(n.text, { size: 15, height: 10, curveSegments: 10, font: "cat and dog" });

Finally be sure you put your (js) typeface file into header section for the web site e.g:

<script src="fonts/droid/droid_serif_bold.typeface.js"></script>

Last thing that would be helpful is link for (js) typeface file generator: http://typeface.neocracy/fonts.html

All I had to do for mine was load the font in a script tag and change the font in the TextGeometry:

var text3d = new THREE.TextGeometry(n.text, {
  size: 10,
  height: 5,
  curveSegments: 2,
  font: "droid sans"  //change this
});

I don't think there are any other steps necessary.

As Tim says, the only tricky thing is to get the font name right. It seems to be the "family name" that is inside the generated js, (font_family_name) in lowercase - keeping spaces. You can even edit it (in the .js) if you find it convenient - I've done that myself.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745189771a4615810.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信