当前位置: 首页 > news >正文

three.js ——文字

three.js ——文字

<!--* @Date: 2025-09-22 13:53:07* @LastEditors: jiayaolin01 “jiayl@wizpower.com”* @LastEditTime: 2025-09-23 15:56:09* @FilePath: \threejs-demo\text.html
-->
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>My first three.js app</title><style>body {margin: 0;}</style>
</head><body><script type="importmap">{"imports": {"three": "./node_modules/three/build/three.module.js","three/examples/jsm/": "./node_modules/three/examples/jsm/"}}
</script><script type="module">// three/examples/jsm/路径之后对应的是three.js官方文件包`/examples/jsm/`中的js库import * as THREE from 'three';// 扩展库OrbitControls.jsimport { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';// 扩展库GLTFLoader.jsimport { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';console.log(OrbitControls);console.log(GLTFLoader);import { TextGeometry } from 'https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/geometries/TextGeometry.js';
import { FontLoader } from 'https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/loaders/FontLoader.js';// 创建场景const scene = new THREE.Scene();scene.background = new THREE.Color(0x333333);// 创建相机const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);camera.position.z = 200;// 创建渲染器const renderer = new THREE.WebGLRenderer({ antialias: true });renderer.setSize(window.innerWidth, window.innerHeight);document.body.appendChild(renderer.domElement);// 加载字体并创建文字const loader = new FontLoader();loader.load('https://unpkg.com/three@0.160.0/examples/fonts/helvetiker_regular.typeface.json', function (font) {// 创建文字几何体const textGeometry = new TextGeometry('Hello three.js!', {font: font,size: 20,height: 5,curveSegments: 12,bevelEnabled: true,bevelThickness: 2,bevelSize: 1,bevelSegments: 5});// 创建材质const textMaterial = new THREE.MeshPhongMaterial({ color: 0x00ff00,shininess: 100 });// 创建网格对象const textMesh = new THREE.Mesh(textGeometry, textMaterial);// 居中文字textGeometry.computeBoundingBox();const centerOffset = -0.5 * (textGeometry.boundingBox.max.x - textGeometry.boundingBox.min.x);textMesh.position.x = centerOffset;textMesh.position.y = -50;// 添加到场景scene.add(textMesh);// 添加光源const ambientLight = new THREE.AmbientLight(0x404040, 2);scene.add(ambientLight);const directionalLight = new THREE.DirectionalLight(0xffffff, 1);directionalLight.position.set(1, 1, 1);scene.add(directionalLight);// 渲染循环function animate() {requestAnimationFrame(animate);textMesh.rotation.y += 0.01;renderer.render(scene, camera);}animate();});// 窗口大小调整window.addEventListener('resize', function() {camera.aspect = window.innerWidth / window.innerHeight;camera.updateProjectionMatrix();renderer.setSize(window.innerWidth, window.innerHeight);});</script></body></html>
<style>#info {position: absolute;top: 10px;width: 100%;text-align: center;z-index: 100;display: block;}
</style>

效果图

在这里插入图片描述

文档链接

http://www.webgl3d.cn/Three.js/

http://www.dtcms.com/a/398942.html

相关文章:

  • 中山市智能h5网站建设公司wordpress电视剧
  • 个人网站域名一级a做爰片免费网站黄
  • mac m4电脑运行 LLaMA Factory 微调
  • 基于Python的二手房价格数据分析预测系统
  • 【速成】快速掌握CMD
  • 网站建设找哪个网盟官方网站
  • NCL数据分析与处理实践技术应用
  • 莱阳 网站建设商城前端模板
  • 【APK安全】Receiver嗅探:Android广播组件的权限与UID安全防护及测试指南
  • (自用)vim的高级命令
  • ELK分析系统详解
  • 架构师成长之路06:缓存设计收官篇,缓存该放哪?写缓存怎么用?这篇讲透最后两个核心问题
  • 电子商务网站建设外包服务wordpress 教程
  • 简述Android应用程序结构包含哪些部分
  • 百度网站改版提交wordpress主题改中文版
  • 前端埋点(tracking)技术介绍(记录用户行为和页面性能数据)(埋点代码)ajax埋点、img埋点、navigator.sendBeacon埋点
  • 网站备案ps网站建设入门教程视频教程
  • 免费申请网站永久域名建设一个网站用什么软件下载
  • 内存泄漏可能由哪些原因导致?
  • 数据采集与同步
  • Weblogic T3 CVE-2018-2628漏洞复现
  • Spring Cloud Alibaba快速入门-Sentinel熔断规则
  • TDEngine-OSS-3.3.7.5开源版搭建手册(包含单节点与三副本高可用方案搭建)
  • 【强化学习】解决MPE环境中两个小球重合导致态势为nan问题
  • 建教会网站的内容部门网站建设个人总结
  • 陕西省建设监理协会网站证书关于网站开发的外文书籍
  • FFmpegLinux开发环境开荒
  • iPhone HTTPS 抓包实战,原理、常见工具、SSL Pinning 问题与替代工具的解决方案
  • 在百度做橱柜网站wordpress add_editor_style
  • 256m内存 wordpresswordpress 博客主题 seo