Skip to content Skip to sidebar Skip to footer

Figuring Out How Much Of The Side Of A Cube Is Visible

I have a simple Three.js scene with a camera that orbits around a cube, always looking directly at it. I need to figure out the percentage of the side that is currently most visibl

Solution 1:

As another option, you could calculate the dot product of the camera's view vector and the cubes face normals, maybe? Then calculate the angle in degrees from the dot product and you know the angle of each face normal relative to the cameras view vector. I am not quite sure if this works, was just an idea. So everything above 90 degrees is not visible at all and 0 degrees is completely facing the camera. Well, not quite sure about the percentages but i don't know your use case. Just thought about saving the screenspace operations proposed by Gero3 somehow.... by only using the angles from the face normals. FOr example if you would be looking at the edge of the cube and have 2 faces in 45 degrees from the camera view direction, you know that you are 50% for each of the two faces?

Solution 2:

First calculate the position of the vertexes in screen space.

HOW TO:

var screenspaceVertexPosition = vertex.position.applyProjection(
    this.projectionMatrix.multiplyMatrices(object.matrixWorld))

Do this for all 8 vertexes. Then figure out which planes are visible by checking the planes normals. Calculate then the area used by each face in screenspace. From there you can calculate the complete visible area and the percentage.

Post a Comment for "Figuring Out How Much Of The Side Of A Cube Is Visible"