bosskay972
bosskay972

Reputation: 993

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. 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.

So how can I get the sizes and how can I set the sizes ?

Upvotes: 1

Views: 524

Answers (2)

bosskay972
bosskay972

Reputation: 993

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

I solve it, i create my own 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));

Upvotes: 1

manthrax
manthrax

Reputation: 5016

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

Upvotes: 2

Related Questions