简体   繁体   English

threejs-显示2D图像

[英]threejs - Displaying a 2D image

Another threejs question. 另一个threejs问题。 I'm basically trying to get a 2D image display on the screen when I hit a key. 我基本上是想在按下键时在屏幕上显示2D图像。 I've searched around but I can't find a way to get my image to display properly and some methods I just can't get working at all. 我已经四处搜寻,但是找不到让图片正确显示的方法,而且有些方法根本无法使用。 Of the times I do manage to get an image showing, it either shows behind my 3d environment container (in html) or causes the entire 3D window to disappear even though the images aren't larger than it. 在我确实设法显示图像的时候,它要么显示在我的3d环境容器的后面(以html格式),要么即使图像不大于它,整个3D窗口也消失了。 I haven't really messed around with images so I'm not sure what I'd need. 我并没有真正弄乱图像,所以我不确定我需要什么。 I'm not trying to get an image display in 3D space, just an image to pop up on the screen, like a menu or something. 我不是要在3D空间中显示图像,而只是要在屏幕上弹出图像,例如菜单之类的东西。

You could also use a THREE.Sprite , very easy to implement and even if it gets created in a 3D space it always face the camera. 您还可以使用THREE.Sprite ,它非常易于实现,即使在3D空间中创建它,它也始终面向相机。

Here's a quick implementation example from the documentation : 这是文档中的一个快速实施示例:

var map = new THREE.TextureLoader().load( "sprite.png" );
var material = new THREE.SpriteMaterial( { map: map, color: 0xffffff } );
var sprite = new THREE.Sprite( material );
scene.add( sprite );

And remember to scale the sprite to match your image dimensions (in addition to setting camera.position.z to something high enough, of course): 记住记住缩放精灵以匹配您的图像尺寸(当然,除了将camera.position.z设置为足够高的值之外):

sprite.scale.set(imageWidth,imageHeight,1);

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

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