|
| 1 | +# `replicad` |
| 2 | + |
| 3 | +The library to build browser based 3D models with code. |
| 4 | + |
| 5 | +## How to play with it |
| 6 | + |
| 7 | +I am still working on making an accessible toolchain for replicad, so for now |
| 8 | +you can play with my [online |
| 9 | +"visualiser"](https://studio.replicad.xyz/visualiser). |
| 10 | + |
| 11 | +Write in a local file, select it in the tool and it should build your model. |
| 12 | +There is still a lot of work to make this intuitive, but you can play with the |
| 13 | +examples below. Note that if you use Chrome the model is recomputed as you |
| 14 | +change your local file. |
| 15 | + |
| 16 | +You need to write a "main" function that receives the complete `replicad` |
| 17 | +library. |
| 18 | + |
| 19 | +## Examples |
| 20 | + |
| 21 | +Here are some basic examples of things you can do with replicad. |
| 22 | + |
| 23 | +#### A simple example |
| 24 | + |
| 25 | +```js |
| 26 | +const main = ({ Sketcher }) => { |
| 27 | + const base = new Sketcher("XZ") |
| 28 | + .hLine(-25) |
| 29 | + .halfEllipse(0, 40, 5, true) |
| 30 | + .hLine(25) |
| 31 | + .close() |
| 32 | + .revolve([0, 0, 1]); |
| 33 | + |
| 34 | + const hole = new Sketcher() |
| 35 | + .quadraticBezierCurveTo([0, 20], [20, 30]) |
| 36 | + .closeWithMirror() |
| 37 | + .extrude(40) |
| 38 | + .translateY(-12); |
| 39 | + |
| 40 | + return base.cut(hole); |
| 41 | +}; |
| 42 | +``` |
| 43 | + |
| 44 | +#### The open cascade bottle |
| 45 | + |
| 46 | +```js |
| 47 | +const defaultParams = { |
| 48 | + width: 50, |
| 49 | + height: 70, |
| 50 | + thickness: 30, |
| 51 | +}; |
| 52 | + |
| 53 | +const main = ( |
| 54 | + { Sketcher, FaceSketcher, localGC, makeCylinder, makeOffset, FaceFinder }, |
| 55 | + { width: myWidth, height: myHeight, thickness: myThickness } |
| 56 | +) => { |
| 57 | + let shape = new Sketcher() |
| 58 | + .movePointerTo([-myWidth / 2, 0]) |
| 59 | + .vLine(-myThickness / 4) |
| 60 | + .threePointsArc(myWidth, 0, myWidth / 2, -myThickness / 4) |
| 61 | + .vLine(myThickness / 4) |
| 62 | + .closeWithMirror() |
| 63 | + .extrude(myHeight) |
| 64 | + .fillet(myThickness / 12); |
| 65 | + |
| 66 | + const myNeckRadius = myThickness / 4; |
| 67 | + const myNeckHeight = myHeight / 10; |
| 68 | + const neck = makeCylinder( |
| 69 | + myNeckRadius, |
| 70 | + myNeckHeight, |
| 71 | + [0, 0, myHeight], |
| 72 | + [0, 0, 1] |
| 73 | + ); |
| 74 | + |
| 75 | + shape = shape.fuse(neck); |
| 76 | + |
| 77 | + shape = shape.shell({ |
| 78 | + filter: new FaceFinder().inPlane("XY", [0, 0, myHeight + myNeckHeight]), |
| 79 | + thickness: myThickness / 50, |
| 80 | + }); |
| 81 | + |
| 82 | + const [r, gc] = localGC(); |
| 83 | + |
| 84 | + const neckFace = r( |
| 85 | + new FaceFinder() |
| 86 | + .containsPoint([0, myNeckRadius, myHeight]) |
| 87 | + .ofSurfaceType("CYLINDRE") |
| 88 | + .find(shape.clone(), { unique: true }) |
| 89 | + ); |
| 90 | + |
| 91 | + const bottomThreadFace = r( |
| 92 | + r(makeOffset(neckFace, -0.01 * myNeckRadius)).faces[0] |
| 93 | + ); |
| 94 | + const baseThreadSketch = new FaceSketcher(bottomThreadFace) |
| 95 | + .movePointerTo([0, 0.25]) |
| 96 | + .halfEllipse(2, 0.5, 0.1) |
| 97 | + .close(); |
| 98 | + |
| 99 | + const topThreadFace = r( |
| 100 | + r(makeOffset(neckFace, 0.05 * myNeckRadius)).faces[0] |
| 101 | + ); |
| 102 | + const topThreadSketch = new FaceSketcher(topThreadFace) |
| 103 | + .movePointerTo([0, 0.25]) |
| 104 | + .halfEllipse(2, 0.5, 0.05) |
| 105 | + .close(); |
| 106 | + |
| 107 | + const thread = baseThreadSketch.loftWith(topThreadSketch); |
| 108 | + gc(); |
| 109 | + |
| 110 | + return shape.fuse(thread); |
| 111 | +}; |
| 112 | +``` |
| 113 | + |
| 114 | +## Making in work in an application |
| 115 | + |
| 116 | +You will need to load opencascadejs separately (you can use |
| 117 | +`replicad-opencascadejs` to only have the method necessary for replicad). You |
| 118 | +then need to inject it in `replicad` with the function: |
| 119 | + |
| 120 | +`setOC(oc)` |
| 121 | + |
| 122 | +Once this is done you can use `replicad` to draw your shapes. |
| 123 | + |
| 124 | +To export your shape, you can either use the `STL` or `STEP` save functions, or |
| 125 | +get the mesh and use it with three (or another 3d viewer library). |
| 126 | + |
| 127 | +Ideally the computation should be done in a worker. |
| 128 | + |
| 129 | +This all needs a bunch of helper, this should come soon(-ish) |
| 130 | + |
| 131 | +## License |
| 132 | + |
| 133 | +Copyright (C) 2021 QuaroTech Sàrl |
| 134 | + |
| 135 | +This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. |
| 136 | + |
| 137 | +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. |
| 138 | + |
| 139 | +You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. |
0 commit comments