[Fixed][Bug#4285] Bevel/Chamfer invert surface normal

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
fc_tofu
Posts: 653
Joined: Sun Jan 05, 2020 4:56 pm

Re: [Bug#4285] 0.19pre PartWB, Bevel/Chamfer command invert surface normal

Post by fc_tofu »

wandererfan wrote: Fri Jun 05, 2020 1:34 pm Let me know if you have any problems.
With the face number of benchmark cube as reference, I made a table of faces orientation.
fsc_2020-06-05_230946.jpg
fsc_2020-06-05_230946.jpg (63.91 KiB) Viewed 1090 times
It seems face orientation doesnot matter in valid solid.

Later I will look into edge orientation.

Thank you.
User avatar
wandererfan
Veteran
Posts: 6307
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Bug#4285] 0.19pre PartWB, Bevel/Chamfer command invert surface normal

Post by wandererfan »

fc_tofu wrote: Fri Jun 05, 2020 3:27 pm It seems face orientation doesnot matter in valid solid.
Not directly, no. Face orientation indicates whether the Face's normal points the same way as the underlying surface's normal or not. https://opencascade.blogspot.com/2009/02/continued.html

The first thing to check would be if all the face normals are pointing "out". That is the most correct configuration. All pointing in works for some things and not others. Some in and some out usually causes problems.
fc_tofu
Posts: 653
Joined: Sun Jan 05, 2020 4:56 pm

Re: [Bug#4285] 0.19pre PartWB, Bevel/Chamfer command invert surface normal

Post by fc_tofu »

wandererfan wrote: Fri Jun 05, 2020 6:39 pm The first thing to check would be if all the face normals are pointing "out".
The check results prove that all cubes face normal are pointing outside, in the above test.

I made a new test. I created cube "10_3DOffset" (3D Offest with positive value, 10mm*10mm*10mm) first, then made 3 derivations from "10_3DOffset" .
21_Rebuild: Downgrade to faces then Upgrade to solid
22_SimpleCopy: PartWB >Simple Copy
23_Reimport: Export as STEP then reimport
3doffset_compare_before.FCStd
(11.35 KiB) Downloaded 39 times
fsc_2020-06-06_143255b.jpg
fsc_2020-06-06_143255b.jpg (54.38 KiB) Viewed 1043 times
Above: red-marked cube will cause flip normal error in chamfer operation, and the other two cubes get no error in chamfer.
fsc_2020-06-06_143315.jpg
fsc_2020-06-06_143315.jpg (72.85 KiB) Viewed 1035 times
Above: chamfer operation (5mm width) on sample cubes

New test shows that, all sample cubes have same faces/wires/edges orientations.

So at last, your check tool helped exclude orientations from suspicion. The culprit is hidding at lower level.

A new find is, reimporting as BREP reproduces the bug, whereas reimporting as STEP fixes the bug.

Summary for bug scenarios,
1. scenarios where bug happens
1.1 3D offset with postive value
1.2 simple copy of 1.1 (also, transformed copy/element copy)
1.3 reimport 1.1 as BREP format

2. scenarios where no bug happens
2.1 3D offset with negative value
2.2 rebuild 1.1 with Downgrade and Upgrade
2.3 reimport 1.1 as STEP format
2.4 refine 1.1

I extracted .brp from .FCStd file, for other people could debug more easily.

ps.
OCCT BREP format official doc:
https://dev.opencascade.org/doc/overvie ... ep_wp.html
Attachments
2.1_negative_valid.brp
(8.35 KiB) Downloaded 43 times
1.1_positive_error.brp
(8.7 KiB) Downloaded 45 times
Last edited by fc_tofu on Mon Jun 08, 2020 4:17 am, edited 4 times in total.
fc_tofu
Posts: 653
Joined: Sun Jan 05, 2020 4:56 pm

Re: [Bug#4285] Bevel/Chamfer invert surface normal

Post by fc_tofu »

For now, I find a better (than rebuild/reimport) workaround for normal users, "PartWB >Refine shape" on defect solid before Bevel/Chamfer.
"Refine shape" is parametric operator, so it won't break existing parametric workflow.
(On the contrary, rebuild/reimport workaround break existing parametric workflow.)
In my tests, this workaround is valid for both 3D-Offset (positive) and Thickness (positive), for both Bevel and Chamfer.
fsc_2020-06-06_233734b.jpg
fsc_2020-06-06_233734b.jpg (67.67 KiB) Viewed 1011 times
For coders, I made sample models for comparison.
Befor refinement:
1.1_positive_error.brp
(8.7 KiB) Downloaded 37 times
After refinement:
2.4_positive_refined_valid.brp
(8.91 KiB) Downloaded 45 times
I still donnot know, wether the culprit is at 3D Offset/Thickness or at Bevel/Chamfer.

Possibly related sources:
https://github.com/FreeCAD/FreeCAD/blob ... Refine.cpp
https://github.com/FreeCAD/FreeCAD/blob ... setFix.cpp
https://github.com/FreeCAD/FreeCAD/blob ... Offset.cpp
https://github.com/FreeCAD/FreeCAD/blob ... atures.cpp
Attachments
3doffset_compare_refine.FCStd
(22.58 KiB) Downloaded 56 times
fc_tofu
Posts: 653
Joined: Sun Jan 05, 2020 4:56 pm

Re: [Bug#4285] Bevel/Chamfer invert surface normal

Post by fc_tofu »

PartWB Chamfer
https://github.com/FreeCAD/FreeCAD/blob ... hamfer.cpp

PartDesign Chamfer
https://github.com/FreeCAD/FreeCAD/blob ... hamfer.cpp

On same defect solid, PartWB Chamfer make invalid result, while PD Chamfer make valid result.
Who can tell the reason from their code?
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: [Bug#4285] Bevel/Chamfer invert surface normal

Post by ulrich1a »

I got a negative volume for those invalid parts.

Code: Select all

>>> App.ActiveDocument.Fillet.Shape.Volume
-499.5250740130765
Ulrich
fc_tofu
Posts: 653
Joined: Sun Jan 05, 2020 4:56 pm

Re: [Bug#4285] Bevel/Chamfer invert surface normal

Post by fc_tofu »

ulrich1a wrote: Sat Jun 06, 2020 7:33 pm I got a negative volume for those invalid parts.
Thank you, also Analyze tool find error in invalid Bevel/Chamfer,
fsc_2020-06-07_123649.jpg
fsc_2020-06-07_123649.jpg (48.89 KiB) Viewed 953 times
I'm curious what's wrong on Offset/Thickness shapes before Bevel/Chamfer.
User avatar
wandererfan
Veteran
Posts: 6307
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Ticket#4285] 0.19pre PartWB, Bevel/Chamfer command invert surface normal

Post by wandererfan »

fc_tofu wrote: Mon May 04, 2020 1:18 pm This is a severe bug, hope more coders pay attention to it. Thanks.
I've got it. Fix will be along shortly.

fix4285.png
fix4285.png (161.99 KiB) Viewed 926 times
fc_tofu
Posts: 653
Joined: Sun Jan 05, 2020 4:56 pm

Re: [Ticket#4285] 0.19pre PartWB, Bevel/Chamfer command invert surface normal

Post by fc_tofu »

wandererfan wrote: Sun Jun 07, 2020 3:42 pm I've got it. Fix will be along shortly.
Congratulations!

I diffed .brp files between invalid offset and its refinement. The geometry part is almost same. The shape part change a lot, I have no clue yet.
I have a concept. If the culprit can hardly be located, refine function could be appended to Offset/Thickness code as workaround.
User avatar
wandererfan
Veteran
Posts: 6307
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Bug#4285] Bevel/Chamfer invert surface normal

Post by wandererfan »

should be fixed by git commit 73f086f73d.
Post Reply