简体   繁体   English

three.js正交摄影机文字

[英]three.js orthographic camera text

I'm attempting to set up an orthographic camera on top of my regular camera to use as a heads up display. 我正在尝试在常规摄影机的顶部设置一个正交摄影机以用作平视显示器。 I can't seem to get any text to display, here is my code: 我似乎无法显示任何文本,这是我的代码:

function createHUD() 
{
var width = window.innerWidth;
var height = window.innerHeight;

cameraOrtho = new THREE.OrthographicCamera(-width/2, width/2,  height/2, -height/2, -10, 10);
cameraOrtho.position.z = 10;

sceneHUD = new THREE.Scene();

var textGeometry = new THREE.TextGeometry("hello world", {size: 20});
var textMaterial = new THREE.MeshBasicMaterial({color: 0xff0000});
var textMesh = new THREE.Mesh(textGeometry, textMaterial);
sceneHUD.add(textMesh);
}

function render()
{
renderer.render(scene, camera);
renderer.render(sceneHUD, cameraOrtho);
}

function init()
{
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x0088FF, 1);
renderer.autoClear = false;
document.body.appendChild(renderer.domElement);
createHUD();
camera.position.z += 5;
camera.position.y += 1;
...

Try to rotate the text 90° to the camera by using the lookAt function: 尝试使用lookAt函数将文本旋转90°到照相机:

   var textMesh = new THREE.Mesh(textGeometry, textMaterial);
   textMesh.lookAt(cameraOrtho.position); // Rotate the mesh so the face is fully visible by the camera
   sceneHUD.add(textMesh);

Also the ortographic camera worked best for me when I did not change its position, maybe try different positions and rotations. 当我不更改其位置(也许尝试不同的位置和旋转)时,正字相机也对我最有效。 You could also use orbit controls, so you can play with the values. 您还可以使用轨道控件,因此可以使用这些值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM