How does Three.JS calculate the center of a shape?

I set the position of a cylinder (CylinderGeometry(5, 1, 1, 5)) to (0,0,0) and it placed it at the following location (blue line intersection is (0,0,0))

Does ThreeJS sum the vertice vectors to find the shape’s center and move that to (0,0,0)? Does it calculate the bounding box and use that center?

1 Like

Depends on the geometry - you can find construction methods for basic geometries here (for example for circle.)

For built-in geometries, geometry is usually built around the origin - equally in all directions. You can check where the origin is at any point by simply adding a mock to the Mesh (it’ll appear by default in the local origin):

const origin = new Three.Mesh(new Three.BoxGeometry(0.01, 0.01, 0.01), new Three.MeshNormalMaterial());

model.add(origin); // NOTE cube will appear at (0,0,0)

Nope and nope. For basic geometries, vertices are just generated around (0,0,0) with math formulas. For more complex models - origin depends on the model. It can be the centre of gravity, it can be volumetric average, it can be center of the bounding box - but that depends only on you and how you implement it.