三.js:制作边界框 [英] Three.js: making bounding box

查看:36
本文介绍了三.js:制作边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,我试图围绕点云制作边界框.为此,我计算了相反的顶点.

In my program, I am trying to make bounding box around a point cloud. I have calculated the opposite vertices for this purpose.

此处提供了 BoxGeomtery 的文档.但我无法理解构造函数.构造函数以宽度、高度、深度作为输入.但是盒子的位置呢.这个框将在场景中的哪个位置创建?我希望边界框由我拥有的两个顶点定义.

Here, documentation for BoxGeomtery is available. But I am not able to understand the constructor. Constructor takes width,height, depth as inputs. But what about location of the box. Where in the scene would this box be created?I want bounding box to be defined by two vertices I have.

var geometry = new THREE.Box3(mn,mx);
var material = new THREE.MeshBasicMaterial({color: 0xfffff, wireframe: true});
var bBox = new THREE.Mesh(geometry, material);
scene.add(bBox);

mn,mx 是盒子的顶点.上面的代码给出的错误为:

mn,mx are vertices of the box. Above code gives error as:

未捕获的类型错误:object.geometry.addEventListener 不是函数

Uncaught TypeError: object.geometry.addEventListener is not a function

推荐答案

BoxGeomtery 是一个几何生成器.您正在寻找的是 Box3three.js 的 AABB 实现.您可以使用 Box3.setFromObject 为 3D 对象生成边界框.

BoxGeomtery is a geometry generator. What you are looking for is Box3, three.js's AABB implementation. You can use Box3.setFromObject to generate a bounding box for a 3D object.

const aabb = new THREE.Box3().setFromObject( points );

然后您可以使用 Box3.getCenter 来检索中心盒子.

You can then use Box3.getCenter to retrieve the center of the box.

这篇关于三.js:制作边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆