Three.js:缩放几何体后错误的 BoundingBox

编程入门 行业动态 更新时间:2024-10-25 14:30:17
本文介绍了Three.js:缩放几何体后错误的 BoundingBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在我的场景中,我有一个简单的立方体:

In my scene I have a simple cube:

var test = new THREE.Mesh(new THREE.CubeGeometry(10,10,10), new THREE.MeshBasicMaterial());
scene.add(test);

这个立方体通过THREE.TransformControls 被用户遍历/缩放.我需要的是这些交互后立方体的边界框.所以我在做

This cube is getting traversed/scaled through the user with THREE.TransformControls. What I need is the boundingbox of the cube after these interactions. So I'm doing

test.geometryputeBoundingBox();
var bb = test.geometry.boundingBox;
bb.translate(test.localToWorld( new THREE.Vector3()));

但我总是得到一个错误的边界框!翻译计算正确,但不是比例.boundingbox 的宽度和高度总是 10 ...

But I always get a wrong boundingbox! The translation is computed correct, but not the scale. The width and heigth of the boundingbox is always 10 ...

这是错误还是功能?如何获得立方体的正确边界框?

Is this a bug or feature? How do I get the correct boundingbox of my cube?

推荐答案

您可以像这样计算对象(包括其子对象)的世界轴对齐边界框:

You can compute the world-axis-aligned bounding box of an object (including its children) like so:

var box = new THREE.Box3();
box.setFromObject( object );

查看源代码,了解它在做什么.

Have a look at the source code so you understand what it is doing.

三个.js.r.60

这篇关于Three.js:缩放几何体后错误的 BoundingBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 15:26:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1396381.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:几何体   缩放   错误   js   BoundingBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!