3D Models
In this tutorial you modify a more complex 3D model. The reference product is a hinge with extrusions and holes. For simplicity you model only half of the hinge.
You will follow three steps:
🎥 You can also follow the tutorial with this video:
1. Create Component​
Create a component container and name it HINGE.
2. Create Sketches​
You model half of the hinge in a simple way with geometry dependent on size
:
A. Leaf​
Start with the leaf (flat part):
- Click Sketch, choose shape Square, then select Create.
- Rename the automatically created function from
generateSquareSketch
togenerateLeafSketch
by editing the code. - Click Save & Run to apply changes.
- Click the function in the left sidebar to visualize it. The sidebar updates with the new name automatically.
export function generateLeafSketch(size: number) {
const sketch = SKYCAD.generateRectangleSketch(0, 0, size, size)
return sketch
}
Extend generateLeafSketch
by creating a sketch for each hole (topHoleSketch
and bottomHoleSketch
) and then merging them into the leaf sketch.
- Under the rectangle sketch line add two circular sketches positioned as in the earlier figure:
const topHoleSketch = SKYCAD.generateCircleSketch(size / 2, (1 / 3) * size, 0.1 * size)
const bottomHoleSketch = SKYCAD.generateCircleSketch(size / 2, (2 / 3) * size, 0.1 * size) - Merge each hole sketch into
sketch
:sketch.mergeSketch(topHoleSketch)
sketch.mergeSketch(bottomHoleSketch) - The function now looks like:
export function generateLeafSketch(size: number) {
const sketch = SKYCAD.generateRectangleSketch(0, 0, size, size)
const topHoleSketch = SKYCAD.generateCircleSketch(size / 2, (1 / 3) * size, 0.1 * size)
const bottomHoleSketch = SKYCAD.generateCircleSketch(size / 2, (2 / 3) * size, 0.1 * size)
sketch.mergeSketch(topHoleSketch)
sketch.mergeSketch(bottomHoleSketch)
return sketch
}
B. Barrel​
Create the middle cylinder (barrel) cross section:
- Click Sketch, select shape Circle, then click Create.
- Rename it to
generateBarrelSketch
. - Click Save & Run to apply changes.
- Click the function in the left sidebar to visualize it.
3. Create Model​
With the sketches ready, create the model of half the hinge:
- At the top of the code section click Model, choose Extrude from generateLeafSketch, then click Create.
- Rename the function to
generateHalfHingeModel
. - As in the previous tutorial, keep a constant leaf thickness inside
generateHalfHingeModel
:
- Add
const leafThickness = 5
. - Use it as the extrusion length:
model.addExtrude(sketch, plane, leafThickness)
. - Keep
size
as the only input (removeextrudeLength
).
- The result should look like:
export function generateHalfHingeModel(size: number) {
const model = new SKYCAD.ParametricModel()
const sketch = GEOM2D.generateLeafSketch(size)
const plane = new SKYCAD.Plane(0, 0, 1)
const leafThickness = 5
model.addExtrude(sketch, plane, leafThickness)
return model
}
Add a second extrusion for the barrel inside generateHalfHingeModel
(similar to the cut in the previous tutorial):
- Define a constant diameter (e.g.
const barrelDiameter = 20
). - Create the barrel cross section:
const barrelSketch = GEOM2D.generateBarrelSketch(barrelDiameter)
. - Create a plane parallel to the y-axis:
const yPlane = new SKYCAD.Plane(0, 1, 0)
. - Add the second extrusion with half of
size
as the extrusion length. - The function now looks like:
export function generateHalfHingeModel(size: number) {
const model = new SKYCAD.ParametricModel()
const leafSketch = GEOM2D.generateLeafSketch(size)
const zPlane = new SKYCAD.Plane(0, 0, 1)
const leafThickness = 5
model.addExtrude(leafSketch, zPlane, leafThickness)
const barrelDiameter = 20
const barrelSketch = GEOM2D.generateBarrelSketch(barrelDiameter)
const yPlane = new SKYCAD.Plane(0, 1, 0)
model.addExtrude(barrelSketch, yPlane, size / 2)
return model
}
You can switch visualization via the left sidebar at any time:
Mouse controls for the camera:
- Rotate: hold right click
- Pan: hold the scroll wheel
- Zoom: scroll wheel
Doublecheck the solution code here:
export function generateHalfHingeModel(size: number) {
const model = new SKYCAD.ParametricModel()
const leafSketch = GEOM2D.generateLeafSketch(size)
const zPlane = new SKYCAD.Plane(0, 0, 1)
const leafThickness = 5
model.addExtrude(leafSketch, zPlane, leafThickness)
const barrelDiameter = 20
const barrelSketch = GEOM2D.generateBarrelSketch(barrelDiameter)
const yPlane = new SKYCAD.Plane(0, 1, 0)
model.addExtrude(barrelSketch, yPlane, size / 2)
return model
}
export function generateLeafSketch(size: number) {
const sketch = SKYCAD.generateRectangleSketch(0, 0, size, size)
const topHoleSketch = SKYCAD.generateCircleSketch(size / 2, (1 / 3) * size, 0.1 * size)
const bottomHoleSketch = SKYCAD.generateCircleSketch(size / 2, (2 / 3) * size, 0.1 * size)
sketch.mergeSketch(topHoleSketch)
sketch.mergeSketch(bottomHoleSketch)
return sketch
}
export function generateBarrelSketch(diameter: number) {
const sketch = SKYCAD.generateCircleSketch(0, 0, diameter)
return sketch
}
You have learned the basics of modifying functions and reusing constants and sketches when possible. Next you reuse this half hinge to build the other half and assemble them. That process is covered in the next tutorial: Static Assets.