Three.js:有没有办法为组取边界框 [英] Three.js: Is there any way to take bounding box for group

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

问题描述

我可以为threejs中的组取边界框吗?我在three.js中有一个对象列表,我将它们全部分组在一个单元中.我想获得组的高度和宽度,所以我尝试使用 Box3 来确定高度和宽度.有没有办法在threejs中获取一组对象的高度和宽度

Can I take bounding box for the groups in threejs. I have a list of objects in three.js where I group them all in single unit. I want to get the height and width of the groups , So i tried to using Box3 to determine the height and width. Is there any way to get the height and width of the group of objects in threejs

var geometry = new THREE.BoxBufferGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );

var cubeA = new THREE.Mesh( geometry, material );
cubeA.position.set( 100, 100, 0 );

var cubeB = new THREE.Mesh( geometry, material );
cubeB.position.set( -100, -100, 0 );

//create a group and add the two cubes
//These cubes can now be rotated / scaled etc as a group
var group = new THREE.Group();
group.add( cubeA );
group.add( cubeB );

scene.add( group );

推荐答案

使用 Box3.setFromObject() 计算一组对象的 AABB.代码示例:

Use Box3.setFromObject() to compute the AABB for a group of objects. Code example:

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

three.js R118

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

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