CindyJS

CindyPrint

CindyPrint is a plug-in that enables the user to print three-dimensional objects from Cindy3D and CindyGL. For this, triangle meshes of the objects can be exported.

For Cindy3D, there are the options to print either the whole scene as the union of all objects (constructive solid geometry, CSG) or print tubes constructed around a path in space. For the former, the JavaScript library csg.js is used (https://github.com/jscad/csg.js/).

For CindyGL, iso surfaces of scalar functions can be created and printed using the Marching Cubes or SnapMC algorithms.

Barth Sextic Torus Discrete Asymptotic Line Catenoid
Barth sextic Torus Discrete asymptotic line catenoid

As a first step, in order to use the plugin, at the beginning of the HTML file, the following code needs to be added (possibly with different file paths).

<script type="text/javascript" src="../../build/js/CindyPrint.js"></script>

Examples on how to use CindyPrint can be found in the folder examples/cindyprint/.


GUI Options

When exporting objects for printing, it is often desirable that the user is able to have control over different types of settings. In the following section, an overview over the different settings the user can configure is given.

GUI options
Figure 1: Print UI for Cindy3D scenes. Call addcindy3dprintui to add this user interface.

In Cindy3D, spheres, cylinders and triangles are the objects a user can add to a scene. For the export, the user can specify the following information.

GUI options
Figure 2: Print UI for tubes in Cindy3D. Call addcindy3dprintuitubes to add this user interface.

When exporting tube meshes enclosing curves, different settings are necessary.

GUI options
Figure 3: Print UI for implicit surfaces in CindyGL. Call addcindyglprintui to add this user interface.

Finally, in CindyGL, the user can export triangle mesh approximations of implicit surfaces of scalar functions. The following settings can be specified.


API Documentation

Saving a triangle mesh of a Cindy3D scene: savecsgmesh(‹meshfilename›)

Description: Computes the union of all objects in a certain Cindy3D instance to create an output mesh. The union is computed as a triangle mesh using constructive solid geometry (CSG).

Modifiers:

Modifier Parameter Effect
instancename ‹string› The name of the Cindy3D instance to use.

Example #1:

savecsgmesh("mesh.stl");

Example #1:

savecsgmesh("mesh.obj",  instancename->"Cindy3DSecondInstance");

Saving a triangle mesh of a tube: savetubemesh(‹meshfilename›, ‹tubepoints›, ‹tuberadius›, ‹tubeclosed›)

Description: Generates the triangle mesh of a tube represented by a list of path line points and a radius and saves it in a file.

Example (f: [0°, 360°] -> ℝ³):

// n is the number of line points used for discretization.
n = 4000;
radius = 1;
f(w) := (sin(4*w), sin(5*w), sin(6*w));
tubePoints = apply(1..n, f((#-1)/n*360°));
savetubemesh("tube.stl", tubePoints, radius, true);

Adding the print UI: addcindy3dprintui(‹meshfilename›)

Description: Adds a printing user interface to the bottom of the website. This includes both changing print settings (like the model scale) and a print preview canvas using Cindy3D. It is expected that savecsgmesh will be used for generating print models (and not savetubemesh).

Example:

<script id='init' type='text/x-cindyscript'>
    use("Cindy3D");
    use("Cindy3DPrint");
    addcindy3dprintui("mesh.stl");
    // ...
</script>

Adding the print UI: addcindy3dprintuitubes(‹meshfilename›, ‹computetubepointsfunction, ‹numtubepointsstring›, ‹radiusstring›, ‹tubeclosed›)

Description: Adds a printing user interface to the bottom of the website. This includes both changing print settings (like the model scale) and a print preview canvas using Cindy3D. It is expected that savetubemesh will be used for generating print models (and not savecsgmesh}).

NOTE: numtubepointsstring and radiusstring are passed as strings and not as variable values, as this way, arbitrary computations for the number of points and the radius can be used that are variable and dependent on the program state. These arguments will be passed to savetubemesh.

Example:

<script id='init' type='text/x-cindyscript'>
    use("Cindy3D");
    use("Cindy3DPrint");
    radius = 1;
    n = 4000;
    f(w) := (sin(4*w), sin(5*w), sin(6*w));
    computeTubePoints(numTubePointsPrint) := (
        apply(1..numTubePointsPrint, f((#-1)/numTubePointsPrint*360°))
    );
    addcindy3dprintuitubes("tube.stl", computeTubePoints, "n", "radius", true);
    // ...
</script>

Drawing the print preview: drawprintpreview()

Description: Renders the content of the print preview canvas using the last generated triangle mesh.

NOTE: This should be called after the rendering code of the main Cindy3D instance!

Example (Cindy3D):

<script id='csmove' type='text/x-cindyscript'>
    begin3d();
    // ...
    end3d();
    drawprintpreview();
</script>

Example (CindyGL):

<script id='csdraw' type='text/x-cindyscript'>
    colorplot(...);
    drawprintpreview();
</script>

Updating the print preview: updatepreviewcdy3d()

Description: The function updates the print preview added by addcindy3dprintui by generating a new mesh using the objects stored in the specified Cindy3D instance (for more details see savecsgmesh).

NOTE: A button with the caption Update preview is automatically added to the UI when calling one of the addcindy3dprintui* functions. Thus, this function doesn't need to be called by the programmer of a website.

Modifiers:

Modifier Parameter Effect
instancename ‹string› The name of the Cindy3D instance to use.

Example #1:

updatepreviewcdy3d();

Example #2:

updatepreviewcdy3d("Cindy3DSecondInstance");

Updating the print preview: updatepreviewtubes()

Description: The function updates the print preview added by addcindy3dprintuitubes by generating a new tube mesh using the data set by addcindy3dprintuitubes.

NOTE: A button with the caption Update preview is automatically added to the UI when calling one of the addcindy3dprintui* functions. Thus, this function doesn't need to be called by the programmer of a website.

Example:

updatepreviewtubes();

Saving a triangle mesh of an iso surface: saveisomeshtofile(‹meshfilename›, ‹F›, ‹dF›, ‹isovalue›, ‹origin›, ‹dx›, ‹nx›)

Description: This function creates an approximation of the iso surface of a scalar field and saves it to a file as a triangle mesh. For this, it evaluates the function we want to compute the implicit surface of at vertices forming a Cartesian grid in 3D.

NOTE: The number of vertices in each dimension is larger by one than the number of cells.

Example:

// Some scalar field function.
fun(x, y, z) := (x^2 + y ^2 + z^2 - 1);

// F takes vec3 instead of 3 variables.
F(p) := (fun(p.x, p.y, p.z));

// Use central difference to approximate dF.
dF(p) := (
    (F(p + [eps, 0, 0]) - F(p - [eps, 0, 0])),
    (F(p + [0, eps, 0]) - F(p - [0, eps, 0])),
    (F(p + [0, 0, eps]) - F(p - [0, 0, eps]))
) / (2 * eps);

saveisomeshtofile("model.stl", F, dF, 0, [-5,-5,-5], 0.01, 1001);

Saving a triangle mesh of an iso surface: saveisomeshtofile(‹meshfilename›, ‹F›, ‹dF›, ‹isovalue›, ‹radius›)

Description: A second version of the command assuming a Cartesian grid centered at (0,0,0) and standard values for the other arguments. The function creates an approximation of the iso surface of a scalar field and saves it to a file as a triangle mesh. For this, it evaluates the function we want to compute the implicit surface of at vertices forming a Cartesian grid in 3D.

Example:

// Changed when the user is zooming in or out.
zoom = 1;

// Some scalar field function.
fun(x, y, z) := (x^2 + y ^2 + z^2 - 1);

// F takes vec3 instead of 3 variables.
F(p) := (fun(p.x, p.y, p.z));

// Use central difference to approximate dF.
dF(p) := (
    (F(p + [eps, 0, 0]) - F(p - [eps, 0, 0])),
    (F(p + [0, eps, 0]) - F(p - [0, eps, 0])),
    (F(p + [0, 0, eps]) - F(p - [0, 0, eps]))
) / (2 * eps);

saveisomeshtofile("mesh.stl", F, dF, 0, 1/zoom);

Adding the print UI: addcindyglprintui(‹meshfilename›, ‹updatepreviewcdyglarguments›)

Description: Adds a printing user interface to the bottom of the website. This includes both changing print settings (like the model scale) and a print preview canvas using Cindy3D. It is expected that saveisomeshtofile will be used for generating print models.

Example:

<script id='init' type='text/x-cindyscript'>
    use("CindyGL");
    use("Cindy3D");
    use("CindyGLPrint");
    addcindyglprintui("isomesh.stl", "F, dF, 0, 1/zoom");
    // ...
</script>

Updating the print preview: updatepreviewcdygl(‹F›, ‹dF›, ‹isovalue›, ‹origin›, ‹dx›, ‹nx›)

Description: The function updates the print preview added by addcindyglprintui.

NOTE: A button with the caption Update preview is automatically added to the UI when calling addcindyglprintui. Thus, this function doesn't need to be called by the programmer of a website.

Example:

updatepreviewcdygl(F, dF, 0, [-5,-5,-5], 0.01, 1001);

Updating the print preview: updatepreviewcdygl(‹F›, ‹dF›, ‹isovalue›, ‹radius›)

Description: The function updates the print preview added by addcindyglprintui.

NOTE: A button with the caption Update preview is automatically added to the UI when calling addcindyglprintui. Thus, this function doesn't need to be called by the programmer of a website.

Example:

updatepreviewcdygl(F, dF, 0, 1/zoom);