admin管理员组文章数量:1303427
I need to find out the bounding box of a geometry after applying rotations on it.
Code to rotate - taken from sample editor of Three JS
object.rotation.x = xRadians;
object.rotation.y = yRdians;
object.rotation.z = zRadians
This rotates the object just fine.
Now I need to get the updated bounding box
Code to get the bounding Box
var minX = parseFloat(object.boundingBox.min.x);
var minY = parseFloat(object.boundingBox.min.y);
var minZ = parseFloat(object.boundingBox.min.z);
I keep getting the same values in minX-Z no matter what the rotation is. What is the right way of getting the updated bounding box?
I am using r-66.
I also tried using:
var radians = x * Math.PI / 180;
var axisX = new THREE.Vector3(1, 0, 0);
var matrix = new THREE.Matrix4().makeRotationAxis(axisX, radians);
geometry.applyMatrix(matrix);
This method performs the relative rotation and also updates the bounding box correctly but I do not want relative rotation. The first approach is what I am looking for but that does not update the bounding box of the object.
Any ideas? Thanks!
I need to find out the bounding box of a geometry after applying rotations on it.
Code to rotate - taken from sample editor of Three JS
object.rotation.x = xRadians;
object.rotation.y = yRdians;
object.rotation.z = zRadians
This rotates the object just fine.
Now I need to get the updated bounding box
Code to get the bounding Box
var minX = parseFloat(object.boundingBox.min.x);
var minY = parseFloat(object.boundingBox.min.y);
var minZ = parseFloat(object.boundingBox.min.z);
I keep getting the same values in minX-Z no matter what the rotation is. What is the right way of getting the updated bounding box?
I am using r-66.
I also tried using:
var radians = x * Math.PI / 180;
var axisX = new THREE.Vector3(1, 0, 0);
var matrix = new THREE.Matrix4().makeRotationAxis(axisX, radians);
geometry.applyMatrix(matrix);
This method performs the relative rotation and also updates the bounding box correctly but I do not want relative rotation. The first approach is what I am looking for but that does not update the bounding box of the object.
Any ideas? Thanks!
Share Improve this question edited Mar 28, 2014 at 12:36 Tiny 27.9k112 gold badges351 silver badges607 bronze badges asked Mar 28, 2014 at 12:15 user3472487user3472487 831 silver badge4 bronze badges2 Answers
Reset to default 6Box3.setFromObject( object )
putes the world-axis-aligned bounding box of an object (including its children), accounting for both the object's, and childrens', world transforms.
var box = new THREE.Box3().setFromObject( object );
three.js r.66
var box = new THREE.Box3().setFromObject( object );
will return the world coordinates, so you need to subtract them from it:
var bbox = new THREE.Box3().setFromObject(object);
bbox.min.sub(object.position);
bbox.max.sub(object.position);
This will give you the correct bounding box relative to the object.
本文标签: javascriptThree JSBoundingBox not being updated after performing rotationsStack Overflow
版权声明:本文标题:javascript - Three JS - BoundingBox not being updated after performing rotations - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741753550a2395976.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论