-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { ExtrudeFromSlices } from "../lib" | ||
import { JsCadFixture } from "../lib/components/jscad-fixture" | ||
import jscad from "@jscad/modeling" | ||
|
||
const { bezier } = jscad.curves | ||
const { circle, line, polygon, rectangle, roundedRectangle, star } = | ||
jscad.primitives | ||
const { extrudeLinear, extrudeRotate, extrudeFromSlices, slice } = | ||
jscad.extrusions | ||
const { mat4 } = jscad.maths | ||
|
||
const baseSlice = slice.fromPoints([ | ||
[2, 2], | ||
[-2, 2], | ||
[-2, -2], | ||
[2, -2], | ||
]) | ||
|
||
const xCurve = bezier.create([1, 1.8, 0.4, 1]) | ||
const yCurve = bezier.create([1, 1.8, 0.5]) | ||
|
||
export default () => ( | ||
<JsCadFixture zAxisUp showGrid> | ||
<ExtrudeFromSlices | ||
numberOfSlices={10} | ||
capStart={true} | ||
capEnd={true} | ||
close={true} | ||
repair={true} | ||
baseSlice={baseSlice} | ||
callback={function (progress, count, base) { | ||
let newslice = slice.transform( | ||
mat4.fromTranslation(mat4.create(), [0, 0, 10 * progress]), | ||
baseSlice, | ||
) | ||
newslice = slice.transform( | ||
mat4.fromScaling(mat4.create(), [ | ||
bezier.valueAt(progress, xCurve) as any, | ||
bezier.valueAt(progress, yCurve) as any, | ||
1, | ||
]), | ||
newslice, | ||
) | ||
|
||
// Rotate the slice 90 degrees along the path | ||
const rotationAngle = (Math.PI / 2) * progress // 90 degrees in radians | ||
newslice = slice.transform( | ||
mat4.fromXRotation(mat4.create(), rotationAngle), | ||
newslice, | ||
) | ||
|
||
return newslice | ||
}} | ||
/> | ||
</JsCadFixture> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { withColorProp } from "lib/wrappers/with-color-prop" | ||
import { withOffsetProp } from "lib/wrappers/with-offset-prop" | ||
import type { Point3 } from "./translate" | ||
|
||
export type Slice = { | ||
edges: Array<[Point3, Point3]> | ||
} | ||
|
||
export type ExtrudeFromSlicesProps = { | ||
numberOfSlices?: number | ||
capStart?: boolean | ||
capEnd?: boolean | ||
close?: boolean | ||
repair?: boolean | ||
baseSlice: Slice | ||
callback?: (progress: number, count: number, base: Slice) => Slice | ||
} | ||
|
||
const ExtrudeFromSlicesBase = ({ | ||
numberOfSlices, | ||
capStart, | ||
capEnd, | ||
close, | ||
repair, | ||
baseSlice, | ||
callback, | ||
}: ExtrudeFromSlicesProps) => { | ||
return ( | ||
<extrudeFromSlices | ||
numberOfSlices={numberOfSlices} | ||
capStart={capStart} | ||
capEnd={capEnd} | ||
close={close} | ||
repair={repair} | ||
baseSlice={baseSlice} | ||
callback={callback} | ||
></extrudeFromSlices> | ||
) | ||
} | ||
|
||
export const ExtrudeFromSlices = withOffsetProp( | ||
withColorProp(ExtrudeFromSlicesBase), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters