Skip to content
Dan Marshall edited this page May 30, 2015 · 23 revisions

#Key Concepts of Maker.js

Maker.js lets you design shapes with JavaScript code. These shapes have only outlines. Shapes are made from primitive outlines called Paths. There are 3 primitive Paths: line, circle, and arc. Paths are defined by Points and other properties. A group of paths may be contained in what is called a Model. A Model may then contain other Models.

There is no concept of contiguity between paths.

POJO's: Plain old JavaScript objects are used to design your model. To make this work, these plain objects must conform to a schema.

Point

{ x: number, y: number }

example:

var myPoint = { x: 42, y: 99 };

Paths

All Path types require these properties at a minimum:

  • type: string
  • id: string
  • origin: Point

Specific path types require additional properties:

Line path

{ type: "line", id: string, origin: Point, end: Point }

example:

var myLine = {type:"line", id:"myLine1", origin:{x:0, y:0}, end:{x:42, y:99}};

Circle path

{ type: "circle", id: string, origin: Point, radius: number }

example:

var myCircle = {type:"circle", id:"myCircle1", origin:{x:0, y:0}, radius:13};

Arc path

{ type: "arc", id: string, origin: Point, radius: number, startAngle: number, endAngle: number }

example:

var myArc = {type:"arc", id:"myArc1", origin:{x:0, y:0}, radius:4.2, startAngle:45, endAngle:135};

Model

Models require only an id property.

  • id: string

Models may optionally contain these properties:

  • type: string
  • origin: Point
  • paths: Array of Paths
  • models: Array of Models
  • units: string

The type property is currently not used, but it might be helpful for your own annotation to know where a model came from. The units property need not be specified, or it can be one of these values:

  • "mm" for millimeter
  • "cm" for centimeter
  • "m" for meter
  • "inch"
  • "foot"

If your model contains a model with different units, you will want to Scale[link] it by a Unit Conversion[link] ratio.

Models may or may not contain paths. They also may or may not contain other models.

Therefore the minimum example of a model is: { id: string } however this is pointless ;-)

examples:

var myModel = {id:"myModel1", paths:[myCircle, myLine, myArc]};

var myOtherModel = {id:"myModel2", paths:[{type:"circle", id:"myCircle2", origin:{x:0, y:0}, radius:3}]};

var allMyModels = {id:"allMyModels", models:[myModel , myOtherModel]};

Clone this wiki locally