View Issue Details

IDProjectCategoryView StatusLast Update
0004353FreeCADBugpublic2021-03-28 11:00
Reporterlaughingrice Assigned Tochennes  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version0.18 
Target Version0.20Fixed in Version0.20 
Summary0004353: parameters of rotate_extrude in CSG files and openscad workbench are ignored
Descriptionimporting a CSG file with rotate_extrude, or using rotate_extrude in the add openscad element in the openscad workbench always uses default values ignoring set ones (true at least for angle and $fn)

It looks like freecad doesn't have an option matching $fn in the menus, but it does have support for angle, but that is ignored as well
Steps To ReproduceIn the openscad workbench press add openscad element and add the following. It should add a pyramid (works correctly if as mesh is ticked), but adds a cone instead

rotate_extrude($fn=4, angle=180) 
  polygon([[0,0],[3,3],[0,3]]);

Importing the matching CSG file results with the same effect, presumably, that is the intermediate format for communicating with openscad

rotate_extrude(angle = 180, convexity = 2, $fn = 4, $fa = 12, $fs = 2) {
        polygon(points = [[0, 0], [3, 3], [3, 0]], paths = undef, convexity = 1);
}
Tags#pending-PR, OpenSCAD
FreeCAD InformationOS: macOS 10.13
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16146 (Git)
Build type: Release
Branch: (HEAD detached at 0.18.4)
Hash: 980bf9060e28555fecd9e3462f68ca74007b70f8
Python version: 3.6.7
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)

Activities

laughingrice

2020-05-31 04:00

reporter  

Untitled1.csg (151 bytes)   
rotate_extrude(angle = 180, convexity = 2, $fn = 4, $fa = 12, $fs = 2) {
	polygon(points = [[0, 0], [3, 3], [3, 0]], paths = undef, convexity = 1);
}

Untitled1.csg (151 bytes)   

Kunda1

2020-06-05 14:19

administrator   ~0014470

Per guidelines, please open a forum thread first to let the community know. (post the link to the forum thread and post this ticket in the forum thread linking it back here)

keithsloan52

2021-02-26 20:07

developer   ~0015442

Try the following changes

590 def process_rotate_extrude(obj, angle):
605 myrev.Angle = angle
614 angle = float(p[3]['angle'])

keithsloan52

2021-02-26 20:12

developer   ~0015444

So rotate_extrude_action should look like

def p_rotate_extrude_action(p):
 612 'rotate_extrude_action : rotate_extrude LPAREN keywordargument_list RPA REN OBRACE block_list EBRACE'
 613 if printverbose: print("Rotate Extrude")
 614 angle = float(p[3]['angle'])
 615 if (len(p[6]) > 1) :
 616 part = fuse(p[6],"Rotate Extrude Union")
 617 else :
 618 part = p[6][0]
 619 p[0] = [process_rotate_extrude(part, angle)]
 620 if printverbose: print("End Rotate Extrude")

And process_rotate_extrude Should look like

def process_rotate_extrude(obj, angle):
 591 newobj=doc.addObject("Part::FeaturePython",'RefineRotateExtrude')
 592 RefineShape(newobj,obj)
 593 if gui:
 594 if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCA D").\
 595 GetBool('useViewProviderTree'):
 596 from OpenSCADFeatures import ViewProviderTree
 597 ViewProviderTree(newobj.ViewObject)
 598 else:
 599 newobj.ViewObject.Proxy = 0
 600 obj.ViewObject.hide()
 601 myrev = doc.addObject("Part::Revolution","RotateExtrude")
 602 myrev.Source = newobj
 603 myrev.Axis = (0.00,1.00,0.00)
 604 myrev.Base = (0.00,0.00,0.00)
 605 myrev.Angle = angle
 606 myrev.Placement=FreeCAD.Placement(FreeCAD.Vector(),FreeCAD.Rotation(0,0 ,90))
 607 if gui:
 608 newobj.ViewObject.hide()
 609 return(myrev)

Kunda1

2021-03-13 16:31

administrator   ~0015503

@chennes is this on your radar?

chennes

2021-03-13 17:17

administrator   ~0015504

It is now :) -- I'll implement @keithsloan52's fix and add a unit test.

chennes

2021-03-13 19:59

administrator   ~0015506

Update: that fix addresses the angle issue, but does not implement $fn, which will be a more complex fix.

keithsloan52

2021-03-13 21:31

developer   ~0015508

Last edited: 2021-03-13 21:32

$fn is optional, to quote the OpenSCAD documentation "$fn is optional and specifies the resolution of the linear_extrude (higher number brings more "smoothness", but more computation time is needed)."
It is all about creating a smooth a mesh. Now if the user has the workbench option 'maximum number of faces for polygons set to a sensible value, then any OpenSCAD circle, polygon with greater than setting should be imported as a circle so $fn should not matter.

chennes

2021-03-13 22:11

administrator   ~0015511

OpenSCAD users often use $fn to deliberately create non-smooth objects: in this particular bug report it seems that @laughingrice does indeed want a pyramid, and not half a cone. I am handling it the way we do in the cylinder code: if $fn is larger than the MAXFN value in the user's preferences we treat it as infinite, but if it's lower we treat it as though the user is deliberately creating a faceted surface.

keithsloan52

2021-03-13 22:47

developer   ~0015512

Last edited: 2021-03-13 22:52

Sorry don't follow, in that what is being extruded is on the stack, so should already be subject to the $fn for the operation that created it. Not sure that applying $fn to something that is already on the stack is a good idea. What is on the stack could have been created by a number of OpenSCAD operatives.

chennes

2021-03-13 23:14

administrator   ~0015513

I've attached an image of what OpenSCAD generates for this operation.
Example2.png (24,925 bytes)   
Example2.png (24,925 bytes)   

keithsloan52

2021-03-13 23:30

developer   ~0015514

So the issue is with a low value of $fn not a high value.

chennes

2021-03-13 23:33

administrator   ~0015515

Right - I am following the example of the logic found in the cylinder code:

    n = int(round(float(p[3]['$fn'])))
    fnmax = FreeCAD.ParamGet(\
        "User parameter:BaseApp/Preferences/Mod/OpenSCAD").\
        GetInt('useMaxFN', 16)
[...]
            if n < 3 or fnmax != 0 and n > fnmax:
                mycyl=doc.addObject("Part::Cylinder",p[1])
                mycyl.Height = h
                mycyl.Radius = r1
            else :
                if printverbose: print("Make Prism")
So if the input fn is high, it's doing the normal surface of revolution. But if it's low, it creates a more prismatic shape.

keithsloan52

2021-03-13 23:42

developer   ~0015516

Last edited: 2021-03-13 23:42

I see

rotate_extrude($fn=6, angle=360) 
  polygon([[0,0],[3,3],[0,3]]);
  
Produces attached image

So the $fn is determining the base of object and what is on the stack the sides.

Was not aware that was what it was doing.
image.png (15,048 bytes)   
image.png (15,048 bytes)   

keithsloan52

2021-03-14 11:45

developer   ~0015517

Will teach me to read the manual rather than make assumptions, thought it was like extrude with an angle, rather than rotate about the z axis.
Tried
rotate_extrude($fn=4, angle=180) 
translate([10,0,0])
  circle(10);

And get the result as per picture.

The problem I see is that when the rotate_extrude gets to be executed, what is to be rotated round the z axis is on the stack. (Being on the stack is a result of CSG being a script type language that has to be parsed.) Now with a low $fn, the $fn needs to be applied to things on the stack i.e. retrospectively and what is on the stack could in general be quite complicated, there is no rule that says it has to be one simple shape.
Image 14-03-2021 at 11.34.jpeg (39,634 bytes)   
Image 14-03-2021 at 11.34.jpeg (39,634 bytes)   

keithsloan52

2021-03-14 12:09

developer   ~0015518

Last edited: 2021-03-14 13:31

Forget what I am saying, the problem is not what on the stack it, it if a low $fn value is specified one has to use something other than a Part::Revolution to get the end result.
Part::Revolution works when one want to make a smooth rotation. Have to code polygon once as per shape on stack and then at $fn * angle / 360 degrees with a cross section as per shape on the stack.

keithsloan52

2021-03-14 13:25

developer   ~0015519

Last edited: 2021-03-14 13:27

Another thing to watch for is there is a rotate_extrude_file see def p_rotate_extrude_file(p):
    'rotate_extrude_file : rotate_extrude LPAREN keywordargument_list RPAREN SEMICOL'

It currently calls process_rotate_extrude(obj) so would barf as the definition for process_rotate_extrude does not set angle as a default.
I would have to check if passing a file also allowed an angle to be specified.

chennes

2021-03-14 17:45

administrator   ~0015520

I've got the "prism" (for lack of a better term) code working fine and matching OpenSCAD if the shape being extruded does not contact the axis of rotation. I am using makeRuled() to connect the ribs that are created by revolving the original 2D shape. In the OP's bug report, though, that triangle has a line along the axis of rotation, so I can't use makeRuled() to create the surface we need. If you have any suggestions for how to connect the edges together I am all ears! I posted about it here: https://forum.freecadweb.org/viewtopic.php?f=3&t=56631

keithsloan52

2021-03-14 18:06

developer   ~0015521

GDML has a much richer set of Solid Graphics than FreeCAD, you might checkout out https://geant4-userdoc.web.cern.ch/UsersGuides/ForApplicationDeveloper/html/Detector/Geometry/geomSolids.html

If you find anything that is similar or matches the bill. Look at GDMLObjects.py in repro https://github.com/KeithSloan/GDML
Then look for the def createGeometry which draws the said Shape

I am thinking on the lines of Polyhedra or makeFrustrum function.

chennes

2021-03-17 19:38

administrator   ~0015529

PR: https://github.com/FreeCAD/FreeCAD/pull/4629

wmayer

2021-03-28 10:48

administrator   ~0015563

https://github.com/FreeCAD/FreeCAD/commit/4e58747c16c5f05814d540f93fee16e128c1ed67
https://github.com/FreeCAD/FreeCAD/commit/dfd683d46451b2a2e00bf2f9a5efff814613764c

Related Changesets

FreeCAD: master 4e58747c

2021-03-15 00:12:51

chennes


Committer: wmayer Details Diff
[OpenSCAD] Add $fn and angle to rotate_extrude()

As pointed out in Issue 0004353 the OpenSCAD Workbench does not
correctly implement the angle parameter to rotate_extrude (it's a
relatively recent addition to OpenSCAD), nor does it attempt to do
anything with a specified $fn. This commit adds both features. To add
$fn handling, the code from the cylinder extrusion was mimicked,
allowing FreeCAD to create perfect, smooth representations when $fn
exceeds a user specified value in Preferences, but attempting to create
OpenSCAD's more discrete representation when using a lower $fn. Note
that this determination is made at creation time: if the user later
increases the segments parameter in the new object, it will remain
prismatic regardless of how high the value is made.
Affected Issues
0004353
mod - src/Mod/OpenSCAD/OpenSCADFeatures.py Diff File
mod - src/Mod/OpenSCAD/OpenSCADTest/app/test_importCSG.py Diff File
mod - src/Mod/OpenSCAD/importCSG.py Diff File

Issue History

Date Modified Username Field Change
2020-05-31 04:00 laughingrice New Issue
2020-05-31 04:00 laughingrice File Added: Untitled1.csg
2020-06-05 14:18 Kunda1 Tag Attached: #post-to-forum
2020-06-05 14:19 Kunda1 Status new => feedback
2020-06-05 14:19 Kunda1 Note Added: 0014470
2021-02-06 06:49 abdullah Target Version => 0.20
2021-02-26 20:07 keithsloan52 Note Added: 0015442
2021-02-26 20:12 keithsloan52 Note Added: 0015444
2021-03-13 16:31 Kunda1 Note Added: 0015503
2021-03-13 16:33 Kunda1 Tag Attached: OpenSCAD
2021-03-13 17:17 chennes Note Added: 0015504
2021-03-13 17:17 chennes Assigned To => chennes
2021-03-13 17:17 chennes Status feedback => assigned
2021-03-13 17:34 Kunda1 Steps to Reproduce Updated
2021-03-13 17:35 Kunda1 Tag Detached: #post-to-forum
2021-03-13 17:35 Kunda1 Tag Attached: #pending-PR
2021-03-13 19:59 chennes Note Added: 0015506
2021-03-13 21:31 keithsloan52 Note Added: 0015508
2021-03-13 21:32 keithsloan52 Note Edited: 0015508
2021-03-13 21:32 keithsloan52 Note Edited: 0015508
2021-03-13 21:32 keithsloan52 Note Edited: 0015508
2021-03-13 22:11 chennes Note Added: 0015511
2021-03-13 22:47 keithsloan52 Note Added: 0015512
2021-03-13 22:51 keithsloan52 Note Edited: 0015512
2021-03-13 22:52 keithsloan52 Note Edited: 0015512
2021-03-13 23:14 chennes Note Added: 0015513
2021-03-13 23:14 chennes File Added: Example2.png
2021-03-13 23:30 keithsloan52 Note Added: 0015514
2021-03-13 23:33 chennes Note Added: 0015515
2021-03-13 23:42 keithsloan52 Note Added: 0015516
2021-03-13 23:42 keithsloan52 File Added: image.png
2021-03-13 23:42 keithsloan52 Note Edited: 0015516
2021-03-14 11:45 keithsloan52 Note Added: 0015517
2021-03-14 11:45 keithsloan52 File Added: Image 14-03-2021 at 11.34.jpeg
2021-03-14 12:09 keithsloan52 Note Added: 0015518
2021-03-14 13:25 keithsloan52 Note Added: 0015519
2021-03-14 13:27 keithsloan52 Note Edited: 0015519
2021-03-14 13:31 keithsloan52 Note Edited: 0015518
2021-03-14 17:45 chennes Note Added: 0015520
2021-03-14 18:06 keithsloan52 Note Added: 0015521
2021-03-17 19:38 chennes Note Added: 0015529
2021-03-28 10:48 wmayer Status assigned => closed
2021-03-28 10:48 wmayer Resolution open => fixed
2021-03-28 10:48 wmayer Fixed in Version => 0.20
2021-03-28 10:48 wmayer Note Added: 0015563
2021-03-28 11:00 wmayer Changeset attached => FreeCAD master 4e58747c