最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Find object dimensions in three.js - Stack Overflow

programmeradmin1浏览0评论

Short question. How does one find the dimensions of a mesh in three.js?

I have Collada (.dae) files which I would like to know the size of in units (x,y,z). I have seen comments about using geometryputeBoundingBox(), but I am still not exactly sure how to use it.

Also I am aware of using scale but my ultimate goal is to compare objects in the scene with realistic measurements (mm) so it helps to know the exact physical dimensions of an object so that I may change it if necessary.

Appreciate any words of wisdom :^)

Short question. How does one find the dimensions of a mesh in three.js?

I have Collada (.dae) files which I would like to know the size of in units (x,y,z). I have seen comments about using geometry.computeBoundingBox(), but I am still not exactly sure how to use it.

Also I am aware of using scale but my ultimate goal is to compare objects in the scene with realistic measurements (mm) so it helps to know the exact physical dimensions of an object so that I may change it if necessary.

Appreciate any words of wisdom :^)

Share Improve this question asked Jan 2, 2018 at 14:32 Jonathan DrummondJonathan Drummond 1451 gold badge1 silver badge10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 19

Using a bounding box sounds like a good idea. You can try something like this

    boundingBox = new THREE.Box3().setFromObject(your_object)
    size = boundingBox.getSize() // Returns Vector3

Docs:

  • Box3: https://threejs.org/docs/#api/math/Box3
  • Vector3: https://threejs.org/docs/#api/math/Vector3

Comment update: Now that I have the object dimensions X,Y,Z, how can I change the value of let's say 'X' and have the object scale to it?

scaleFactor = otherSize.x / mySize.x 
myObject.scale(scaleFactor, scaleFactor, scaleFactor)
发布评论

评论列表(0)

  1. 暂无评论