ARB6 (triangular prism): 6 vertices, 5 faces (2 triangles + 3 quads).
Identifies opposing triangle faces and pairs vertices via shared
side quads.
ARB7 (arb8 with one collapsed corner): 7 vertices, 6 faces
(2 triangles + 4 quads). Finds the bottom quad, identifies top
vertices, and pairs via face adjacency.
Previously these fell through to BOT.
ID_PARTICLE: exported as hull() of two spheres at endpoints.
ID_PIPE: exported as union of cylinders for straight segments
with spheres at joints for smooth connections.
ID_REVOLVE: exported as rotate_extrude(polygon()) by reading
the referenced sketch's vertices and line segments.
csg-g: import(file="foo.stl") now reads the referenced STL file
relative to the .csg file's directory and inlines it as a BOT.
Also adds render() as a pass-through wrapper.
g-scad: ID_HALF (halfspace) is exported as a 2e10mm cube positioned
on the correct side of the plane via multmatrix. Not mathematically
exact but sufficient for any practical CSG subtraction.
ft_tessellate can corrupt the rt_db_internal structure, causing
heap corruption when rt_db_free_internal runs later. Fix by
re-reading the primitive from the database for a fresh copy
before tessellating.
Note: EHY tessellation (rt_ehy_tess) has a pre-existing heap
corruption bug in BRL-CAD itself — not addressed here.
csg-g: linear_extrude(polygon()) creates a BRL-CAD sketch from the
polygon vertices/paths, then extrudes it with mk_extrusion. Also
handles rotate_extrude(circle()) as torus and linear_extrude with
circle/square children as cylinder/box.
g-scad: ID_EXTRUDE primitives are exported as linear_extrude(polygon())
by reading the referenced sketch's vertices and line segments.
ID_SKETCH primitives encountered standalone are silently skipped.
rotate_extrude(circle()) maps to mk_tor (torus). This recovers all
1145 previously-skipped solids across the test suite.
linear_extrude(square()) maps to mk_rpp (box).
linear_extrude(circle()) maps to mk_tgc (cylinder/cone).
Unsupported extrude children (polygon, etc.) warn and skip.
Walks the CSG tree preserving boolean structure (union, difference,
intersection), transformation matrices, and primitive geometry.
Direct mappings: SPH/ELL to sphere(), TGC/REC to cylinder(), ARB to
polyhedron(), BOT to polyhedron(), TOR to rotate_extrude(circle()).
Unsupported primitives are tessellated via ft_tessellate/nmg_bot.
Combination colors are emitted as color() wrappers.
Non-convex polyhedra go straight to BOT since ARB primitives require
convexity for correct ray tracing. The check verifies that for each
face, all other vertices lie on the same side of the face plane.
Tetrahedra (arb4) skip the check since they are always convex.
Parse OpenSCAD polyhedron() nodes, attempting to match ARB primitives
before falling back to BOT (bag of triangles). Detection order:
arb8 (8 verts, 6 quad faces), arb5 (5 verts, quad base + apex),
arb4 (4 verts, 4 tri faces). Non-matching polyhedra are
fan-triangulated into BOT solids.
Import OpenSCAD's evaluated CSG tree format (.csg) into BRL-CAD .g
files. The .csg format is produced by: openscad -o file.csg input.scad
Supports cube, sphere, cylinder primitives, boolean operations
(difference, union, intersection, group), multmatrix transforms,
and color nodes. Warns and skips unsupported nodes (linear_extrude,
rotate_extrude, hull, minkowski).
2026-04-08 09:12:43 -04:00
6 changed files with 4004 additions and 0 deletions
*csg-g* converts an OpenSCAD evaluated CSG file (_file.csg_) to a BRL-CAD _file.g_ file. The CSG format is produced by running `openscad -o file.csg input.scad` and contains the fully evaluated CSG tree with all variables, modules, and loops resolved.
The converter preserves CSG structure, mapping OpenSCAD primitives and boolean operations directly to BRL-CAD equivalents rather than tessellating to mesh. Supported primitives include cube (RPP), sphere (SPH), cylinder (TGC), polyhedron (ARB or BOT), torus via rotate_extrude of circle (TOR), and extrusions of square, circle, and polygon profiles (RPP, TGC, or sketch+extrusion). Boolean operations (difference, union, intersection, group) and transformation matrices (multmatrix) are preserved. Colors are stored as object attributes. The `import()` node reads and inlines referenced STL files as BOT primitives.
Polyhedra are matched against ARB4, ARB5, and ARB8 when the vertex and face counts match and the shape is convex. Non-convex polyhedra and unmatched shapes fall back to BOT (bag of triangles).
The *-d* option prints debugging information during conversion.
[[example]]
== EXAMPLE
----
$ openscad -o model.csg model.scad
$ csg-g model.csg model.g
----
[[see_also]]
== SEE ALSO
*g-scad*(1), *stl-g*(1), *openscad*(1)
[[author]]
== AUTHOR
BRL-CAD Team
[[copyright]]
== COPYRIGHT
This software is Copyright (c) 2025 by the United States Government as represented by U.S. Army Research Laboratory.
[[bug_reports]]
== BUG REPORTS
Reports of bugs or problems should be submitted via electronic mail to devs@brlcad.org
g-scad - BRL-CAD to OpenSCAD Translator (BRL-CAD to SCAD)
== SYNOPSIS
[source]
----
g-scad [-d] [-o output.scad] file.g object(s)
----
[[description]]
== DESCRIPTION
*g-scad* converts the specified BRL-CAD objects from _file.g_ to OpenSCAD format. The output preserves CSG structure, mapping BRL-CAD boolean operations and primitives directly to OpenSCAD equivalents rather than tessellating everything to polyhedron.
Direct primitive mappings: SPH and ELL to sphere(), TGC and REC to cylinder(), ARB to polyhedron(), BOT to polyhedron(), TOR to rotate_extrude(circle()), PARTICLE to hull() of two spheres, PIPE to union of cylinders and spheres, EXTRUDE to linear_extrude(polygon()), REVOLVE to rotate_extrude(polygon()), and HALF to a large translated cube. Combination colors are emitted as color() wrappers. Primitives without direct mappings are tessellated via their ft_tessellate method and emitted as polyhedron().
The *-d* option prints debugging information. The *-o* option specifies the output file (default is stdout).
[[example]]
== EXAMPLE
----
$ g-scad -o model.scad model.g all.g
$ openscad model.scad
----
[[see_also]]
== SEE ALSO
*csg-g*(1), *g-stl*(1), *openscad*(1)
[[author]]
== AUTHOR
BRL-CAD Team
[[copyright]]
== COPYRIGHT
This software is Copyright (c) 2025 by the United States Government as represented by U.S. Army Research Laboratory.
[[bug_reports]]
== BUG REPORTS
Reports of bugs or problems should be submitted via electronic mail to devs@brlcad.org
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.