Find Direction of Exterior Walls of GLTF Model

Hello, I loaded a gltf house model in threejs. The house has walls, what i want to know is what direction the exterior wall face is pointing. For example i have a 4 walled house, i want to know which direction the front of the house is facing. The walls that I have, they have a thickness. So there is one side of the wall towards the inside of the house, and the other is towards the exterior side. So how can i detect which direction the exterior of the wall is pointing?

-x, +x, -z, or +z. Is this possible?

I already posted a similar question, but i do not like the way i worded the question.

There are several ways, but it all depends on the model. I will start with 4 methods, other people may add the rest:

  • check whether the designer of the model has followed some rules that will help you, for example, if the house is designed so that the local X axis of each wall points outwards, then you can use it to find exterior direction
  • cast a ray from the center of the house towards the wall – the first hit point is internal, the second is external, the raycaster will give the normal vector and this is the direction – this will not work well if there are other objects on the wall that you cannot isolate
  • cast a ray but only check the first hit point, take its normal vector, flip it and you will have the external direction
  • take the tangent vector of the long side of the wall, rotate it horizontally 90° and check whether it points towards the center of the house or away of the center; of course, you only check just the sign of a dot product; +1 means external, -1 means internal

thank you, i want to try method 2 or 3, but how would this work with models like this?

It would not. They would work for 4-wall houses with X/Z orientations – this is what you described in your first message.

For a shape like the image, it might be better to use the odd-even algorithm. Pick a point in front of the wall (either inside or outside, you do not know yet). Cast a ray in any direction and count how many walls are intersected. Odd number of walls = the point is internal; even number of walls = the point is external.

Note that this algorithm would not work if there are holes in the walls. So, you should treat doors and windows are part of the walls.

Okay, I’m trying to understand this algorithm.
Let’s say we go back to the four walls. If I choose the left wall and the ray points to the right, it will detect the right wall. If the ray points left, it will detect the left wall. How can I use this information to determine the direction of the exterior?

And what if the ray points upward and detects the back wall? How can I use that information?

hold on i might have figured it out sorry, ill update what i figure out

I’ve figured it out, thanks to your guidance.

Here’s the approach I took: for each wall, I assigned four raycasters in the positive x, negative x, positive z, and negative z directions. When one of these raycasters detects the wall that generated it, I remove the other three raycasters. Afterward, I check how many other walls intersect with the active raycaster (excluding the wall that generated it). Then, I use the algorithm you explained to process the intersections.