forked from jscad/OpenJSCAD.org
-
Notifications
You must be signed in to change notification settings - Fork 0
connectors proposal
Davor Hrg edited this page Jun 6, 2021
·
9 revisions
What I thinkg we need
- connector generators for each built-in geometry,
- pattern for modules that provide custom geometries to follow suit and provide own factories
- connectors are a wrappers on top of the solids, and changes to connectors code-base would not affect geometries.
- generator is created by providing the identical parameters one would provide for the geometry
- generator creates the same geometry (cuboid, sphere, cylinder, ...etc) but stores the provided parameters
- generator adds
getConnector
method to geometry to calculate a connectors, later on, based on some logic that makes sense for that geometry - a cube connector generator could provide connectors on different faces and corners
- a pyramid connector generator would have different expectations
- a cylinder connector generator would have top or bottom, or at some angle with some distance from bottom/top
A connector generator is useful, because different geometries have different logical places where connectors could be and how to calculate their position.
After that we need a pattern to use and combine the connectors
- align would use
getConnector
method from each geometry and apps parameters to it - when combining connectors first one is fixed and other one is moved to it
- the second geometry connector direction should be flipped by default
- when connecting two identical cones at their bottom one should be flipped to get expected result, so that would be the reasoning behind the flipping
- align function can then do the transformations based on parameter for getConnector method of each geometry
My preferred shortcut for aligning models that I already use in jscad scripts that I will use in these examples:
- T - top
- B - bottom
- N,S,E,W
- I decided against: Left,Right,Top,Bottom,Front,Back because of first letter collision for Bottom and Back
Code using connectors that would be equal to creating a cuboid with size: [10,10,10]
let cube = cuboidConnector({size:[10,10,10]})
return cube;
Although it looks similar it gets better when you start moving things
// create cuboid, but use bottom-south-west corner to place it at xyz origin.
// it facing down because first letter(B) is for direction, the rest are for location
let cube = cuboidConnector({size:[10,10,10]}, 'BBSW')
return cube
The magic happens when you add cone to the East face of the cube
// create cuboid, but use bottom-south-west corner to place it at xyz origin
// facing down because first letter(B) is for direction, rest for location
let cube = cuboidConnector({size:[10,10,10]}, 'BBSW')
let cone = cylinderConnector({height:10, startRadius: [5,5], endRadius:[1]})
// align cube by fixating at East side of cube, and moving bottom of the cone there
cone = align(cube, 'E',cone, 'B') // original cone is not touched, a copy is created
// align would do this by calling cube.getConnector('E') and cone.getConnector(B) and then do the move
return [cube, cone];
Add a sphere on top of the cone
let cube = cuboidConnector({size:[10,10,10]}, 'BBSW')
let cone = cylinderConnector({height:10, startRadius: [5,5], endRadius:[1]})
cone = align(cube,'E', cone, 'B') // original cone is not touched, a copy is created
return [cube, cone, align(cone,'T',sphere())];