SolidCode / SolidPython

A python frontend for solid modelling that compiles to OpenSCAD
1.11k stars 173 forks source link

apply parameter-less transforms directly #63

Closed scifuentes closed 1 year ago

scifuentes commented 7 years ago

Syntax sugar to allow the application of parameter-less transformations as functions i.o. objects. Existing OpenScad-esque syntax not affected

e.g.: difference(cube(1), sphere(1)) vs difference()(cube(1). sphere(1))

guoqiao commented 3 years ago

Something I was thinking:

# python set operations 
cube(1) | sphere(1)  # union,  `+` seems also make sense
cube(1) - sphere(1)  # difference, already have this
cube(1) & sphere(1) # intersection, `*` doesn't make sense for this

cube(1).union(sphere(1))
cube(1).difference(sphere(1))
cube(1).intersection(sphere(1))

cube(1).translate(1,1,1)
cube(1).translate_x(-1)
cube(1).translate_y(2)

cube(1).scale(1.1, 0, 0)
cube(1).rotate(90, 0, 0)

cube(1).color('red')
cube(1).red()

cube(1).mirror([1,0,0])
cube(1).mirror_x(1)

# support chain operations
(cube(1) | sphere(1) & cylinder(2) - cube(2)).translate_z(2).rotate_z(90).red().mirror_y(1).render()
ilyakh commented 3 years ago

I have a similar design implemented in solipython-elements repo, in case you need inspiration for the API.