简体   繁体   English

使用js获取3d模型的尺寸(大小)

[英]Get the dimensions(sizes) of a 3d model with js

I actually work on AR project with three.js and i handle some 3d models, but I have some problem with the sizes of the models. 我实际上使用Three.js处理AR项目,并处理了一些3D模型,但是模型的大小存在一些问题。 Because I want them to all have the same size, so I needed to set the same dimensions to all models. 因为我希望它们都具有相同的尺寸,所以我需要为所有模型设置相同的尺寸。 I first tried to solve this by using boundingbox and boundingsphere but it doesn't work. 我首先尝试通过使用boundingbox和boundingsphere解决此问题,但它不起作用。

So how can I get the sizes and how can I set the sizes ? 那么,如何获得尺寸以及如何设置尺寸呢?

var size = new THREE.Box3().setFromObject( yourObject ).getSize(new THREE.Vector3())

I need somethig else, because the code of manthrax is interesting but have some limits.. for exemple with this code: 我需要别的东西,因为手动编码很有趣,但是有一些限制..例如:

andy.scale.set(0.011, 0.011, 0.011);
                                andy.rotation.set(0, 0, 0);
                                andy.position.set(0,0,0);
                                var size = new THREE.Box3().setFromObject(andy).getSize(new THREE.Vector3())
                                console.log(size);

                                function moy(vect){
                                    return ((vect.x+vect.y+vect.z)/3);;
                                }

                                console.log(moy(size));

                                andy.scale.set(0.030, 0.030, 0.030);
                                console.log(moy(size));

If i want to change the value of "size" how can i do that ? 如果我想更改“大小”的值,该怎么办?

PS: andy is my 3d model PS:安迪是我的3D模型

I solve it, i create my own box3: 我解决了,我创建了自己的box3:

                        andy.scale.set(0.011, 0.011, 0.011);
                        andy.rotation.set(0, 0, 0);
                        andy.position.set(0,0,0);
                        var box3d = new THREE.Box3();
                        var size = box3d.setFromObject(andy).getSize(new THREE.Vector3())
                        console.log(size);

                        function moy(vect){
                            return ((vect.x+vect.y+vect.z)/3);;
                        }

                        console.log(moy(size));

                        andy.scale.set(0.030, 0.030, 0.030);
                        box3d.setFromObject(andy).getSize(size);
                        console.log(moy(size));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM