Entities.add_face reverses the face if it aligns with the ground plane - how to override?

I’m using a custom importer and that uses entites.add_face to build my geometry which seems to work fine except for a special case where the face aligns with the x,y axis - and this is causing the normal direction of the face to be reveresed regardless of the order of the points being added. This was driving me crazy and then I noticed in the docs this is actually mentioned -

Note: A special case exists for any face created on the ground plane, in which case the vertex order is ignored and the face is always facing down.

Is there a way to override this? Or should I be using a different method to import my geometry. The format of this geometry is an array of vertex positions and then an array of the faces each of which is an array of indexes that relate to the vertex positions. So what i’m doing atm is essentially just looping though each face and drawing a face based on those relevant positions.

*I just noticed there’s a new EntitiesBuilder class in skp 2022, is this the way to go?

Thanks for any help you can give

It’s always been like that - by default any flat face at z==0 is created facing downwards even if the point-order would suggest otherwise…

It’s easily fixed in your code…
Collect your faces as you create them.
Any you get with
face.normal == [0,0,-1] && face.bounds.z == 0
you then use face.reverse! on them to flip them over…

2 Likes

Thanks for explaining the solution. I’ve just got it working with the new EntitiesBuilder which seems to have fixed it by just adding in the builder wrapper and seems to be quite a bit faster too!
Atm it just needs to work in the latest version but i guess I can add that in if I need it to be backwards compatible

1 Like

Which was the goal.

Within your module or class …

if defined?(::Sketchup::EntitiesBuilder)
  # Use the new paradigm
  def import(arglist)
    # uses EntitiesBuilder
  end
else
  # Use the slower old way
  def import(arglist)
    # uses Entities#add_face and reverses ground plane faces
  end
end

Using a conditional to choose how a method is defined at load time is faster than repeatedly deciding which paradigm to use at runtime.

2 Likes