Skip to main content

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:

  1. Create component
  2. Create sketches
  3. Create model (half hinge)
tip

🎥 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):

  1. Click Sketch, choose shape Square, then select Create.
  2. Rename the automatically created function from generateSquareSketch to generateLeafSketch by editing the code.
  3. Click Save & Run to apply changes.
  4. 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.

  1. 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)
  2. Merge each hole sketch into sketch:
    sketch.mergeSketch(topHoleSketch)
    sketch.mergeSketch(bottomHoleSketch)
  3. 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:

  1. Click Sketch, select shape Circle, then click Create.
  2. Rename it to generateBarrelSketch.
  3. Click Save & Run to apply changes.
  4. Click the function in the left sidebar to visualize it.

3. Create Model​

With the sketches ready, create the model of half the hinge:

  1. At the top of the code section click Model, choose Extrude from generateLeafSketch, then click Create.
  2. Rename the function to generateHalfHingeModel.
  3. 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 (remove extrudeLength).
  1. 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):

  1. Define a constant diameter (e.g. const barrelDiameter = 20).
  2. Create the barrel cross section: const barrelSketch = GEOM2D.generateBarrelSketch(barrelDiameter).
  3. Create a plane parallel to the y-axis: const yPlane = new SKYCAD.Plane(0, 1, 0).
  4. Add the second extrusion with half of size as the extrusion length.
  5. 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
    }

note

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:
GEOM3D
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
}
GEOM2D
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.