javascript 如何将标签添加到 THREE.Mesh?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11447821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:15:49  来源:igfitidea点击:

how to add Label to a THREE.Mesh?

javascriptthree.js

提问by George Neil

The objective is to display the Three.Mesh name as a label while hovering the mouse over the mesh. How we can do this in Three.js

目标是在将鼠标悬停在网格上时将 Three.Mesh 名称显示为标签。我们如何在 Three.js 中做到这一点

Can someone give a sample code ?

有人可以提供示例代码吗?

回答by Lee Stemkoski

Challenge accepted!

接受挑战!

Working code example at: http://stemkoski.github.com/Three.js/Mouse-Tooltip.html

工作代码示例位于:http: //stemkoski.github.com/Three.js/Mouse-Tooltip.html

There appear to be three major steps to this goal, each of which I have broken into smaller example programs.

这个目标似乎分为三个主要步骤,每个步骤我都分解成较小的示例程序。

(1) Determine which scene element the mouse is pointed over. See: http://stemkoski.github.com/Three.js/Mouse-Over.html

(1) 判断鼠标指向的场景元素。见:http: //stemkoski.github.com/Three.js/Mouse-Over.html

(2) Render the text you want to display as an image (I used a canvas element for this). See: http://stemkoski.github.com/Three.js/Texture-From-Canvas.html

(2) 将要显示的文本渲染为图像(为此我使用了画布元素)。见:http: //stemkoski.github.com/Three.js/Texture-From-Canvas.html

(3) Draw a sprite containing the image from part (2) at the location of the mouse pointer. See: http://stemkoski.github.com/Three.js/Mouse-Sprite.html

(3) 在鼠标指针位置绘制一个包含第 (2) 部分图像的精灵。见:http: //stemkoski.github.com/Three.js/Mouse-Sprite.html

All these examples (and more) are part of my growing collection of introductory examples (with detailed comments) at http://stemkoski.github.com/Three.js/, in which I am trying to showcase the possibilities of Three.js in a series of minimal examples.

所有这些示例(以及更多)都是我在http://stemkoski.github.com/Three.js/ 上不断增加的介绍性示例(带有详细评论)集合的一部分,我试图在其中展示 Three.js 的可能性在一系列最小的例子中。

Also, credit where it's due: parts (1) and (3) are based on some of MrDoob's examples on his github page, specifically the interactive cubes example: http://mrdoob.github.com/three.js/examples/webgl_interactive_cubes.html

此外,应归功于:第 (1) 部分和 (3) 部分基于 MrDoob 在其 github 页面上的一些示例,特别是交互式立方体示例:http://mrdoob.github.com/three.js/examples/webgl_interactive_cubes .html