Skip to content

Instantly share code, notes, and snippets.

@marklundin
Last active September 22, 2015 18:44
Show Gist options
  • Save marklundin/d2e8c0730b7cf1ce3ea6 to your computer and use it in GitHub Desktop.
Save marklundin/d2e8c0730b7cf1ce3ea6 to your computer and use it in GitHub Desktop.
/*
Below is an example shape object in JSON notation. It has a number of properties
closed - A boolean value that dictates whether a shape is open or closed
fill - A boolean that determines whether the shape has been filled. NOTE, a shape must be closed to be filled.
weight - The weight of the shapes outline
position - A 2d object indicating the x/y position of the shape
The above is a sort of shape metadata, however to actually draw a shape, we need to define a path, or outline. This is done using the 'path' property,
paths - An Array of Path Segments.
A Path segment is a section of the overall shape, it can be a line, a move or a curve, but for the most part, you'll
probably only need the line and curve segments. To define the type of segment, you'll need to define it's 'order' which
is specified as a number. Below is a list of orders and their corresponding types;
0: Move
1: Line
2: Cubic Curve
3: Quadratic Curve
Once you have specified the type of path segment you want, you must define an array of points used to draw the segment. For
simple segments such as move, or line commands you only need 1 point, however for cubic curves you need 2; 1 for the
control and one for the anchor. For Quadratic curves you need 3; 2 control points and 1 anchor.
The sample below defines a filled rectangle. Note how you don't specify the last coordinate to close the shape. Simply
specifying the shapes as 'closed' will automatically draw a path segment back to the first point.
*/
{
/*
Filled Rectangle
*/
closed:true,
fill:true,
weight:1,
position:{
x:100,
y:100
},
path:[
{
order:0,
points:[{x:0,y:0}]
},
{
order:1,
points:[{x:100,y:0}]
},
{
order:1,
points:[{x:100,y:100}]
},
{
order:1,
points":[{x:0,y:100}]
}
]
}
{
/*
TOOL
----
The path tool for example allows users to draw shapes, whilst the cursor tools allows
them to move and manipulate them
*/
tool: 'PEN',
/*
SHAPES
------
Here we define an array of shapes objects. Each shape object defines a 2D path
which is drawn on the canvas and triangulated into a 3d shape.
Each shape has a list of points that represent the geometry of the shape,
as well as other properties that define it's visual representation.
A more formal defintition of a shape object can be found here https://gist.github.com/marklundin/d2e8c0730b7cf1ce3ea6
*/
shapes:[],
/*
selectedShapes
--------------
We also maintain a list of shapes that are currently selected. Selected shapes are treated
differently from non-selected shapes in that they can be dragged, moved or deleted. Visually,
they are also treated differently.
The selected shapes are kept as a list of indices into the shapes array.
*/
selectedShapes: [],
/*
Thickness
---------
The thickness defines how chunky the bracelet is, or more technically how far we
extrude the 2d shape into 3d.
*/
thickness: 10,
/*
Resolution
----------
The resolution determines the quality of the resulting 3d mesh. It is used when
sampling the 2d image to construct the 3d geometry. A higher number creates
a more detailed mesh, however this comes at the expense of a larger file
size, and it also takes more time to compute. At higher resolutions
this may become a problem for older machines.
The recommended resolution depends on the physical size of the printed object
*/
resolution: 0.2,
max:{
thickness: 25
},
min:{
thickness: 5
}
}
@IndieKA
Copy link

IndieKA commented Sep 22, 2015

Thank you. If you do not mind I will be using this in my mainJS file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment