旋转相机时旋转文本以面对用户 [英] Rotate text to face user when camera is rotated
问题描述
如果你看看我的小提琴:
If you take a look at my fiddle:
http://jsfiddle.net/jmg157/Y35cQ/1/
你会看到我在立方体轴上有网格标签.我想要做的是每当用户围绕立方体旋转时,让文本也旋转,以便数字始终面向用户.
You'll see I have grid labels on the cube axes. What I'd like to do is whenever the user rotates around the cube, have the text rotate as well so that the numbers are always facing the user.
我尝试了诸如 xMarks.rotation = camera.rotation
之类的东西,其中 xMarks
是文本对象,但没有成功.任何建议将不胜感激.
I tried things like xMarks.rotation = camera.rotation
, where xMarks
are the text objects, but no success. Any suggestions would be greatly appreciated.
推荐答案
three.js 现在基于四元数.
three.js is now quaternion-based.
要使使用 THREE.PlaneGeometry
创建的文本面向相机,请执行以下操作:
To make the text created with THREE.PlaneGeometry
face the camera, do this:
mesh.quaternion = camera.quaternion; // EDIT - see note below
更新小提琴:http://jsfiddle.net/Y35cQ/2/
另一种方法是使用 THREE.Sprite
,它总是面向相机.
An alternative is to use THREE.Sprite
, which always faces the camera.
three.js r.63
three.js r.63
EDIT - mesh.quaternion = camera.quaternion;
不再有效.您必须改用此模式:
EDIT - mesh.quaternion = camera.quaternion;
no longer works. You must use this pattern instead:
mesh.quaternion.copy( camera.quaternion );
three.js r.67
three.js r.67
这篇关于旋转相机时旋转文本以面对用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!