当前位置:网站首页>Threejs implements labels and displays labels with custom styles
Threejs implements labels and displays labels with custom styles
2022-07-05 04:00:00 【Zuo Ben】
1, Introduce
Use threejs Realize label display , Here we only introduce how to realize the function of displaying labels , Others can check previous articles .
The renderings are as follows :
2, Main description
Realize the use of labels CSS2DRenderer(2D Renderers ) Rendering .
1, Introduce the renderer and initialize
2, establish dom Element object , Add displayed content and style
3, hold dom The elements are packed into CSS2DObject object , And add it to the scene
4, Use CSS2DRenderer Rendering display
Bring in renderer , And initialization
<script type="text/javascript" src="libs/CSS2DRenderer.js"></script>
var labelRenderer = new THREE.CSS2DRenderer();
labelRenderer.setSize(window.innerWidth, window.innerHeight);
labelRenderer.domElement.style.position = 'absolute';
labelRenderer.domElement.style.top = 0;
document.body.appendChild(labelRenderer.domElement);
Create a label , And add it to the scene
// new label
function createLableObj(text, vector) {
let laberDiv = document.createElement('div');// establish div Containers
laberDiv.className = 'laber_name';
laberDiv.textContent = text + '\n' + " allowance :123";
let pointLabel = new THREE.CSS2DObject(laberDiv);
pointLabel.position.set(vector.x, vector.y, vector.z);
return pointLabel;
}
let pointLabel = createLableObj(text, vector);
scene.add(pointLabel);
Rendering
labelRenderer.render(scene, camera);
If you need a complete code, please leave a message or contact me on wechat :1171053128
边栏推荐
- [untitled]
- 【web審計-源碼泄露】獲取源碼方法,利用工具
- [punch in questions] integrated daily 5-question sharing (phase III)
- 反絮凝剂-氨碘肽滴眼液
- CTF stegano practice stegano 9
- [vérification sur le Web - divulgation du code source] obtenir la méthode du code source et utiliser des outils
- Online text line fixed length fill tool
- Interview byte, pass the exam and directly work on three sides. As a result, I found an architect to hang me?
- Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
- 技术教程:如何利用EasyDSS将直播流推到七牛云?
猜你喜欢
UE4 DMX和grandMA2 onPC 3.1.2.5的操作流程
“金九银十”是找工作的最佳时期吗?那倒未必
IronXL for . NET 2022.6
测试开发是什么?为什么现在那么多公司都要招聘测试开发?
[数组]566. 重塑矩阵-简单
Some enterprise interview questions of unity interview
[wp][introduction] brush weak type questions
【web审计-源码泄露】获取源码方法,利用工具
[untitled]
@The problem of cross database query invalidation caused by transactional annotation
随机推荐
[vérification sur le Web - divulgation du code source] obtenir la méthode du code source et utiliser des outils
postman和postman interceptor的安装
UI自動化測試從此告別手動下載瀏覽器驅動
[PHP features - variable coverage] improper use, improper configuration and code logic vulnerability of the function
Nmap user manual learning records
How is the entered query SQL statement executed?
How does the applet solve the rendering layer network layer error?
Plasticscm enterprise crack
Wechat applet development process (with mind map)
[wp]bmzclub几道题的writeup
Containerization Foundation
Containerd series - what is containerd?
Operation flow of UE4 DMX and grandma2 onpc 3.1.2.5
[punch in questions] integrated daily 5-question sharing (phase III)
Why do big companies such as Baidu and Alibaba prefer to spend 25K to recruit fresh students rather than raise wages by 5K to retain old employees?
函数基础学习02
provide/inject
@Transactional 注解导致跨库查询失效的问题
基于TCP的移动端IM即时通讯开发仍然需要心跳保活
“金九银十”是找工作的最佳时期吗?那倒未必