简体   繁体   English

单击覆盖场景中自定义几何体上的侦听器 - Autodesk forge 查看器

[英]Click listener on custom geometry in the overlay scene - Autodesk forge viewer

I have added a custom geometry on the 2D screen of forge viewer我在 Forge 查看器的 2D 屏幕上添加了自定义几何图形

     const geom = new THREE.SphereGeometry(10, 8, 8);
     const material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
     const sphereMesh = new THREE.Mesh(geom, material);
     sphereMesh.position.set(1, 2, 3);
     viewer.impl.createOverlayScene('custom-scene');
     viewer.impl.addOverlay('custom-scene', sphereMesh);
     viewer.impl.invalidate(true);

How do I add a click listener on the mesh of this overlay scene.如何在此叠加场景的网格上添加点击侦听器。

TL;TR: https://forge.autodesk.com/blog/handling-custom-meshes-selection-along-model-components-forge-viewer TL;TR: https://forge.autodesk.com/blog/handling-custom-meshes-selection-along-model-components-forge-viewer

Since Forge Viewer is based on three.js, when customizing the Viewer, you either rely on Viewer's API, or you can go deeper, use three.js API or even more deeper, WebGL. Since Forge Viewer is based on three.js, when customizing the Viewer, you either rely on Viewer's API, or you can go deeper, use three.js API or even more deeper, WebGL.

In your case, you created a custom geometry using three.js, which is lower level than the Viewer API, and you cannot expect that Viewer can interact with it.在您的情况下,您使用 three.js 创建了一个自定义几何图形,该几何图形低于查看器 API 的级别,并且您不能期望查看器可以与其交互。 Thus, since (by creating a three.js geometry) you are at three.js level, you'll have to rely on three.js API to handle the custom geometry selection.因此,由于(通过创建 three.js 几何)您处于 three.js 级别,您将不得不依赖 three.js ZDB974238714CA14 来处理自定义几何选择。38DE634A7CED 几何选择To achieve this, usually raycasting is used and there are lots of tutorials around it, some of them being:为了实现这一点,通常使用光线投射,并且有很多关于它的教程,其中一些是:

Those are generic ones and in one of the Forge blog posts there is an illustration of raycasting in context of Forge Viewer: https://forge.autodesk.com/blog/handling-custom-meshes-selection-along-model-components-forge-viewer这些是通用的,在 Forge 的一篇博客文章中,有一个 Forge Viewer 上下文中的光线投射说明: https://forge.autodesk.com/blog/handling-custom-meshes-selection-along-model-components-伪造查看器

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

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