--- title: Cloning ---

Models and paths are simple JavaScript objects, so they are easy to clone in a way that is standard to JavaScript. Maker.js provides a few functions for cloning:

Cloning is useful in many situations. For example, if you need many copies of a model for rotation:

{% highlight javascript %} //clone and rotate var makerjs = require('makerjs'); function sawtooth(numTeeth, r1, rd, offset) { var a = 360 / numTeeth; var a1 = 90 - a / 2; var r2 = r1 + rd; var p1 = makerjs.point.fromPolar(makerjs.angle.toRadians(a1), r1); var p2 = makerjs.point.rotate(p1, a, [0, 0]); var p3 = [-offset, r2]; this.paths = { outer: new makerjs.paths.Arc(p1, p3, r2 / 4, false, false), inner: new makerjs.paths.Arc(p2, p3, r1 / 4, false, false) }; } var wheel = { models: {} }; var numTeeth = 30; var tooth = new sawtooth(numTeeth, 100, 20, 10); for (var i = 0; i < numTeeth; i++ ) { var clone = makerjs.cloneObject(tooth); var a = 360 / numTeeth; makerjs.model.rotate(clone, a * i, [0, 0]); wheel.models[i] = clone; } var svg = makerjs.exporter.toSVG(wheel); document.write(svg); {% endhighlight %}