简体   繁体   English

Forge Viewer-无法向场景添加线

[英]Forge Viewer - Can't add lines to scene

I am trying to add some lines into the scene of a 3D model in a Forge Viewer application I am building. 我正在尝试在正在构建的Forge Viewer应用程序中向3D模型的场景添加一些线条。 I want to draw some bounding boxes around certain objects; 我想在某些对象周围画一些边界框。 I have used the following guide as a baseline: 我已将以下指南用作基准:

Getting bounding boxes of each component in the viewer 在查看器中获取每个组件的边界框

At the moment I am just using the drawLines function as I already have the coordinate data for the object I want to draw a box around from elsewhere in my code. 目前,我只是在使用drawLines函数,因为我已经有了要在我的代码中的其他位置绘制框的对象的坐标数据。 However, when scene.add is called, the following error appears in console: 但是,当调用scene.add时,控制台中会出现以下错误:

WebGL: INVALID_OPERATION: drawArrays: no buffer is bound to enabled attribute

I have looked up this error and can't find anything that can help me. 我查了这个错误,找不到任何可以帮助我的东西。 It seems the issue may be due to the fact that my application already adds meshes to the scene, and when it goes to add lines, it uses the same shader, which does not have attributes set up correctly to deal with lines. 看来问题可能是由于我的应用程序已经在场景中添加了网格物体,并且在添加线时使用了相同的着色器,该着色器没有正确设置属性来处理线。 This is just a guess though, I really have no idea what exactly is causing the error, or what I can do differently to fix it. 不过,这只是一个猜测,我真的不知道是什么导致了错误,或者我可以采取其他措施来解决该错误。 I have tried various types of THREE.js objects, using sceneAfter, etc, but still cannot draw lines into the scene. 我已经使用sceneAfter等尝试了各种类型的THREE.js对象,但是仍然无法在场景中绘制线条。

You need to make a new Material like below. 您需要制作一个新的材质,如下所示。

var lineMaterial = new THREE.LineBasicMaterial ({
color: new THREE.Color (0xFF0000),
transparent: true,
depthWrite: false,
depthTest: true,
linewidth: 10,
opacity: 1.0
})

var lines = new THREE.Line (geometry,
lineMaterial)
scene.add (lines)

If you're calling the drawLines function directly, make sure to use the same material type as the tutorial: 如果直接调用drawLines函数,请确保使用与教程相同的材质类型:

let material = new THREE.LineBasicMaterial({ color: 0xffff00, linewidth: 2 });
viewer.impl.matman().addMaterial('MyLineMaterial', material, true);
drawLines([{x:0,y:0,z:0}, {x:10,y:10,z:10}], material);

Aha, managed to get it working! 啊哈,设法使其正常工作! To fix it I had to use createOverlayScene and addOverlay to add the line geometry to the scene instead of using scene.add, and had to remove matman().addMaterial. 要解决此问题,我必须使用createOverlayScene和addOverlay将线几何添加到场景中,而不是使用scene.add,并且必须删除matman()。addMaterial。

make a new scene try ---- just the codesorry for my bad english 尝试一个新场景---- 仅提供代码对不起,我的英语不好

  const geometry = new THREE.Geometry () geometry.vertices.push (new THREE.Vector3 ( 0, 0, 0)) geometry.vertices.push (new THREE.Vector3 (100, 100, 100)) var material = new THREE.LineBasicMaterial({ color: 0x0000ff, linewidth: 2 }); var lines = new THREE.Line (geometry, material) viewer.impl.scene.add (lines) 

You need to make sure that your scene can create lines. 您需要确保场景可以创建线条。

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

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