Skip to content

Commit 78f7496

Browse files
authored
Merge pull request #122 from Billiam/feature/mirror
Add a `Mirror` command
2 parents e4fb23a + ffe3513 commit 78f7496

File tree

7 files changed

+33
-3
lines changed

7 files changed

+33
-3
lines changed

js/CADWorker/CascadeStudioStandardLibrary.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,31 @@ function Rotate(axis, degrees, shapes, keepOriginal) {
400400
return rotated;
401401
}
402402

403+
function Mirror(vector, shapes, keepOriginal) {
404+
if (!vector) { vector = [1, 0, 0]; }
405+
const mirrored = CacheOp(arguments, () => {
406+
const mirrorTransform = new oc.gp_Trsf();
407+
const mirrorPlaneOrigin = new oc.gp_Pnt(0, 0, 0);
408+
const mirrorPlaneNormal = new oc.gp_Dir(vector[0], vector[1], vector[2]);
409+
mirrorTransform.SetMirror(new oc.gp_Ax2(mirrorPlaneOrigin, mirrorPlaneNormal));
410+
const mirroring = new oc.TopLoc_Location(mirrorTransform);
411+
412+
if (!isArrayLike(shapes)) {
413+
return new oc.TopoDS_Shape(shapes.Moved(mirroring).Reversed());
414+
} else if (shapes.length >= 1) {
415+
let newMirroring = [];
416+
for (let shapeIndex = 0; shapeIndex < shapes.length; shapeIndex++) {
417+
newMirroring.push(new oc.TopoDS_Shape(shapes[shapeIndex].Moved(mirroring).Reversed()));
418+
}
419+
return newMirroring;
420+
}
421+
})
422+
if (!keepOriginal) { sceneShapes = Remove(sceneShapes, shapes); }
423+
sceneShapes.push(mirrored);
424+
425+
return mirrored;
426+
}
427+
403428
function Scale(scale, shapes, keepOriginal) {
404429
let scaled = CacheOp(arguments, () => {
405430
let transformation = new oc.gp_Trsf();

js/MainPage/CascadeMain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ window.workerWorking = false;
1111

1212
let starterCode =
1313
`// Welcome to Cascade Studio! Here are some useful functions:
14-
// Translate(), Rotate(), Scale(), Union(), Difference(), Intersection()
14+
// Translate(), Rotate(), Scale(), Mirror(), Union(), Difference(), Intersection()
1515
// Box(), Sphere(), Cylinder(), Cone(), Text3D(), Polygon()
1616
// Offset(), Extrude(), RotatedExtrude(), Revolve(), Pipe(), Loft(),
1717
// FilletEdges(), ChamferEdges(),

js/StandardLibraryIntellisense.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ function Translate(offset: number[], shape: oc.TopoDS_Shape, keepOriginal?: bool
194194
* @example```let leaningCylinder = Rotate([0, 1, 0], 45, Cylinder(25, 50));```*/
195195
function Rotate(axis: number[], degrees: number, shape: oc.TopoDS_Shape, keepOriginal?: boolean): oc.TopoDS_Shape;
196196

197+
/** Mirror this shape about 3-coordinate normal vector
198+
* [Source](https://github.com/zalo/CascadeStudio/blob/master/js/CADWorker/CascadeStudioStandardLibrary.js)
199+
* @example```let mirrored = Mirror([0, 0, 1] , Text3D("Hello!"));```*/
200+
function Mirror(vector: number[], shape: oc.TopoDS_Shape, keepShape?: boolean): oc.TopoDS_Shape;
201+
197202
/** Scale a shape to be `scale` times its current size.
198203
* [Source](https://github.com/zalo/CascadeStudio/blob/master/js/CADWorker/CascadeStudioStandardLibrary.js)
199204
* @example```let scaledCylinder = Scale(50, Cylinder(0.5, 1));```*/

node_modules/opencascade.js/dist/oc.d.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/opencascade.js/dist/opencascade.wasm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-7.28 KB
Binary file not shown.
132 Bytes
Loading

0 commit comments

Comments
 (0)