how to add Label to a THREE.Mesh?

后端 未结 1 1083
离开以前
离开以前 2020-12-14 12:56

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

Can someone give a sample code ?

1条回答
  •  旧巷少年郎
    2020-12-14 13:43

    Challenge accepted!

    Working code example at: 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

    (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

    (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

    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.

    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

    0 讨论(0)
提交回复
热议问题