简体   繁体   English

Three.js:如何创建一个固定在场景中心的十字准线

[英]Three.js: How to create a crosshair that stay fixed at the center of the scene

I'm using video.js https://videojs.com/ and https://videojs-vr.netlify.app/ to play a VR video.我正在使用 video.js https://videojs.com/https://videojs-vr.netlify.app/播放 VR 视频。 Video.js with the help of videojsvr can do this. Video.js 在 videojsvr 的帮助下可以做到这一点。 Videojs-vr supports Three.js and can access three.js objects using this Videojs-vr 支持 Three.js 并且可以使用此访问 three.js 对象

var player = videojs('my-video');

player.vr().camera;
player.vr().scene;
player.vr().renderer;

I want to add a crosshair or any dot/circle in the middle of the video/scene that stay fixed even moving the screen within the 360 video.我想在视频/场景的中间添加一个十字准线或任何点/圆圈,即使在 360 度视频中移动屏幕也能保持固定。 How can I achieve that?我怎样才能做到这一点?

I have the following code我有以下代码

// Add crosshair
addCrosshair() {
    var self = this;
    var player = self.get('player');

    const cursor = new THREE.Mesh(
        new THREE.RingBufferGeometry(0.2, 0.08, 30),
        new THREE.MeshBasicMaterial({ color: "#FFFFFF", side: THREE.DoubleSide })
      );
      cursor.position.x = 0;
      cursor.position.y = 0;
      cursor.position.z = -8;

      player.vr().scene.add(player.vr().camera)
      player.vr().camera.add(cursor);
}

It seems to be doing what I need and the dot/small circle stays fixed in the center of the video/scene.它似乎正在做我需要的事情,并且点/小圆圈固定在视频/场景的中心。 However, it affects other three.js object I've placed in the video.但是,它会影响我放在视频中的其他 three.js object。 It messes up with the rendering of other objects.它与其他对象的渲染相混淆。 I've got a theory that it happens because I'm adding the cursor/dot in another camera and then add it to the scene.我有一个理论,它发生是因为我在另一个相机中添加光标/点,然后将它添加到场景中。

I've tried to do add it as another child of my other three.js objects.我试图将它添加为我的其他 three.js 对象的另一个子对象。 Although that seem to work too at first, if I move around the view within the 360 video, the cursor/dot doesn't stay fixed in the scene.虽然起初这似乎也有效,但如果我在 360 度视频中移动视图,光标/点不会在场景中保持固定。

Hopefully my question make sense.希望我的问题有意义。 If you don't have experience using videojs and video-vr.js, can you just help me to position a three.js object/crosshair at the center of the scene no matter where you move the camera view within the scene?如果您没有使用 videojs 和 video-vr.js 的经验,无论您在场景中将相机视图移动到何处,您都可以帮我在场景中心的 position 一个 three.js 对象/十字准线吗? Thank you so much in advance.非常感谢你。 Would be a big help to me.对我会有很大帮助。

I can't add a comment due to reputation, so I'll leave an answer.由于声誉问题,我无法添加评论,所以我会留下答案。

Have you thought about making the crosshair an HTML element?您是否考虑过将十字准线设为 HTML 元素? Either a PNG, p tag, h1 tag or a circle div. PNG、p 标签、h1 标签或圆形 div。

Make the elements position fixed in the center of your canvas and ensure that the elements z-index is greater then your canvas.将元素 position 固定在 canvas 的中心,并确保元素 z-index 大于 canvas。

Because the element is outside of your canvas, there will be no interference with objects within your scene.由于该元素位于 canvas 之外,因此不会干扰场景中的对象。

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

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