Skip to content

duplicate and corrupt faces #266

@MaschMaker

Description

@MaschMaker

Using:

  • Sketchup 2017 Make version 17.2.2555 64-bit
  • Windows 10 Pro version 1809 os build 17763.503

I'm importing svg paths into sketchup so the resulting faces are always 2D, z axis is 0.

I have found that there are some situations where sketchup creates extra faces and faces that you expect to merged, because they overlap each other in the same plane and in the same group, do not merge. The following code creates 4 faces that show the issues.

rectangle	= [Geom::Point3d.new( 0.mm, 0.mm, 0.mm), Geom::Point3d.new( 0.mm,20.mm, 0.mm), Geom::Point3d.new(40.mm,20.mm, 0.mm), Geom::Point3d.new(40.mm, 0.mm, 0.mm)]
triangle_b1	= [Geom::Point3d.new(20.mm, 5.mm, 0.mm), Geom::Point3d.new(15.mm,10.mm, 0.mm), Geom::Point3d.new(20.mm,15.mm, 0.mm)]
triangle_b2	= [Geom::Point3d.new(20.mm, 5.mm, 0.mm), Geom::Point3d.new(25.mm,10.mm, 0.mm), Geom::Point3d.new(20.mm,15.mm, 0.mm)]
diamond_c	= [Geom::Point3d.new(30.mm, 5.mm, 0.mm), Geom::Point3d.new(25.mm,10.mm, 0.mm), Geom::Point3d.new(30.mm,15.mm, 0.mm), Geom::Point3d.new(35.mm,10.mm, 0.mm)]

model = Sketchup.active_model
model.start_operation(op_name="api issue", disable_ui=true)

# ----------------------------------------------------

face_group = model.entities.add_group
face_group.name="api_issue"

rectangle_face 		= face_group.entities.add_face(rectangle);	rectangle_face.back_material = 'lightcyan';	rectangle_face.material = 'orange'

# rectangle_face.reverse!	if (!rectangle_face.normal.samedirection?(Z_AXIS))

triangle_b1_face	= face_group.entities.add_face(triangle_b1);	triangle_b1_face.back_material = 'green'
diamond_c_face		= face_group.entities.add_face(diamond_c);	diamond_c_face.back_material = 'red'
triangle_b2_face	= face_group.entities.add_face(triangle_b2);	triangle_b2_face.back_material = 'coral'

# ----------------------------------------------------

model.commit_operation

puts "face count = #{face_group.entities.grep(Sketchup::Face).length}"

face count = 5

api_issue1

There were only 4 calls to add_face() method but 5 faces were created.

These steps show that the red diamond did not merge with the rectangle and extra faces were created.

  1. Edit the group named "api_issue"
  2. Click once on the red diamond face, hit delete. Another face appears beneath it with bold edges.
  3. Click once (don't select the edges, just the face) on the same diamond with bold edges, hit delete. You should now see the rectangle and the edges from the diamond. This shows that the red diamond face never merged with the rectangle like the green and coral triangles did.
  4. Clicking on either the green or coral triangle face and pressing delete, punches a hole through the rectangle as expected. This is what I was expecting with the red diamond. I should be able to select it, delete it, and see a hole punched through the rectangle.

To see what I'm calling corruption, start over (delete the group and run the code again).

  1. Edit the group named "api_issue"
  2. Double click on the red diamond face. The face and all 4 of it's edges should be selected. Press delete key.
  3. Undo the erase.
  4. Click on the coral triangle. Instead of the coral triangle being selected, like you would expect, the red diamond is selected instead.

There are many other bizarre scenarios here, these are just a few. If the faces are created in a different order or uncommenting the line that reverses the rectangle face will make things work as expected. The faces are upside down because they are created on the ground plane.

Also, these problems only seem to occur when there are shared edges and the face that joins two other faces is created last (this is why, to show the issue, I created the coral triangle last, because it joins the green triangle and the red diamond together).

I have spent a lot of time trying to understand what is happening and also searching the web for others who might be having the same issues. I would find some hits referring to extra faces getting created but the root cause always seemed to be bad geometry. Clearly, my simple example of a rectangle, a diamond, and two triangles are not bad geometry.

The approach I have taken to work around these issues is to draw faces in the order they are connected. I've also started to avoid the add_face() method in favor of add_faces_from_mesh() and fill_from_mesh(). Although, I'm not sure they don't also result in the same issues.

If I create all the faces in the same group and then explode the group, the extra face merges but the face that was returned from the add_face() method is the one SketchUp chooses to make disappear. I verified this by collecting the persistent_id property of each face before exploding the group and then comparing the persistent_id of the faces that are in the resulting parent group.

Anybody have a better way to prevent these issues? I've finally figured out how to get the expected results but I'm having to check face counts to see if any extra faces get created and use temporary groups to isolate the issue and delete the extra faces before exploding the group.

Sorry for the long text, it was hard to condense and still show the issues I'm facing (pun intended)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions