threejs特殊几何体(一:文字几何体对象)

threejs中文字几何体通过newTextGeometry()生成,它被单独作为一个类存在于threejs中const txtGeo = new TextGeometry("threejs", { ...opts, font: font });

我们先看效果:

复制代码
<template>
    <div>
    </div>
</template>
<script  setup>
import { ref } from "vue";
import * as THREE from "three";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
import { TextGeometry } from "three/examples/jsm/geometries/TextGeometry";
import { FontLoader } from "three/examples/jsm/loaders/FontLoader";
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
  75,
  window.innerWidth / window.innerHeight,
  0.1,
  1000
);
// const font = new THREE.Font("Arial");
camera.position.set(0, 0, 10);

let opts = {
  size: 3,
  height: 5,
  //   fontWeight: "bold",
  bevelSize: 3,
  bevelEnabled: false,
  steps: 7,
  font: "",
  bevelThickness: 1
};

const ftloader = new FontLoader();
ftloader.load("/src/assets/fonts/helvetiker_regular.typeface.json", font => {
  const txtGeo = new TextGeometry("sean", { ...opts, font: font });
  const mesh = new THREE.Mesh(
    txtGeo,
    new THREE.MeshBasicMaterial({ color: "#e6c" })
  );
  scene.add(mesh);
});

const renderder = new THREE.WebGLRenderer();
renderder.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderder.domElement);
renderder.setClearColor("#eee");
const control = new OrbitControls(camera, renderder.domElement);
const render = () => {
  requestAnimationFrame(render);
  renderder.render(scene, camera);
};
render();
</script>
<style scoped>
/* body {
  font-family: Arial, Helvetica, sans-serif;
} */
</style>

这里特别要注意的是:

注意点:1 文字几何体font必须要引入。可以使用three库默认的字体。该字体位于three/example/fonts/文件夹下,默认字体采用了json文件格式

2 给TextGeometry添加配资的时候,font选项不是普通的字体对象而是three里面的字体对象。也就是font是 new FontLoader()。load加载后的字体对象

相关推荐
毕业设计制作和分享1 小时前
springboot150基于springboot的贸易行业crm系统
java·vue.js·spring boot·后端·毕业设计·mybatis
键盘不能没有CV键3 小时前
【图片处理】✈️HTML转图片字体异常处理
前端·javascript·html
yantuguiguziPGJ4 小时前
WPF 联合 Web 开发调试流程梳理(基于 Microsoft.Web.WebView2)
前端·microsoft·wpf
大飞记Python4 小时前
部门管理|“编辑部门”功能实现(Django5零基础Web平台)
前端·数据库·python·django
tsumikistep5 小时前
【前端】前端运行环境的结构
前端
你的人类朋友5 小时前
【Node】认识multer库
前端·javascript·后端
Aitter5 小时前
PDF和Word文件转换为Markdown的技术实现
前端·ai编程
mapbar_front6 小时前
面试问题—上家公司的离职原因
前端·面试
昔人'7 小时前
css使用 :where() 来简化大型 CSS 选择器列表
前端·css
昔人'7 小时前
css `dorp-shadow`
前端·css