Opening an .scad file its parts are put to the wrong coordinates on screen

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Opening an .scad file its parts are put to the wrong coordinates on screen

Post by keithsloan52 »

chennes wrote: Thu Apr 22, 2021 12:43 pm
keithsloan52 wrote: Thu Apr 22, 2021 7:27 am My thoughts are on the lines that there is a bug in the importer that is causing the Placement of the plane to be wrong i.e. at Base (0,0,0) rather than a correct value and hence not cutting correctly.
The way I tested it was to remove the final boolean operation from the tree, and try to do it "by hand" in FreeCAD. I get the same results. Something about some of those objects is rendering them "uncuttable".
What does 'Analyzes Geometry for errors' say?

Could be a case of saving as Brep file and checking with OSS tool (Sorry forget name)
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Opening an .scad file its parts are put to the wrong coordinates on screen

Post by keithsloan52 »

Okay Checking the Geometry I get
A57296B6-A096-478A-818F-B43DE68BF0B6.jpeg
A57296B6-A096-478A-818F-B43DE68BF0B6.jpeg (123.42 KiB) Viewed 1201 times
9FB4773F-1B46-47F8-B8EE-259BB1590AA6.jpeg
9FB4773F-1B46-47F8-B8EE-259BB1590AA6.jpeg (135.89 KiB) Viewed 1201 times
infocean
Posts: 17
Joined: Tue Nov 13, 2018 4:41 am

Re: Opening an .scad file its parts are put to the wrong coordinates on screen

Post by infocean »

There is a time out on this board, I composed an email and tried to get a screenshot and when I hit Submit, the whole went the the black hole of Calcutta. Bad board.

I think as the importer processes the Boolean operations it encounter a bug. That bug could be in the importer or in the processed file, I do not know yet. The consequence is that although during the import process other parts were processed right, the renderer in FreeCAD renders even those parts wrongly.

On the attached picture if I comment to a difference(0 function in the rotor(), the whole thing renders just fine. When I include I get the attached picture. Notice that nothing on the first shaft was rendered correctly, but the second shaft were done right. The code order is this:

// Draw shafts
color("CornflowerBlue")
shaft(slength1,sdiam,pshaft1,sdir);
color("CornflowerBlue")
shaft(slength2,sdiam,pshaft2,sdir);
// Draw the end closing in front of the compressor
color("Gray",0.8)
translate([pfrontendplate+0.5,0,0])
endclosings(swdiamo11/2,swthick11);
color("Maroon")
translate([pfrontendplate+0.15,0,0])
bearing();

// Draw the end closing behind the compressor
color("Gray",0.8)
translate([pendclosef,0,0])
endclosings(swdiamo11,swthick11);
color("Maroon")
translate([pendclosef-0.3,0,0])
bearing();

// Draw the first generator
translate([pgenerator1,0,0])
generator();
The shafts are processed separately from the generator(). However when the importer encounter the generator() and finds out that it cannot correctly render the two harray() and the one difference() call, it forgets about that it processed earlier correctly the parts on the first shaft, but still process the second shat right. Very strange.
Attachments
Screen Shot 2021-04-22 at 4.48.53 PM.png
Screen Shot 2021-04-22 at 4.48.53 PM.png (134.21 KiB) Viewed 1187 times
Last edited by infocean on Sat Apr 24, 2021 1:44 am, edited 1 time in total.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Opening an .scad file its parts are put to the wrong coordinates on screen

Post by Kunda1 »

please put code in bbcode code tags
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
infocean
Posts: 17
Joined: Tue Nov 13, 2018 4:41 am

Re: Opening an .scad file its parts are put to the wrong coordinates on screen

Post by infocean »

Chris,

Exporting as .stl from OpenSCAD is no help because FreeCAD see it as an empty shell and I cannot do 2D drawings from it. Or I might just do it wrongly, but I doubt it.

However, today I discovered that I made a mistake in OpenScad when I draw the pump cover. That I overlooked because the color difference was little. Instead of drawing an 1/2 thick wall I draw a 2.5 thick wall - going also into the pump's blades -, and that messed up the cover when I imported into FreeCAD. That is a different issue that it was also drawn in a totally different place. So, looks to me that if the parts are not drawn correctly in OpenSCAd, then although OpenSCAD does not complain, it causes great difficulties for FreeCAD.

Now I will go over my code with a fine tooth comb and import parts from OpenSCAd one by one, to see those difficulties. From the extra 2D objects after the today's import the big rectangle and the small rectangle disappeared. I have now just two concentric circles whose diameters the same as the pump cover diameter, so I guess I have some coding errors of mine there too.

Interestingly some parts of the shaft inside the displaced cover either show up or not depending what view I select. I attached a few screenshots for illustration.
So it is possible that the importer is working fine, if the .scad file is perfect, however it has some difficulties if the .scad file is not so perfect, and I hope this exercise help you to make an importer that is more aware of imperfect .scad files.
Thanks ahead,
Infocean
Attachments
Shaft is partially covered differently.
Shaft is partially covered differently.
Rear view.png (71.98 KiB) Viewed 1124 times
Shaft is partially covered.
Shaft is partially covered.
Front view.png (65.55 KiB) Viewed 1124 times
Shat is uncovered.
Shat is uncovered.
Bottom view.png (91.35 KiB) Viewed 1124 times
Shaft is covered.
Shaft is covered.
Top view.png (85.59 KiB) Viewed 1124 times
infocean
Posts: 17
Joined: Tue Nov 13, 2018 4:41 am

Re: Opening an .scad file its parts are put to the wrong coordinates on screen

Post by infocean »

Chris,

Well, the big rectangle disappeared only because I did not make a cross-section. As soon as I did one in OpenSCAd and imported into FreeCAD the rectangle was back.

It looks to me that the 2D concentric circles appear when I have this kind of construction:
translate()
rotate()
Linear_extrude()
or
translate()
rotate()
rotate_extrude()
See attached file.


When I do not have the translate() in these triumvirates, then FreeCAd works ok.
Thanks ahead,
Infocean
Attachments
pump_cover_only.scad
The two white circles caused by the two linear_extrude()
(1.56 KiB) Downloaded 25 times
infocean
Posts: 17
Joined: Tue Nov 13, 2018 4:41 am

Re: Opening an .scad file its parts are put to the wrong coordinates on screen

Post by infocean »

I forgot to mention in the previous message, that I found these red sentences in the Report window during one of the tests:

00:52:46 Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Volumes/Apps/CAD3D-programs/FreeCAD/FreeCAD.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 119, in open
processcsg(tmpfile)
File "/Volumes/Apps/CAD3D-programs/FreeCAD/FreeCAD.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 177, in processcsg
result = parser.parse(f.read())
File "/Volumes/Apps/CAD3D-programs/FreeCAD/FreeCAD.app/Contents/Resources/lib/python3.8/site-packages/ply/yacc.py", line 333, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/Volumes/Apps/CAD3D-programs/FreeCAD/FreeCAD.app/Contents/Resources/lib/python3.8/site-packages/ply/yacc.py", line 1120, in parseopt_notrack
p.callable(pslice)
File "/Volumes/Apps/CAD3D-programs/FreeCAD/FreeCAD.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 916, in p_multmatrix_action
parentcolor=p[6][0].ViewObject.ShapeColor
<class 'IndexError'>: list index out of range
01:02:36 ECHO: version = [2021, 1, 0]

I guess you never saw anything like these. :lol:
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Opening an .scad file its parts are put to the wrong coordinates on screen

Post by keithsloan52 »

infocean wrote: Mon Apr 26, 2021 6:25 am Chris,

Well, the big rectangle disappeared only because I did not make a cross-section. As soon as I did one in OpenSCAd and imported into FreeCAD the rectangle was back.

It looks to me that the 2D concentric circles appear when I have this kind of construction:
translate()
rotate()
Linear_extrude()
or
translate()
rotate()
rotate_extrude()
See attached file.


When I do not have the translate() in these triumvirates, then FreeCAd works ok.
Thanks ahead,
Infocean
infocean wrote: Mon Apr 26, 2021 6:35 am I forgot to mention in the previous message, that I found these red sentences in the Report window during one of the tests:

00:52:46 Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Volumes/Apps/CAD3D-programs/FreeCAD/FreeCAD.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 119, in open
processcsg(tmpfile)
File "/Volumes/Apps/CAD3D-programs/FreeCAD/FreeCAD.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 177, in processcsg
result = parser.parse(f.read())
File "/Volumes/Apps/CAD3D-programs/FreeCAD/FreeCAD.app/Contents/Resources/lib/python3.8/site-packages/ply/yacc.py", line 333, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/Volumes/Apps/CAD3D-programs/FreeCAD/FreeCAD.app/Contents/Resources/lib/python3.8/site-packages/ply/yacc.py", line 1120, in parseopt_notrack
p.callable(pslice)
File "/Volumes/Apps/CAD3D-programs/FreeCAD/FreeCAD.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 916, in p_multmatrix_action
parentcolor=p[6][0].ViewObject.ShapeColor
<class 'IndexError'>: list index out of range
01:02:36 ECHO: version = [2021, 1, 0]

I guess you never saw anything like these. :lol:
multmatrix operations will be as a result of translate and rotation operations, so your suspicions on translate/rotation problems are probably correct. Would also tie in with the cutting object placement being such that it only covers half of the object to. be cut.
infocean
Posts: 17
Joined: Tue Nov 13, 2018 4:41 am

Re: Opening an .scad file its parts are put to the wrong coordinates on screen

Post by infocean »

Hi Keith,

I also find these blue triangles and rectangles suspicious and awkward when I mouse over them. See attached. Can a meshing issue also add to the problem?
Thanks a lot,
Infocean
Attachments
Screen Shot 2021-04-26 at 11.58.18 AM.png
Screen Shot 2021-04-26 at 11.58.18 AM.png (201.88 KiB) Viewed 1076 times
Screen Shot 2021-04-26 at 11.55.19 AM.png
Screen Shot 2021-04-26 at 11.55.19 AM.png (273.83 KiB) Viewed 1076 times
Screen Shot 2021-04-26 at 11.55.10 AM.png
Screen Shot 2021-04-26 at 11.55.10 AM.png (273.28 KiB) Viewed 1076 times
infocean
Posts: 17
Joined: Tue Nov 13, 2018 4:41 am

Re: Opening an .scad file its parts are put to the wrong coordinates on screen

Post by infocean »

Hi,

Do you guys have any estimated time when a "good enough" solution for the problem will be available?
Thanks ahead,
Infocean
Post Reply