> Learn to create your own meshes by extruding mesh faces.

Source: https://doc.babylonjs.com/features/introductionToFeatures/chap3/polycar

# Getting Started - Extruding Polygons

## Building the Car
The car is going to be a very simple one. The body will be built using the *extrudePolygon* method. This is another shape that can be built using *MeshBuilder*. The outline of the shape is drawn in the XZ plane, with points in counter-clockwise order, and the extrusion is in the Y direction. The origin for the polygon is the zero point on the bottom plane.

The outline for the car consists of an array of Vector3 points forming a horizontal baseline, a quarter circle for the front, followed by a horizontal top line. The vertical back is formed by the *extrudePolygon* method, as it automatically joins the first and last points.

```javascript
//base
const outline = [
    new BABYLON.Vector3(-0.3, 0, -0.1),
    new BABYLON.Vector3(0.2, 0, -0.1),
]

//curved front
for (let i = 0; i < 20; i++) {
    outline.push(new BABYLON.Vector3(0.2 * Math.cos(i * Math.PI / 40), 0, 0.2 * Math.sin(i * Math.PI / 40) - 0.1));
}

//top
outline.push(new BABYLON.Vector3(0, 0, 0.1));
outline.push(new BABYLON.Vector3(-0.3, 0, 0.1));
```

These, together with the depth to extrude along Y, give the shape for the car.
```javascript
const car = BABYLON.MeshBuilder.ExtrudePolygon("car", {shape: outline, depth: 0.2});
```

> Note: The *extrudePolygon* and [PolygonMeshBuilder](https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/polyMeshBuilder) both use a *earcut* slicing algorithm.  
> The playground has earcut defined, but if you are following this tutorial on your own file system, you will need to download the earcut algorithm via [CDN](https://unpkg.com/earcut@latest/dist/earcut.min.js) or [NPM](https://github.com/mapbox/earcut#install).  
> If you are using TypeScript then you can inject the earcut algorithm as the *earcutInjection* parameter on the [extrudePolygon function](https://doc.babylonjs.com/typedoc/classes/babylon.meshbuilder#extrudepolygon).

- [Playground: Learning to Extrude](https://playground.babylonjs.com/#KDPAQ9#10) - Simple demonstration showing the basics of extruding meshes.

We form the wheel for the right-back position from a cylinder and add it as a child of the car. We then make copies for the right-front, left-back, and left-front wheels. This time, we use *clone* rather than *createInstance*, since we can clone a clone. When we clone a wheel, the clone inherits the wheel's parent.

```javascript
const wheelRB = BABYLON.MeshBuilder.CreateCylinder("wheelRB", {diameter: 0.125, height: 0.05})
wheelRB.parent = car;
wheelRB.position.z = -0.1;
wheelRB.position.x = -0.2;
wheelRB.position.y = 0.035;

const wheelRF = wheelRB.clone("wheelRF");
wheelRF.position.x = 0.1;

const wheelLB = wheelRB.clone("wheelLB");
wheelLB.position.y = -0.2 - 0.035;

const wheelLF = wheelRF.clone("wheelLF");
wheelLF.position.y = -0.2 - 0.035;
```

- [Playground: Extruding Wheels](https://playground.babylonjs.com/#KDPAQ9#11) - Expanding on the basics of extruding meshes.

Now we will make the car look a bit more like a real car by using some textures.
