Import CSG files from OpenSCAD.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Veteran
- Posts: 2753
- Joined: Mon Feb 27, 2012 5:31 pm
Import CSG files from OpenSCAD.
I have started work on importing CSG files from OpenSCAD. I see that the DXF importer has a DXF parser and the SVG importer uses an XML parser. Any suggestions on a parser for CSG files or is it a case of write one oneself. I don't want to reinvent the wheel so open to suggestions before I start.
A typical CSG file being
group() {
group() {
difference() {
sphere($fn = 0, $fa = 12, $fs = 2, r = 25);
group() {
multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
cylinder($fn = 0, $fa = 12, $fs = 2, h = 62.5, r1 = 12.5, r2 = 12.5, center = true);
}
}
group() {
multmatrix([[1, 0, 0, 0], [0, 6.12303e-017, -1, 0], [0, 1, 6.12303e-017, 0], [0, 0, 0, 1]]) {
cylinder($fn = 0, $fa = 12, $fs = 2, h = 62.5, r1 = 12.5, r2 = 12.5, center = true);
}
}
group() {
multmatrix([[6.12303e-017, 0, 1, 0], [0, 1, 0, 0], [-1, 0, 6.12303e-017, 0], [0, 0, 0, 1]]) {
cylinder($fn = 0, $fa = 12, $fs = 2, h = 62.5, r1 = 12.5, r2 = 12.5, center = true);
}
}
}
}
}
A typical CSG file being
group() {
group() {
difference() {
sphere($fn = 0, $fa = 12, $fs = 2, r = 25);
group() {
multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) {
cylinder($fn = 0, $fa = 12, $fs = 2, h = 62.5, r1 = 12.5, r2 = 12.5, center = true);
}
}
group() {
multmatrix([[1, 0, 0, 0], [0, 6.12303e-017, -1, 0], [0, 1, 6.12303e-017, 0], [0, 0, 0, 1]]) {
cylinder($fn = 0, $fa = 12, $fs = 2, h = 62.5, r1 = 12.5, r2 = 12.5, center = true);
}
}
group() {
multmatrix([[6.12303e-017, 0, 1, 0], [0, 1, 0, 0], [-1, 0, 6.12303e-017, 0], [0, 0, 0, 1]]) {
cylinder($fn = 0, $fa = 12, $fs = 2, h = 62.5, r1 = 12.5, r2 = 12.5, center = true);
}
}
}
}
}
Re: Import CSG files from OpenSCAD.
How does the structure of a CSG file look like?
-
- Veteran
- Posts: 2753
- Joined: Mon Feb 27, 2012 5:31 pm
Re: Import CSG files from OpenSCAD.
I edited the original post to include an example
-
- Veteran
- Posts: 2753
- Joined: Mon Feb 27, 2012 5:31 pm
Re: Import CSG files from OpenSCAD.
Thats the OpenSCAD language. I am going to try and import CSG file which is not the same thing.shoogen wrote:http://en.wikibooks.org/wiki/OpenSCAD_U ... D_Language
I am also looking for something to help parse the CSG without having to write from scratch.
Re: Import CSG files from OpenSCAD.
I'm sorry I don't see the difference.keithsloan52 wrote: Thats the OpenSCAD language. I am going to try and import CSG file which is not the same thing.
-
- Veteran
- Posts: 2753
- Joined: Mon Feb 27, 2012 5:31 pm
Re: Import CSG files from OpenSCAD.
Try installing OpenSCAD then open a scad file and then export the same file to a CSG file. Do this for the exampleshoogen wrote:I'm sorry I don't see the difference.keithsloan52 wrote: Thats the OpenSCAD language. I am going to try and import CSG file which is not the same thing.
files for instance. I think for very simple stuff it might be the same.
The scad file is written in the OpenSCAD language. The CSG file is different it does not contain functions and loads
of language stuff. It just enough to define the objects as combinations of primitive 3d objects. Hopefully a lesser
task than having to deal with the whole language.
-
- Veteran
- Posts: 2753
- Joined: Mon Feb 27, 2012 5:31 pm
Re: Import CSG files from OpenSCAD.
I just did a test and exported one of the examples as a CSG file. Sure enough it is different from the original.
But if I change the file extension to scad. It will load as a SCAD file and produce the same result.
So I think it fair to say CSG is a subset without some of the language features like functions etc
But if I change the file extension to scad. It will load as a SCAD file and produce the same result.
So I think it fair to say CSG is a subset without some of the language features like functions etc
-
- Veteran
- Posts: 2753
- Joined: Mon Feb 27, 2012 5:31 pm
Re: Import CSG files from OpenSCAD.
Found this web page on various parsers for python http://wiki.python.org/moin/LanguageParsing
Any suggestions for one that might be suitable for passing the CSG files?
Any suggestions for one that might be suitable for passing the CSG files?
Re: Import CSG files from OpenSCAD.
it seems to bee a dump of thier in memory tree structure. As there is practicaly no documentaion on this subset, we might have to get through every 'toString()' Method in OpenSCAD.keithsloan52 wrote:So I think it fair to say CSG is a subset without some of the language features like functions etc
- cgaladv.cc
color.cc
csgops.cc
expr.cc
import.cc
linearextrude.cc
node.cc
node.cc
primitives.cc
projection.cc
render.cc
rotateextrude.cc
surface.cc
transform.cc
value.cc
Last edited by shoogen on Wed Feb 29, 2012 7:09 am, edited 1 time in total.