Index of /OpenSCAD/conflate

      Name                    Last modified      Size  Description
Parent Directory - conflate.c 2025-09-15 00:15 14K flex.c 2025-09-15 00:15 9.2K flex.h 2025-09-15 00:15 9.4K gencomp.c 2025-09-15 00:15 12K Makefile 2025-09-15 00:15 119 Makefile-conflate 2025-09-15 00:15 8.7K parser.h 2025-09-15 00:15 842 regen.c 2025-09-15 00:15 11K regexp-lexer.c 2025-09-15 00:15 43K regexp-lexer.h 2025-09-15 00:15 1.3K takeon.c 2025-09-15 00:15 24K takeon-checks.c 2025-09-15 00:15 24K takeon-output.c 2025-09-15 00:15 32K uparse.c 2025-09-15 00:15 60K uparse-main.c 2025-09-15 00:16 9.7K README.txt 2025-09-15 00:23 2.8K conflate.g 2025-09-18 13:16 42K conflate-aarch64 2025-09-18 13:16 1.0M conflate.h 2025-09-18 13:18 54K conflate-x86-64 2025-09-18 13:18 1.4M conflate.zip 2025-09-18 13:19 1.3M
15th Sep 2025

This is a work-in-progress version of a utility I'm writing that will allow
you to take a series of OpenSCAD transformation calls, and output a shorter
sequence of calls that should have the same effect.  Note that the transformations
(translate, rotate, mirror, and multmatrix) should have numeric parameters,
not parameter names or expressions.

This code only accepts the transformation calls, not full OpenSCAD statements,
for example, these:

   rotate([  0.00,  0.00, 90.00])
   scale([1.00,2.00,1.00])
   mirror([1,0,0])
   translate([  0.00,  0.00, 50.00])
   mirror([0,1,0])
   rotate([  0.00, 90.00,  180.00])
   scale([  1.00,  0.50,  1.00])

(they don't have to be on separate lines)

Running the utility can be done interactively as follows:

$ ./conflate /dev/stdin
rotate([90,0,0]) rotate([0,180,0])
^D
conflate: parsed "/dev/stdin" successfully

/* maps to:

    multmatrix([ [-1.00, 0.00, 0.00, 0.00],
                 [0.00, 0.00, 1.00, 0.00],
                 [0.00, 1.00, 0.00, 0.00],
                 [0.00, 0.00, 0.00, 1.00] ]) */

// which is equivalent to:

    rotate([ 90.00,   0.00, -180.00])

$ ./conflate /dev/stdin
rotate([0,180,0]) rotate([90,0,0])
^D
    conflate: parsed "/dev/stdin" successfully

/* maps to:

    multmatrix([ [-1.00, 0.00, 0.00, 0.00],
                 [0.00, 0.00, -1.00, 0.00],
                 [0.00, -1.00, 0.00, 0.00],
                 [0.00, 0.00, 0.00, 1.00] ]) */

// which is equivalent to:

    rotate([-90.00,   0.00, 180.00])


If you're interested in seeing how the code works, or want to make enhancements,
the significant source file is conflate.g which is the combined grammar for CSG files
and code to perform the simplification.  Everything else in this directory is a
copy of my parser generator.  If this code were to be added to OpenSCAD, you would
use the internal AST of OpenSCAD rather than parsing the output to recreate an AST.

(And if anyone wanted an actual utility like this, I'ld recommend converting
conflate.g into the format of whatever more well-known parser generator you
prefer to use, for better portability.  The main logic of the optimisation
is all contained in the single function 'optimised_csg')

There is a statically-linked intel (x86-64) binary of conflate in this directory
if compiling from source is too daunting (though it shouldn't be - just copy the
files and type 'make'.  The zip file here contains all the other files.)
conflate-aarch64 is the same binary, also compiled statically, for arm aarch64
(specifically raspberry pi).

You may also be interested in a similar utility, flatten, in the directory
above this one.  It takes a .csg file and removes a lot of redundancy from
it.  However it does not apply these transformation conflations.  Perhaps
at some point in the future these two programs may be merged but that is
not an immediate priority.


Graham <gtoal@gtoal.com>