适当使用三js box3()。getsize()方法是什么?

发布于 2025-01-20 08:56:39 字数 935 浏览 1 评论 0原文

stackoverflow 等人似乎都同意正确使用 Box3() getSize() 方法如下:

const geometry = new THREE.BoxGeometry( 10, 10, 10 );
const material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );

let cubeBoundingBox = new THREE.Box3().setFromObject( cube );
let boxSize = cubeBoundingBox.getSize();
console.log("BoxSize: " + boxSize);

然而事实似乎并非如此。请参阅此示例中的错误: https://jsfiddle.net/8L5dczmf/3/

我可以请参阅 Three.js 文档 getSize() 实际上应该这样使用...除非我正在阅读 .getSize ( target : Vector3 ) : Vector3错误地。那么上面小提琴中的代码有什么问题呢?

Everywhere on stackoverflow et al seem to agree that the proper use of the Box3() getSize() method is as follows:

const geometry = new THREE.BoxGeometry( 10, 10, 10 );
const material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );

let cubeBoundingBox = new THREE.Box3().setFromObject( cube );
let boxSize = cubeBoundingBox.getSize();
console.log("BoxSize: " + boxSize);

However this doesn't seem to be the case. See the error in this example: https://jsfiddle.net/8L5dczmf/3/

I can see in the three.js documentation that getSize() is in fact supposed to be used this way... unless I'm reading .getSize ( target : Vector3 ) : Vector3 incorrectly. What is wrong with the code in the fiddle above then?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴意少年 2025-01-27 08:56:39

您需要传入一个向量,结果将写入其中:

// ...

let boxSize = new THREE.Vector3();
cubeBoundingBox.getSize(boxSize);

console.log("BoxSize: " + boxSize);

这里的目的是您可以 池化您的 Vector3 对象,并以低廉的成本重复使用它们,而不会产生大量垃圾供 GC 清理。

You're expected to pass in a vector into which the result will be written:

// ...

let boxSize = new THREE.Vector3();
cubeBoundingBox.getSize(boxSize);

console.log("BoxSize: " + boxSize);

The intention here is that you can pool your Vector3 objects, and re-use them cheaply without making tons of garbage for the GC to clean up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文