shaise / FreeCAD_FastenersWB

A workbench to add/attach various fasteners to parts
GNU General Public License v2.0
284 stars 86 forks source link

Thread crest missing after boolean cut (Part_Cut) a ISO 4017 Hex head screw head with a cube (Part_Box), with Refine=true #379

Open lmutt opened 5 months ago

lmutt commented 5 months ago

I'm trying to remove (cut) the head from a "ISO 4017 Hex head screw". To accomplish this, I do the following steps:

1) Using the Fasteners Workbench, I add the fastener, configure it to be M30, length custom (20 mm), and select "enable" from "thread" property (EDIT 4: I discovered later that diameter and length don't matter here). All ok, the fastener and its thread looks good -- see Fig1.

2) Then I create a cube (Part_Box) with Part Workbench, resize and position it to make it cover the entire head of the screw (the part I want to eliminate) -- see Fig2.

3) Then I select first the screw object, second the cube and click the cut icon (Part_Cut). (EDIT 4: also, set the property Refine=true for the Cut object). The screw is cut in the correct location, but the thread crest faces are now gone -- see Fig3. I'm sure that the cut object is really missing "pieces", because when I export it in STL and import it in OrcaSlicer, I see the same thing: I can see the other side through the slits. It is no longer a solid object. OrcaSlicer complains about this, reporting error 1087 (non-manifold edges).

I'm doing something wrong? Is this a Freecad bug? or a fasteners bug?

INFO: Freecad/fasteners information obtained from Help->About menu:

OS: Arch Linux (KDE/plasma)
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.37249 (Git) AppImage
Build type: Release
Branch: main
Hash: 3acbc561f299b4cddea8215c387a52f3d5132cf6
Python 3.11.9, Qt 5.15.13, Coin 4.0.2, Vtk 9.2.6, OCC 7.7.2
Locale: Portuguese/Brazil (pt_BR)
Installed mods: 
   * fasteners 0.5.20

EDIT 1.1: Source FCStd file (zipped): bug_test.zip

EDIT 1.2: Same figure of the step 3 but with the cube unhidden. Fig4


EDIT 4 (beginning):

(the text from EDIT 2 and 3 were eliminated to make this report a little more concise)

4.1) After thorough testing, I discovered that, contrary to what I stated previously, this bug occurs both in the stable version (0.21.2, which uses OCC 7.6.3) and in the weekly-builds (0.22.0dev.37249, which uses to OCC 7.7.2). The key for the bug to occur is the Cut object's property Refine=true.

4.1.1) Details: In the weekly-builds version, which I usually use, the option "Automatically refine model after boolean operation" was enabled (It's in the Edit->Preferences->Part/Part Design->General menu). This option makes the "Refine" property of the "Cut" object set to "true" by default. I had forgotten to mention that. Furthermore, always before running the stable version, I would make a backup of the ~/.config/FreeCAD/ directory and delete the original (to avoid possible configuration file compatibility issues between different versions of FreeCad). This meant that tests using the stable version were inadvertently done with the default settings ("Refine=false"), while those using the weekly-builds version were done with "Refine=true". This all led me to mistakenly state that this bug only manifested itself in the weekly-builds version. Sorry for the confusion.

4.2) I also did some tests by changing the type and diameter of the screw and also the cutting object:

4.3) I tested changing the "z" position of the cutting object. I found that, for the bug to occur, the cutting object needs to be above a certain point on the screw, apparently at the beginning of the thread (close to the head). Examples of points where this occurs: M8 Screw: z >= -0.37; M10 screw: z > -0.55 (examples considering a screw in the standard position, z=0).

4.4) As previously reported in this comment, it is possible to observe a strange artifact (a "stray face") on the pure screw (before cutting) located at the beginning of the thread. I found that it appears clearly on screws with a diameter >= M10 (ISO 4017 Hex type, I haven't tested other types). I have now also discovered that the "z" position of the cut object where the bug starts to occur coincides exactly with the "z" position of this artifact. I believe this is strong evidence that this bug is caused by this artifact. Is this artifact generated by a bug in Freecad or Fasteners?

4.5) Summary: For the bug to manifest itself, the two conditions below must occur: 1) The "Refine" property of the "Cut" object must be "true"; and 2) The cutting object needs to be positioned (z axis) above a certain point on the screw, apparently at the beginning of the thread, on the head side (this point is exactly where it is possible to see the "stray face" artifact).

EDIT 4 (end)

tobiasfalk commented 5 months ago

Could you give us a File and a picture similar to the first or third but with the green Box?

lmutt commented 5 months ago

Could you give us a File and a picture similar to the first or third but with the green Box?

For sure. I have updated my original message with the required information.

tobiasfalk commented 5 months ago

I can see your Problem in your file, but I am just not able to reproduce it from scratch, seem to me that this may be a DEV build problem, my guess is the OCC version since this was changed to a newer one and made some Problems. I do not think that this is a pure Fasteners WB problem, @shaise what do you think? @lmutt when the next Weekly Build and if the Problem still exists (from new Objects and cuts to prevent corrupted files) and report about it. I tried it with:

OS: Windows 10 build 19045
Word size of FreeCAD: 64-bit
Version: 0.21.2.33771 (Git)
Build type: Release
Branch: releases/FreeCAD-0-21
Hash: b9bfa5c5507506e4515816414cd27f4851d00489
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: German/Germany (de_DE)
Installed mods: 
  * DynamicData 2.60.0
  * fasteners 0.5.20
  * kicadStepUpMod 11.1.0

And with

OS: Windows 10 build 19045
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.37213 (Git)
Build type: Release
Branch: main
Hash: 20e7deb86a8c6c2cd2378f09f8313760933f3a5c
Python 3.11.9, Qt 5.15.13, Coin 4.0.2, Vtk 9.2.6, OCC 7.7.2
Locale: German/Germany (de_DE)
Installed mods: 
  * DynamicData 2.60.0
  * fasteners 0.5.20
  * kicadStepUpMod 11.1.0
shaise commented 5 months ago

Generating threads is notoriously problematic with OCC. Sometimes the generated fastener is not a perfect solid and this can cause issues when more solid manipulations are done. But this is not something that can be solved within Fasteners WB.

lmutt commented 5 months ago

Looking carefully at just the pure fastener, I found that artifact face, see: image

hasecilu commented 5 months ago

Could be related with #375 ?

tobiasfalk commented 5 months ago

But this is not something that can be solved within Fasteners WB.

@lmutt could you open a FreeCAD Issue and also link in it to this one.

lmutt commented 5 months ago

But this is not something that can be solved within Fasteners WB.

@lmutt could you open a FreeCAD Issue and also link in it to this one.

I did more careful testing and edited my original message (EDIT 4) with the details I found. I now believe that this can be easily reproduced by you.

I think that the artifact present in the screw ("stray face") directly generated by Fasteners is causing this bug, and in this case it would not be appropriate to report this bug in Freecad. Maybe it's better if I open another bug here reporting only the problem of the artifact present in the pure screw, and link it to this issue. What do you think?

shaise commented 5 months ago

What are the steps to get this stray face? I can not reproduce it. (though the missing crest is easily reproduced - without stray faces to start with)

lmutt commented 5 months ago

What are the steps to get this stray face? I can not reproduce it. (though the missing crest is easily reproduced - without stray faces to start with)

1) Select Fasteners Workbench 2) Add ISO 4017 hex head bolt 3) Select the above created screw. In Data tab, change the diameter property to at least M10 4) Set thread property to "true" 5) Rotate the 3d view (clicking in the navigation cube, in its vertice Right/Rear/Bottom). The stray face is visible at the starting of the thread (near the head). For M10 screw, the face is approximately in the position (x,y,z) = (3 mm, 4 mm, -0.55 mm) -- see figure below for its position.

image

tobiasfalk commented 5 months ago

Yes I did see the artifacts but for some reason did not report them or ignored the, I may have to.much focused on the problem you described. I will follow the steps you mentioned when I have access to a PC.

shaise commented 5 months ago

Still can't reproduce the stray face. However cutting still results with missing crest.

lmutt commented 5 months ago

Still can't reproduce the stray face. However cutting still results with missing crest.

Tested here again... with the latest Freecad weekly build available, and this time with a clean Freecad config:

rm -rf ~/.cache/FreeCAD/
mv ~/.config/FreeCAD/ ~/.config/FreeCAD.bak
mv .local/share/FreeCAD/ .local/share/FreeCAD.bak

Then starting the "brand new" Freecad and downloading again the fasteners WB.

The stray face are reproduced again easily. Just adding an ISO 4017 hex head bolt and setting it for the diameter M10, enabling threads, and pressing 5 on keyboard to see the bottom side. Please see attached screenshot with the stray face highlighted. Does this problem (stray face) appears just for me?

image

Version info:

OS: Arch Linux (KDE/plasma)
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.37358 (Git) AppImage
Build type: Release
Branch: main
Hash: 3a0152b076dd7791c9724c286963d74b5814e24f
Python 3.11.9, Qt 5.15.13, Coin 4.0.2, Vtk 9.2.6, OCC 7.7.2
Locale: Portuguese/Brazil (pt_BR)
Installed mods: 
  * fasteners 0.5.21