当前位置:   article > 正文

three.js从入门到精通系列教程017 - three.js加载中文字体并绘制斜角立体汉字_threejs 中文字体

threejs 中文字体
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>three.js从入门到精通系列教程017 - three.js加载中文字体并绘制斜角立体汉字</title>
  6. <script src="ThreeJS/three.js"></script>
  7. <script src="ThreeJS/jquery.js"></script>
  8. </head>
  9. <body>
  10. <center id="myContainer"></center>
  11. <script type="text/javascript">
  12. //创建渲染器
  13. var myRenderer = new THREE.WebGLRenderer({ antialias: true });
  14. myRenderer.setSize(window.innerWidth, window.innerHeight);
  15. $("#myContainer").append(myRenderer.domElement);
  16. var myScene = new THREE.Scene();
  17. myScene.background = new THREE.Color('white');
  18. var myCamera = new THREE.OrthographicCamera(-2.5, 2.5, 1.875, -1.875, 1, 100);
  19. myCamera.position.set(3, 3, 20);
  20. myCamera.lookAt(new THREE.Vector3(2, 1, 0));
  21. myScene.add(myCamera);
  22. var myLight = new THREE.DirectionalLight('white');
  23. myLight.position.set(-5, 10, 5);
  24. myScene.add(myLight);
  25. //加载中文字体并绘制斜角汉字
  26. var myFontLoader = new THREE.FontLoader();
  27. myFontLoader.load('Data/MicrosoftYaHei_Regular.json', function (font) {
  28. var myTextGeometry = new THREE.TextGeometry('上善若水',
  29. {
  30. font: font, size: 0.6, height: 1, curveSegments: 120,
  31. bevelEnabled: true, bevelThickness: 1.5,
  32. bevelSize: 0.05, bevelSegments: 3
  33. });
  34. //创建金属发亮材质
  35. var myMaterial = new THREE.MeshPhongMaterial({ color: 0x00ff00 });
  36. var myTextMesh = new THREE.Mesh(myTextGeometry, myMaterial);
  37. myTextMesh.position.y = 0.5;
  38. myScene.add(myTextMesh);
  39. });
  40. //渲染绘制的斜角汉字
  41. animate();
  42. function animate() {
  43. requestAnimationFrame(animate);
  44. myRenderer.render(myScene, myCamera);
  45. }
  46. </script>
  47. </body>
  48. </html>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/520567
推荐阅读
相关标签
  

闽ICP备14008679号