geometry: .center() vs .computeBoundingBox

Hi,
For fonts created in ThreeJS, when I use .center() and it computes the bounding box automatically it is different than then I manually calculate it. This is an inconsistent result that is breaking my code where I have to display text in pixel perfect boxes. I need to handle vertical centered calculations differently so I cannot use .center() for all text, but now the x axis varies.

Steps to reproduce:

  1. Create a font geometry with .generateShapes() using any word.
  2. Center the geometry using .center() command.
  3. Display the bounding box in the console.
  4. Now repeat steps 1 & 2, but compute the bounding box manually using .computeBoundingBox() command.
  5. Display the bounding box in the console.

You will notice a difference after the decimal point on the x axis. Subtracting the boundingBox.max.x from the boundingBox.min.x and dividing it by two for step 4 does not give you the same center point as obtained from the .center command.

let a=new THREE.ShapeBufferGeometry(SomeFont.generateShapes('Testicle',30));
a.computeBoundingBox();
let b=a.clone().center();//or create it manually like a. It makes no difference.
console.log('a :',a.boundingBox);
console.log('b :',b.boundingBox);
console.log((a.boundingBox.max.x-a.boundingBox.min.x)/2.0);
/*The last line should log the same as b.boundingbox's x axis allready in
the console, but it is not resulting in text moving slightly horizontally.*/

Kind Regards
Jayson

  • Device: Desktop
  • OS: Windows
  • Browser: Firefox
  • Three.js version: r120

1 possible answer(s) on “geometry: .center() vs .computeBoundingBox

  1. Hi @Mugen87

    Thanks for the reply.

    I discovered the .getCenter() command shortly after my last reply and it has greatly improved my experience regarding this. It is good to see the .center() command also uses it. It keeps the math standard throughout.

    PS: I may very well have wasted your time on this, since I am still not so very sure if this is even a bug or just because I was trying to put a square peg in a round hole. I will probably run to the forum first next time as I should have done.

    Kind Regards

    Jayson