ShapeJS 2.0 Developer Documentation

Browse the ShapeJS Documentation below.

Overview

ShapeJS is a language designed to make creating and sharing 3D printable objects easy. Based on Javascript, it provides a rich set of solid modeling primitives over top a powerful voxel engine. The combination enables control of 3d printed objects down to printer resolution levels. The voxel approach has many advantages over typical triangle systems and aligns well with how 3d printers actually manufacture items. Scripts include a parameter definition to allow interactive exploration of interesting variants via an automatically generated user interface. The script, current parameters and any external resources can be saved into a simple transmittal format that others can easily load.

These docs describe the new ShapeJS 2.0 system. ShapeJS 2.0 is a major overhaul of the original ShapeJS system. Core to this release is a focus on creating real time responses. We've been prototyping several creators on the Shapeways site to prove out this point. Check out the Pendant Creator, Ornament Creator and Audio creators for examples of what's possible.

We developed ShapeJS to serve two primary communities: makers and creator creators. In the maker community OpenSCAD has shown the way in a simple but powerful scripting language for creating physical objects. They married a scripting engine to a powerful CAD kernel. For many makers this emphasis on a programming approach to 3D modeling resonated well. ShapeJS is similar in concept with a few significant differences. It is based on a voxel kernel instead of a triangle one and it’s built on a common programming language(Javascript), which is complete and used all over the world by millions of people.

To avoid a holy war I won't detail the differences too much here. Most 3D printers work by adding together small bits of material into a complete object. Using triangles to describe these voxels makes the code more difficult and harder to allow for print resolution accuracy. ShapeJS and the accompanying editor is designed to make creating 3D printable objects fast and easy. Using voxels avoids the most common reasons that 3d prints fail. Currently if you download a triangle model from most 3d repositories they typically must be repaired before printing. This is because it's very hard to write triangle code that retains the mathematical rigor necessary for 3d printing. ShapeJS will always generate manifold and oriented models that can be 3d printed. For these reasons we felt that writing a new language was warranted and would in the end prove valuable in the maker's toolbox.

The second community we wanted to target is are people who want to write object creators for others to use. We call them "Creator Creators" and we see them as a necessary enabler for 3d printing to be usable by humanity at large. A natural progression when developing an object is to parameterize its function. Similar to software an object gains features during it's development. These parameters allow the object to be used in a wider context and meet more peoples needs. A natural tendency is to want to share your creations with others. Now that many people have 3D printers at home and access to many more through printing services its become feasible to share the design for an object and expect others to be able to make it. ShapeJS provides a development environment to create those parameterizable objects and a way to share those designs with others.

The voxel based representation gives ShapeJS greater flexibility in shape generation over traditional representation via triangle meshes. It is similar to advantages 2D raster graphics has over 2D vector graphics. Vector graphics is great for drawing diagrams and raster graphics is on practice the tool of choice for anything else.

The way to fill the voxel grid is to create an object with a DataSource interface, which can calculate signed distance function for each point in space. The distance function calculations may be very complex task for complex object. But this calculation can be simplified by composing complex objects from many simpler ones using several simple operations.

There are several predefined simple object like Sphere,Box, Cylinder and Cone. More complex methods include functionality to convert 2D image to a 3D embossed object using Image3D object and importing user provided 3D object using load() function.

There is a flexible set of transformations which can be applied to any DataSource object. Transformations include standard 3D linear transformations like rotation, translation, scale, reflection. Flexibility of using volume based data allows to use arbitrary non linear transformation among those are RingWrap, SphereInversion, FriezeSymmetry, WalPaperSymmetry, ReflectionSymmetry. Several simple transformations can be composed into more complex transformation using CompositeTransform. A transformation can be applied to any DataSource object via its setTransform() method.

Script Structure

ShapeJS Scripts are Javascript programs over top the AbFab3D Voxel library. All standard Javascript functionality is supported.

Below is a simple ShapeJS program.


function main(args) {
    var r = 10*MM;
    var sphere = new Sphere(r);

    var bounds = new Bounds(-r,r,-r,r,-r,r);
    var scene = new Scene(sphere,bounds);

    return scene;
}

Click Simple Sphere to run this example.

All ShapeJS scripts should have a function main(args). This function is executed by the ShapeJS scripting engine. The main function must return a Scene object. A scene specifies how to create the object,its physical bounds and other global properties. It is possible to pass arbitrary arguments (including uploaded files) to the main(args), but we will explain this later.

The unit of length in ShapeJS is meters. To avoid awkward numbers there are a few useful conversion constants in the global scope, MM=0.001 for millimeters, IN=0.0254 for inches.

The scene bounds are the area in which ShapeJS will endeavor to display. The Bounds are a box, defined as Bounds(X minimum, X maximum, Y minimum, Y maximum, Z minimum, Z maximum). These distances are relative to the center of everything, which you will generally use as the center of your bounds as well, (0,0,0), which is also called the origin. It is the center of the scene, as well as the default center for data sources. If whatever data source you are displaying is red and cut off at its edges, this is a warning that part of it is extending out of the Bounds of your scene. To remedy this, simply enlarge the scene size. There are some performance implications for having bounds too large so try to keep them relatively minimal. An optional parameter voxelSize is the size of a grid voxel. It defines the resolution of volume rendering. A Voxel size of 0.1 millimeter corresponds to the printing resolution of most 3D printers in 2015. This parameter greatly affects speed of all calculations and the best approach is to keep it larger (0.2mm or 0.3mm) during script development and set to printer resolution only at the final stage.

Controlling parameters of output mesh

When writing triangle models from ShapeJS there are some variables that control different aspects of the operation. These parameters are set on the Scene object returned from the main function.

setMeshSmoothingWidth Width of gaussian smoothing of the grid before conversion to triangle mesh. The width is given relative the grid voxel size. Default value is 0.5.

setMeshErrorFactor is maximal error allowed during mesh decimation (reducing mesh complexity). It is given relative to voxel size. Default value is 0.1. Smaller values greatly increase the resulting mesh complexity.

setMinPartVolume allows to filter out sand size particles from the resulting mesh. All parts of volume less than meshMinPartVolume are discarded. This volume is specified in meters3. Default value is 0.

setMaxPartsCount specifies the maximum number of parts to save. The n largest parts are kept. By default all parts are retained.

Parameters

ShapeJS scripts can contain a parameter definition that defines the interface of the script. These parameters should be user facing parameters that allow changes to the object. They will typically be used in automatic user interface creation and they will be available in the IDE for you to modify.

When main is called on your script you are passed a map of the parameter values. This map contains the parameter name as the key and then the current parameter value as a native Javascipt object. These can be referenced as "args.radius" inside your script.

All parameters have the following properties:
NameDescription
nameThe name of the parameter. Must be unique in the script.
labelThe label to use in user interfaces. Defaults to name if not provided
descA textual description of the parameter, usually used in tool tips.
dataTypeThe type of data. See DataTypes section for valid values
defaultValThe default value for the parameter. JSON encoded value.
groupGrouping ID. Used to group similar properties together.
onChangeFunction to call when the value changes. Defaults to main

Data Types

The following data types are supported:

Double

A floating point number. Doubles have a default unit of measure which is M for meters. If a non default value is specified then the script will convert the value to meters when sending in the main(args) method.
    {
    name: "textHeight",
    desc: "Text Height(mm)",
    type: "double",
    rangeMin:1,
    rangeMax:1000,
    step: 0.5,
    defaultVal: 5,
    group: "Text"
    }
    
NameDescription
rangeMinThe minimum acceptable value. Defaults to -Infinity
rangeMaxThe maximum acceptable value. Defaults to +Infinity
stepThe step value to use in user interfaces such as sliders
unitThe unit of measure. Valid values are: M,CM,MM,UM,IN,FT. Defaults to M

Enum

Enumerated values. This defines a list of valid values. Example:
    {
    name: "purpose",
    desc: "Purpose",
    type: "enum",
    values: ["MESH","RENDER","PICK"],
    defaultVal: "RENDER",
    }
    
NameDescription
valuesJSON encoded list of valid string values

Location

Represents a 3D location and orientation in space. Location parameters usually implemented by allowing the user to click onto the object to place something. The default value for this type is a JSON map with two properties: point and normal. The point is a 3D position in space. The normal is the outward surface direction at that point.
Example:
    {
        name: "textpos0",
        desc: "Text Pos1",
        type: "location",
        defaultVal : {"point":[-0.024,0,0],"normal":[0,0,1]}
    }
    
NameDescription
pointMinThe minimum point value allowed.
pointMaxThe maximum acceptable value. Defaults to +Infinity

String

String values
NameDescription

URI

A URI references a resource such as an image or 3d model. A URI type will typically allow the user to use a local file from their system. It can also use fully qualified URL's to access network resources. Example:
    {
        name: "image",
        desc: "Image",
        type: "uri",
        defaultVal: "http://www.website.com/sample_image.png"
    }
    
URI's support the use of stock images and models. These are resources that are available to all scripts and are typically useful for default content.
    {
        name: "image",
        desc: "Image",
        type: "uri",
        defaultVal: "urn:shapeways:stockImage:allblack"
    }
     
Stock Media
URIDescription
urn:shapeways:stockImage:allblackAn image of all black(0,0,0) pixel values
urn:shapeways:stockImage:allwhiteAn image of all white(255,255,255) pixel values
urn:shapeways:stockImage:gradientAn image gradient that goes from black to white in a left to right direction
urn:shapeways:stockImage:smallboxAn 3d model of a 10mm box
urn:shapeways:stockImage:boxAn 3d model of a 20mm box
urn:shapeways:stockImage:smallsphereAn 3d model of a 10mm diameter sphere
urn:shapeways:stockImage:sphereAn 3d model of a 20mm diameter sphere

Mental Model

When your authoring a ShapeJS script it's helpful to understand what's going on under the covers. Your script is building up a datasource graph that describes the object. This graph is composed of datasources as the nodes. Each datasource contains a transform that locates it in and its children in space.

ShapeJS's transform graph allows for any arbitrary transformation. Unlike traditional real time graphics you are not restricted to affine transformations such as translation, scale, rotation. These are available of course but you can also do more interesting effects such as twists and infinite symmetry calculations.

Change Listeners

A parameter can contain a field called onChange. By default this just recalls the main() method with the changed parameters. If you specify a different method name then that method will be called each time the parameter is changed. These change listeners are expected to modify the current scene. This maybe faster then rerunning main each time. Currently we are looking at some caching techniques that would hopefully make authoring change listeners unnecessary.

Javascript

We use the Rhino Scripting engine in Java which implements Javascript 5. If you want specific details you can find the project documentation here: Rhino Documentation

Functions

ShapeJS has global helper functions accessible from your script.
createGrid
Create a voxel grid
createGrid(sx,sy,sz,voxelSize)
Create a grid of given size and resolution.
double sx x size of grid
double sy y size of grid
double sz z size of grid
double voxelSize The size of each voxel.
getModelBounds
Load a 3D mesh and calculates the models physical bounds. Currently supports ASCII and BINARY STL files and X3D files(.x3d,.x3dv,x3db). Returns an abfab3d.util.Bounds object. The bounds represent the axis aligned bounding box of the 3D model plus any margins. See this wiki entry for an explanation: Bounding Box
Bounds getModelBounds(filename,voxelSize,margin)
Returns a distance grid from the 3D mesh. Uses the given voxelSize
String filename The name of the file to load
double voxelSize The size of voxels to use, defaults to 0.1mm
double margin The margin around the object, default to voxelSize.
loadImage
Loads an image. Currently supports PNG and JPG. Returns an abfab3d.grid.Grid2D object.
Bounds getModelBounds(filename,voxelSize,margin)
Returns a distance grid from the 3D mesh. Uses the given voxelSize
String filename The name of the file to load
double pixelSize The size of pixels to use, defaults to 0.1mm
loadModelDensity
Load a 3D mesh into a grid. Currently supports ASCII and BINARY STL files and X3D files(.x3d,.x3dv,x3db). Currently x3d files have their color information stripped out.
Grid loadModelDensity(filename)
Returns a grid from the 3D mesh. Uses the default voxelSize of 0.1mm
String filename The name of file to load
Grid loadModelDensity(filename,voxelSize)
Returns a density grid from the 3D mesh. Uses the given voxelSize
String filename The name of the file to load
double voxelSize The size of voxels to use
Grid loadModelDensity(filename,grid)
Returns a density grid from the 3D mesh. Uses the given voxelSize
String filename The name of the file to load
Grid grid The grid to load the result into. Will overwrite filled areas with model data, unfilled areas will not be changed. The grid must be large enough to contain the object.
loadModelDistance
Load a 3D mesh and calculates the distance to the surface. Currently supports ASCII and BINARY STL files and X3D files(.x3d,.x3dv,x3db). Currently x3d files have their color information stripped out. Returns a abfab3d.datasources.DataSourceGrid object.
DataSourceGrid loadModelDistance(filename,voxelSize,maxDist)
Returns a distance grid from the 3D mesh. Uses the given voxelSize
String filename The name of the file to load
double voxelSize The size of voxels to use, defaults to 0.1mm
double maxDist The maximum distance to calculate from the surface, defaults to 1mm.
int algo The algorithm to use. Defaults to 0. Algoritm 1 is a slightly more accurate version of 0 but much slower. Algorithm 2 is the ShapeJS 1.0 original algorithm for backwards compatibility.
print
Print's a message to the console. This will be available in the IDE's console.

Variables

ShapeJS has global variables accessible from your script.
MM Conversion factor from mm's to meters.
MM3 Conversion factor from mm^3 to m^3
CM Conversion factor from cm's to meters.
IN Conversion factor from in's to meters.
FT Conversion factor from feet to meters.

Objects

Specific objects are exposed to the scripts. This section lists the objects exposed and provides links to their documentation.

Math

The standard Javascript Math object is available. W3Schools provides a nice overview here

Vector3d

ShapeJS ships with a standard vecmath library. This is the javax.vecmath package provided by Oracle. You can see view the docs here

Operations

Operations work on Grids and usually perform fairly heavyweight computations. Some of the available operations are TrimOp, ExpandOp. See the abfab3d.grid.op documentation here trimOp expandOp

Sharing Scenes

ShapeJS defines a zip format for sharing scenes. A scene contains the script, a JSON encoded params file and any URI references saved as local resources. The main script is saved as script.js. The parameter values are stored as a JSON map in params.json.

When saving a scene, any local files used will be saved into the zip container. Fully qualified URL's will be downloaded and stored in the zip as well.

Mailing List

We've setup a forum to discuss ShapeJS here

License

The core library is licensed as LGPL, available at www.abfab3d.com. Certain portions of the library which are GPU accelerated are Shapeways internal.
Data Sources
Abs
Return the absolute value of a data source.
Abs(source)
Create an Abs of a data source
DataSource source
setSource(ds)
Set the source
DataSource ds The data source
getSource()
Get the source
Add
Makes sum of 2 data sources, source1 + source2.
Add(d1,d2)
Addition of two data sources.
DataSource d1
DataSource d2
Add(d1,d2)
Addition of source1 and a constant value.
DataSource d1
double d2
Add(d1,d2)
Addition of a constant value and source2.
double d1
DataSource d2
setSource1(ds)
Set source1
DataSource ds The data source
getSource1()
Get the first source
setSource2(val)
Set source2 to a constant value
double val The constant value
setSource2(ds)
Set the second source
DataSource ds data source
getSource2()
Get the second source
Box
Solid box of given size
Box()
Construct a default box
Box(sx,sy,sz)
Box with 0,0,0 center and given size
double sx x size
double sy y size
double sz z size
Box(sx,sy,sz,rounding)
Box with 0,0,0 center and given size
double sx x size
double sy y size
double sz z size
double rounding The amount of rounding
Box(size)
Box with 0,0,0 center and given size
Vector3d size Size vector
Box(cx,cy,cz,sx,sy,sz)
Box with given center and size
double cx x coordinate of center
double cy y coordinate of center
double cz z coordinate of center
double sx x size
double sy y size
double sz z size
Box(center,size,rounding)
Box with given center, size and rounding
Vector3d center
Vector3d size
double rounding
Box(cx,cy,cz,sx,sy,sz,rounding)
Box with given center and size
double cx x coordinate of center
double cy y coordinate of center
double cz z coordinate of center
double sx x size
double sy y size
double sz z size
double rounding The amount of rounding
setSize(val)
Set the size
Vector3d val The value in meters
getSize()
Get the size
setWidth(val)
Set the height
double val The value in meters
setHeight(val)
Set the height
double val The value in meters
setDepth(val)
Set the depth
double val The value in meters
setCenter(val)
Set the center of the coordinate system
Vector3d val The value in meters
setCenter(x,y,z)
Set the center of the coordinate system
double x
double y
double z
setCenterX(val)
Set the center x position
double val The value in meters
getCenterX()
Get the center x position
setCenterY(val)
Set the center y position
double val The value in meters
getCenterY()
Get the center y position
setCenterZ(val)
Set the center z position
double val The value in meters
getCenterZ()
Get the center z position
getCenter()
Get the center of the coordinate system.
setRounding(val)
Set the amount of rounding of the edges
double val
getRounding()
Get the amount of rounding of the edges
initParams()
updateBounds()
Call to update bounds after each param change that affects bounds
Complement
Boolean complement. The datasource is the opposite of the input.
Complement(source)
Complement of the given datasource.
DataSource source object to which the complement is generated
setSource(ds)
Set the source
DataSource ds data source
getSource()
Get the source
Cone
Cone with point at apex, axis along given direction and given half angle. This Cone goes infinitely in the axis direction.
Cone()
Cone(apex,axis,angle)
Cone with apex at the given center, axis along given direction and given half angle. This Cone goes infinitely in the axis direction.
Vector3d apex Cone apex
Vector3d axis Direction of cone axis
double angle Cone's half angle
setApex(apex)
set cone apex
Vector3d apex
getApex()
Get the cone apex
setAxis(axis)
set cone axis
Vector3d axis
getAxis()
Get the cone axis
setAngle(angle)
set cone angle
double angle
getAngle()
Get the cone angle
setRounding(rounding)
set cone rounding
double rounding
getRounding()
getDistance(pnt)
Vec pnt
Constant
Return constant data value
Constant(value)
Constant of given value
double value
setValue(val)
Set the constant value
double val
getValue()
Get the constant value
Cylinder
Cylinder with given ends and radius
Cylinder(v0,v1,radius)
Circular cylinder of uniform radius
Vector3d v0 center of first base
Vector3d v1 center of second base
double radius Radius of cylinder
Cylinder(v0,v1,radius0,radius1)
Circular cylinder of variable radius from point v0 to point v1
Vector3d v0 center of first base
Vector3d v1 center of second base
double radius0 radius of base centered at v0
double radius1 radius of base centered at v1
setRadius0(r)
The the radius of vertex0
double r
setRadius1(r)
The the radius of vertex1
double r
setV0(v)
Set the vertex0 location
Vector3d v
getV0()
Get the vertex0 location
setV1(v)
Set the vertex1 location
Vector3d v
setRounding(val)
Set the amount of rounding of the edges
double val
getRounding()
Get the amount of rounding of the edges
DataSourceGrid
DataSource interface to Grid. This object shall be used if one wants to use a generated grid as a general shape. By default, grid uses linear interpolation of values between voxels.
DataSourceGrid(grid)
constructs DataSource from the given grid
AttributeGrid grid
DataSourceGrid(grid,subvoxelResolution)
obsolete
AttributeGrid grid
int subvoxelResolution
DataSourceGrid(grid,_bounds,subvoxelResolution)
params aftetr grid are obsolete
AttributeGrid grid
double[] _bounds
int subvoxelResolution
emptyCache()
setInterpolationType(value)
sets type used for intervoxel interpolation
int value of interpolation (INTERPOLATION_BOX or INTERPOLATION_LINEAR)
getInpolationType()
Gets type used for intervoxel interpolation
getGridBounds()
Get the grid bounds in meters
getGridWidth()
Get the grid width in voxels
getGridHeight()
Get the grid height in voxels
getGridDepth()
Get the grid depth in voxels
getDataChannel()
setGridDataTypeSize(val)
Set the number of bytes to use for a grid. Determines precision of rendering.
int val Currently supports 1 or 2
getGridDataTypeSize()
DataTransformer
Transform the data source. This provides a transformable wrapper for any data source. It is used when one need to appply transformation to a data source which already has its own transformation.
DataTransformer()
empty DataTransformer
DataTransformer(ds)
DataSource ds
setSource(ds)
DataSource ds data source to be transformed by this transformer
Embossing
Makes an embossing on a surface of the base shape with another source. This is similar to displacement maps in other packages. In general this technique only works well close to the surface, roughly within 2mm.
Embossing(shape,embosser)
constructor for shape and embosser
DataSource shape
DataSource embosser
setBaseShape(shape)
Set the base shape to emboss onto
DataSource shape
getBaseShape()
Get the base shape to emboss onto
setEmbosser(embosser)
Set the data source to emboss onto the base shape
DataSource embosser The source
getEmbosser()
Get the data source to emboss onto the base shape
setMinValue(val)
Set the minimum value from the base shape that the embossing will go
double val The value
getMinValue()
Get the minimum value from the base shape that the embossing will go
setMaxValue(val)
Set the minimum value from the base shape that the embossing will go
double val The value
getMaxValue()
Get the minimum value from the base shape that the embossing will go
setFactor(val)
Set the multiplication factor for the embossing.
double val The value
getFactor()
Get the multiplication factor for the embossing.
setOffset(val)
Set the offset for the embossing.
double val The value
getOffset()
Get the offset for the embossing.
setBlend(val)
Set the blending value of the base shape with the embossing
double val The value in meters
getBlend()
Get the blending value of the base shape with the embossing
Image3D
Makes 3D relief image from supplied 2D image. The shape fits into a box of the specified size. The image is placed parallel to the xy plane. The bounding box is centered at origin.

The image may be placed in 3 different places: on top side, on bottom side and on both sides.

The style of image may be embossed or engraved.

The image can by tiled (repeated) in both x and y directions finite number of times

Image3D()
Image3D(imagePath,sx,sy,sz)
Image3D with given image path and size
String imagePath path to the image file
double sx width of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sy height of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sz depth of the box.
Image3D(imagePath,sx,sy,sz,voxelSize)
Image3D with given image path and size
String imagePath path to the image file
double sx width of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sy height of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sz depth of the box.
double voxelSize size of voxel to be used for image voxelization
Image3D(image,sx,sy,sz)
Image3D with given image path and size
BufferedImage image image data
double sx width of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sy height of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sz depth of the box.
Image3D(image,sx,sy,sz,voxelSize)
Image3D with given image path and size
BufferedImage image image data
double sx width of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sy height of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sz depth of the box.
double voxelSize size of voxel to be used for image voxelization
Image3D(text,sx,sy,sz)
Image3D with given text
Text2D text text data
double sx width of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sy height of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sz depth of the box.
Image3D(text,sx,sy,sz,voxelSize)
Image3D with given text
Text2D text text data
double sx width of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sy height of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sz depth of the box.
double voxelSize size of voxel to be used for image voxelization
Image3D(imwrapper,sx,sy,sz)
Image3D with given image path and size
ImageWrapper imwrapper holder of BufferedImage
double sx width of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sy height of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sz depth of the box.
Image3D(imwrapper,sx,sy,sz,voxelSize)
Image3D with given image path and size
ImageWrapper imwrapper holder of BufferedImage
double sx width of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sy height of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sz depth of the box.
double voxelSize size of voxel to be used for image voxelization
Image3D(grid,sx,sy,sz)
Image3D with given image path and size
Grid2D grid grid representation of image
double sx width of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sy height of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sz depth of the box.
Image3D(grid,sx,sy,sz,voxelSize)
Image3D with given image path and size
Grid2D grid grid representation of image
double sx width of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sy height of the box (if it is 0.0 it will be calculated automatically to maintain image aspect ratio
double sz depth of the box.
double voxelSize size of voxel to be used for image voxelization
setSize(sx,sy,sz)
Set size of the image box
double sx The x dimension in meters
double sy The y dimension in meters
double sz The z dimension in meters
setSize(size)
Set size of the image box
Vector3d size The size in meters
getSize()
Get the size of the image box
setCenter(cx,cy,cz)
Set center of the image box
double cx The x location in meters
double cy The y location in meters
double cz The z location in meters
setCenter(val)
Set center of the image box
Vector3d val The center in meters
getCenter()
Get center of the image box
setTiles(tilesX,tilesY)
Set image tiling
int tilesX the number of X tiles
int tilesY the number of Y tiles
setTilesX(val)
Set image tilingX
int val The value
getTilesX()
Get image tilingX
setTilesY(val)
Set image tilingY
int val The value
getTilesY()
Get image tilingY
setBaseThickness(baseThickness)
Sets thickness of the solid base relative to the bounding box thickness
double baseThickness thickness of solid base relative to the thickness of the bounding box. Default value is 0.
setBlurWidth(blurWidth)
Set the blurring width to apply to the image
double blurWidth The width in meters. Default is 0.
getBlurWidth()
Get the blurring width to apply to the image
setRounding(rounding)
Set the rounding applied to the image.
double rounding The rounding in meters
setBaseThreshold(baseThreshold)
Set the threshold for determining if a pixel creates geometry. Threshold is a 0-1 double based on the incoming image intensity. Default is 0.01 which means anything not exactly black.
double baseThreshold
setVoxelSize(vs)
Set the voxel size to use for the image
double vs The voxel size in meters
setImage(val)
Object val
setImageType(type)
set options to image embossing type
int type Type ot the image. Possible values Image3D.IMAGE_TYPE_EMBOSSED (default value), Image3D.IMAGE_TYPE_ENGRAVED.
setImagePlace(place)
set options to place the image
int place of the image. Possible values: Image3D.IMAGE_PLACE_TOP, Image3D.IMAGE_PLACE_BOTTOM, Image3D.IMAGE_PLACE_BOTH Default Image3D.IMAGE_PLACE_TOP
setUseGrayscale(value)
set option to use grayscale
boolean value if true grayscale componenent of the will be used, if false iumage will be converted into black and white. the black and white option is useful if one want to have image shape with sharp vertical walls.
getPhysicalValue(attribute)
returns physical data value which corresponds to the given attribute value
long attribute
ImageMap

DataSource which fills 3D box with data from from 2D image in xy plane.

ImageMap may have multiple channels, according to the source image type

The 2D image is placed in the XY-plane and for each pixel of the image with coordinate (x,y) the column of voxel of size size.z is formed in both sides of XY plane

The image can be periodically repeated in both X and Y directions
ImageMap(imageSource,sizex,sizey,sizez)
Creates ImageMap from a file
Object imageSource source of the image. Can be url, BufferedImage or ImageWrapper
double sizex - width of the image
double sizey - height of the image
double sizez - depth of the image
setImage(val)
Set the source image
Object val
getImage()
Get the source image
setCenter(val)
Set center of the image box
Vector3d val The center in meters
getCenter()
Get the center of the image box
setSize(val)
Set size of the image box
Vector3d val The size in meters
getSize()
Get the size of the image box
setRepeatX(val)
Set whether the image repeats in the X direction
boolean val The value
isRepeatX()
Is repeatX set
setRepeatY(val)
Set whether the image repeats in the Y direction
boolean val The value
isRepeatY()
Is repeatY set
setWhiteDisplacement(val)
Set how far white pixels displace the image
double val The value in meters. Default is 0.
getWhiteDisplacement()
Get the white displacement
setBlackDisplacement(val)
Set how far black pixels displace the image
double val The value in meters. Default is 0.001.
getBlackDisplacement()
Get the black displacement
setBlurWidth(val)
Set the blurring width to apply to the image
double val The width in meters. Default is 0.
getBlurWidth()
Get the blurWidth
Intersection
Intersection of multiple data sources. The overlap of all data sources will be preserved.
Intersection()
Intersection(ds1,ds2,ds3)
DataSource ds1
DataSource ds2
DataSource ds3
Intersection(ds1,ds2)
DataSource ds1
DataSource ds2
Intersection(ds1)
DataSource ds1
add(ds)
add items to set of data sources
DataSource ds
set(idx,src)
Set an item into the list
int idx The index, it must already exist
DataSource src
clear()
Clear the datasources
setBlend(val)
Set the blending width
double val The value in meters
getBlend()
Get the blending width
Mad
Multiply-accumulate operation. Calculates: source * a + b
Mad(source,a,b)
DataSource source
DataSource a
DataSource b
Mad(source,a,b)
DataSource source
double a
double b
setA(val)
Set the value of the A param
DataSource val
setB(val)
Set the value of the B param
DataSource val
Mask
Makes a mask out of given data source. mask has values in the range (0,1) returned value is calculated from source value v as follows:
   if(v < threshold - thickness/2)
      return 1;
   else if(v > threshold + thickness/2)
      return 0;
   else // inside of the transition area
       return (threshold + thickness/2 - v)/thickness;
   
The mask is typically used to convert distance functions into density.
Mask(source,threshold,thickness)
DataSource source
double threshold
double thickness
setSource(ds)
Set the source mask
DataSource ds data source
getSource()
Get the data source
setThreshold(val)
Set the threshold
double val The threshold. Default is 0.
getThreshold()
Get the threshold
setThickness(val)
Set the thickness. Default is 0.1 mm.
double val The value in meters
getThickness()
Get the thickness
Max
Return maximal value of two data sources: max(source1, source2)
Max(source1,source2)
DataSource source1
DataSource source2
setSource1(ds)
Set source1
DataSource ds The data source
setSource2(ds)
Set source2
DataSource ds The data source
getSource1()
Get the first source
getSource2()
Get the second source
Min
Return minimal value of 2 data sources: min(source1, source2)
Min(source1,source2)
DataSource source1
DataSource source2
setSource1(ds)
Set source1
DataSource ds The data source
getSource1()
Get the first source
setSource2(ds)
Set source2
DataSource ds The data source
getSource2()
Get the second source
Mix
Linear mix of two data sources source1 + (source2 - source1)*mixer
Mix(source1,source2,mix)
DataSource source1
DataSource source2
DataSource mix
Mix(source1,source2,mix)
DataSource source1
DataSource source2
double mix
setSource1(ds)
Set source1
DataSource ds The data source
getSource1()
Get the first source
setSource2(ds)
Set source2
DataSource ds The data source
getSource2()
Get the second source
setMixer(ds)
Set mixer
DataSource ds The data source
getMixer()
Get the mixer
Mul
Multiplies two data sources: source1*source2
Mul(d1,d2)
DataSource d1
DataSource d2
Mul(d1,d2)
DataSource d1
double d2
Mul(d1,d2)
double d1
DataSource d2
setSource1(ds)
Set source1
DataSource ds The data source
getSource1()
Get the first source
setSource2(ds)
Set source2
DataSource ds The data source
getSource2()
Get the second source
Plane
Plane with with given external normal and distance from the origin the shape is half space bounded by that plane. plane normal is pointing outside of that half space
Plane()
Plane(normal,distance)
Plane is defined via external normal and distance along normal from origin.
Vector3d normal The normal to the plane
double distance The distance to the plane
Plane(normal,pointOnPlane)
Plane is defined via external normal and a point, which lies in the plane
Vector3d normal The normal to the plane
Vector3d pointOnPlane the point on the plane
Plane(pnt0,pnt1,pnt2)
Plane is defined via 3 points, which lie in the plane. External normal points into direction from which points pnt0, pnt1, pnt2 look oriented counter clock wise
Vector3d pnt0 point in the plane
Vector3d pnt1 point in the plane
Vector3d pnt2 point in the plane
Plane(nx,ny,nz,dist)
Plane is defined via components of normal and distance from origin
double nx x component of normal
double ny y component of normal
double nz z component of normal
double dist distance from plane to origin
setDistance(val)
Set the distance to the plane freom the origin
double val The value in meters
getDistance()
Get the distance to the plane freom the origin
setNormal(val)
Set the plane normal
Vector3d val
getNormal()
Get the normal
Sphere
Sphere with given location and radius.
If radius is positive the shape is interior of the sphere, if radius is negative - the shape is exterior of the sphere.
Sphere()
Sphere(radius)
sphere with given radius centered at origin
double radius
Sphere(center,radius)
sphere with given center and radius
Vector3d center
double radius
Sphere(cx,cy,cz,radius)
sphere with given center and radius
double cx
double cy
double cz
double radius
initParams()
setCenter(val)
Set the center of the coordinate system
Vector3d val The value in meters
setCenter(x,y,z)
Set the center of the coordinate system
double x
double y
double z
setCenterX(val)
Set the center x position
double val The value in meters
getCenterX()
Get the center x position
setCenterY(val)
Set the center y position
double val The value in meters
getCenterY()
Get the center y position
setCenterZ(val)
Set the center z position
double val The value in meters
getCenterZ()
Get the center z position
getCenter()
Get the center of the coordinate system.
setRadius(r)
Set the radius
double r The value in meters. Default is 1mm.
getRadius()
Get the radius
updateBounds()
Call to update bounds after each param change that affects bounds
Sub
Subtract 2 data sources: (source1 - source2)
Sub(data1,data2)
DataSource data1
DataSource data2
Sub(data1,data2)
DataSource data1
double data2
Sub(data1,data2)
double data1
DataSource data2
setSource1(ds)
Set source1
DataSource ds The data source
setSource2(ds)
Set source2
DataSource ds The data source
getSource1()
Get the first source
getSource2()
Get the second source
Subtraction
Boolean difference between two data sources
Subtraction(shape1,shape2)
shape which is result of subtracting shape2 from shape1
DataSource shape1
DataSource shape2
setBlend(r)
Set the blending width
double r
setShape1(shape1)
DataSource shape1
setShape2(shape2)
DataSource shape2
Text
makes 3D text shape from text string

Text is oriented parallel to xy plane. The bounding box is centered at origin

Text(text,fontName,sx,sy,sz,voxelSize)
String text the string to convert intoi 3D text
String fontName name of font to be used for 3D text
double sx width of the 3D text bounding box
double sy height of the 3D text bounding box
double sz thickness of 3D text bounding box
double voxelSize size of voxel used for text rasterizetion
Text(text,font,sx,sy,sz,voxelSize)
String text
Font font
double sx
double sy
double sz
double voxelSize
setFont(font)
Set the specific font. This overrides any value set in fontName
Font font The font, or null to clear
getFont()
Get the font set by setFont. This will not return a font for Text created via the fontName route.
setSize(val)
Set the size of the box.
Vector3d val The size in meters
getSize()
Get the size
setCenter(val)
Set the center of the coordinate system
Vector3d val The center
getCenter()
Get the center of the coordinate system
setRounding(val)
Set the amount of rounding of the edges
double val The rounding. Default is 0
getRounding()
Get the amount of rounding of the edges
setFontName(fontName)
Set the font name. The available fonts are system dependent.
String fontName
getFontName()
Get the font name
setFontStyle(fontStyle)
Set the font style
int fontStyle
getFontStyle()
Get the font style
setVoxelSize(val)
Set the voxel size
double val The size in meters
getVoxelSize()
Get the voxel size
Text2D
makes 3D text shape from text string

Text is oriented parallel to xy plane. The bounding box is centered at origin

Text2D(text,fontName,voxelSize)
Constructor
String text the string to convert into 3D text
String fontName name of font to be used for 3D text
double voxelSize size of voxel used for text rasterizetion
Text2D(text,font,voxelSize)
Constructor
String text the string to convert into 3D text
Font font font to be used for 3D text
double voxelSize size of voxel used for text rasterizetion
Text2D(text)
Constructor
String text the string to convert into 3D text
getFontName()
Get the font name
setFontStyle(fontStyle)
Set the font style
int fontStyle
getFontStyle()
Get the font style
setFont(font)
Set the specific font. This overrides any value set in fontName
Font font The font, or null to clear
getFont()
Get the font set by setFont. This will not return a font for Text created via the fontName route.
getVoxelSize()
Get the voxel size
setText(val)
String val
setFontName(val)
Set the font name. The available fonts are server dependent.
String val
setFontStyle(val)
Integer val
setVoxelSize(val)
Set the voxel size
double val The size in meters
setSpacing(val)
double val
getSpacing()
setInset(val)
double val
getInset()
set(param,val)
String param
Object val
setWidth(val)
double val
getWidth()
setHeight(val)
double val
getHeight()
setHorizAlign(val)
String val
getHorizAlign()
setVertAlign(val)
String val
getVertAlign()
setFit(val)
String val
getFit()
setPreserveAspect(val)
boolean val
getPreserveAspect()
validateFontName(fontName)
String fontName
Torus
Torus centered at the given point with axis parallel to z-axis
Torus(center,Rout,Rin)
Vector3d center - location of torus center
double Rout - outer radius of torus
double Rin - inner radius of torus
Torus(Rout,Rin)
torus centered at origin
double Rout - outer radius of torus
double Rin - innter radius of torus
Torus(cx,cy,cz,Rout,Rin)
double cx - x component of center
double cy - y component of center
double cz - z component of center
double Rout - outer radius of torus
double Rin - inner radius of torus
setCenter(val)
Set the center of the coordinate system
Vector3d val The value in meters
setCenter(x,y,z)
Set the center of the coordinate system
double x
double y
double z
setCenterX(val)
Set the center x position
double val The value in meters
getCenterX()
Get the center x position
setCenterY(val)
Set the center y position
double val The value in meters
getCenterY()
Get the center y position
setCenterZ(val)
Set the center z position
double val The value in meters
getCenterZ()
Get the center z position
getCenter()
Get the center of the coordinate system.
setRout(value)
Set the spine radius
double value
getRout()
Get the spine radius
setRin(value)
Set the radius of the torus tube
double value
getRin()
Get the radius of the torus tube
updateBounds()
Call to update bounds after each param change that affects bounds
Union
Union of multiple data sources. It can create union
Union()
Create empty union. Use add() method to add arbitrary number of shapes to the union.
Union(shape1)
Union Constructor
DataSource shape1
Union(shape1,shape2)
union of two shapes
DataSource shape1
DataSource shape2
add(shape)
Add item to union.
DataSource shape item to add to union of multiple shapes
set(idx,src)
Set an item into the list
int idx The index, it must already exist
DataSource src
clear()
Clear the datasources
setBlend(val)
Set the blending width
double val The value in meters
getBlend()
Get the blending width
VolumePatterns
VolumePatterns()
VolumePatterns.Gyroid
approximation to Gyroid
VolumePatterns.Gyroid()
VolumePatterns.Gyroid(period,thickness)
double period
double thickness
setPeriod(value)
double value
getPeriod()
setThickness(value)
double value
getThickness()
setCenter(val)
Set the center of the coordinate system
Vector3d val The center
getCenter()
Get the center of the coordinate system
setLevel(value)
double value
getLevel()
initialize()
noRefGuide
VolumePatterns.Lidinoid
http://en.wikipedia.org/wiki/Lidinoid
VolumePatterns.Lidinoid()
VolumePatterns.Lidinoid(period,thickness)
double period
double thickness
VolumePatterns.SchwarzP
Schwarz Primitive as defined here: http://en.wikipedia.org/wiki/Schwarz_minimal_surface#Schwarz_P_.28.22Primitive.22.29
VolumePatterns.SchwarzP()
VolumePatterns.SchwarzP(period,thickness)
double period
double thickness
VolumePatterns.SchwarzD
Schwarz Diamond as defined here: http://en.wikipedia.org/wiki/Schwarz_minimal_surface#Schwarz_P_.28.22Primitive.22.29
VolumePatterns.SchwarzD()
VolumePatterns.SchwarzD(period,thickness)
double period
double thickness
Transformations
CompositeTransform
Arbitrary chain of transformations to be applied to the point
CompositeTransform()
add(transform)
add transform to the chain of transforms
VecTransform transform
getTransformsArray()
getChildren()
FriezeSymmetry
Makes transformations to reproduce Frieze Symmetry patterns Note: This node is not implemented in ShapeJS 2.0 yet.
FriezeSymmetry()
FriezeSymmetry(type,domainWidth)
Frieze Symmetry wih specified type and domain width
int type the symetry type
Possible values are
  • FriezeSymetry.FRIEZE_II
  • FriezeSymetry.FRIEZE_IX
  • FriezeSymetry.FRIEZE_IS
  • FriezeSymetry.FRIEZE_SII
  • FriezeSymetry.FRIEZE_22I
  • FriezeSymetry.FRIEZE_2SI
  • FriezeSymetry.FRIEZE_S22I
double domainWidth width of the fundamental domain
setFriezeType(friezeType)
Set the frieze type
int friezeType
getFriezeType()
Get the frieze type
getDomainWidth()
Get the domain width
setDomainWidth(width)
Set the domain width
double width
PeriodicWrap
transform point into fundamental domain of periodic latice
PeriodicWrap(a1)
one dimensional lattice
Vector3d a1
PeriodicWrap(a1,a2)
two dimensional lattice
Vector3d a1
Vector3d a2
PeriodicWrap(a1,a2,a3)
three dimensional lattice
Vector3d a1
Vector3d a2
Vector3d a3
setOrigin(val)
Vector3d val
initParams()
getOrigin()
getA1()
getA2()
getA3()
getD1()
getD2()
getD3()
getCount()
PlaneReflection
Reflection in a plane
PlaneReflection(normal)
Plane via origin is defined via external normal.
Vector3d normal
PlaneReflection(normal,distance)
Plane is defined via external normal and distance along normal from origin.
Vector3d normal The normal to the plane
double distance The distance to the plane
PlaneReflection(normal,pointOnPlane)
Plane is defined via external normal and a point, which lies in the plane
Vector3d normal The normal to the plane
Vector3d pointOnPlane the point on the plane
PlaneReflection(pnt0,pnt1,pnt2)
Plane is defined via 3 points, which lie in the plane. External normal points into direction from which points pnt0, pnt1, pnt2 look oriented counter clock wise
Vector3d pnt0 point in the plane
Vector3d pnt1 point in the plane
Vector3d pnt2 point in the plane
PlaneReflection(nx,ny,nz,dist)
Plane is defined via components of normal and distance from origin
double nx x component of normal
double ny y component of normal
double nz z component of normal
double dist distance from plane to origin
ReflectionSymmetry

Makes transformations for reflection symmetry group generated by reflections in planes and invesions in spheres.

The fundamental domain of the group is represented as intersection of half spaces and spheres.

The generators of the group are reflections and inversions in the sides of the fundamental domain

It can be used to generate reflection groups in various geometries. See also artice on invesive geomety.

ReflectionSymmetry()
Reflection symmetry with empty fundamental domain
ReflectionSymmetry(fundamentalDomain)
Reflection symmetry with specified fundamental domain
ReflectionGroup.SPlane[] fundamentalDomain
setGroup(fundamentalDomain)
sets the fundamental fomain of the group
ReflectionGroup.SPlane[] fundamentalDomain
setIterations(count)
set max count of reflection to be used in group generation. Default value is 100.
int count
getReflectionGroup()
getPlane(normal,distance)
makes plane defined via external normal and distance from origin.
Vector3d normal external unit normal to the plane. The extenal normal points outiside of the half space used for fundamental domain definition.
double distance Distance from plane to origin. Distance may be positive or negative.
getSphere(center,radius)
makes sphere defined via center and radius
Vector3d center sphere center
double radius
  • if radius is positive - the interior of sphere is used
  • if radius is negative - the exterior of sphere is used
RingWrap

Wraps band in XZ plane about a cylinder of given radius. Cylinder axis is parallel to Y axis.

The diagram below is oriented with Y axis toward the user.

RingWrap()
RingWrap(r)
Ring wrap with given radius
double r
setRadius(r)
set radius of the wrap
double r
Rotation
performs rotation about given axis
Rotation()
identity rotation
Rotation(axis,angle)
rotation with given axis and angle. Angle is measure in radians.
Vector3d axis
double angle rotation angle is measured in radians
Rotation(ax,ay,az,angle)
rotation with given axis components and angle.
double ax x component of rotation axis
double ay y component of rotation axis
double az z component of rotation axis
double angle rotation angle is measured in radians
Rotation(axis,angle,center)
rotation with given axis, angle and center. Angle is measure in radians.
Vector3d axis
double angle rotation angle is measured in radians
Vector3d center
Scale
Performs scaling by given factor
Scale()
Identity scale
Scale(s)
Uniform scaling
double s uniform scaling factor
Scale(sx,sy,sz)
Non uniform scaling
double sx x axis scaling factor
double sy y axis scaling factor
double sz z axis scaling factor
Scale(p)
Arbitary Scale
Vector3d p vector of scale
setScale(s)
Set a uniform scale
double s
setScale(sx,sy,sz)
Set an arbitrary scale
double sx
double sy
double sz
setScale(s)
Set an arbitrary scale
Vector3d s
SphereInversion

performs inversion in a sphere of given center and radius

See inversion in a sphere.

SphereInversion()
Creates default sphere which interchanges upper half space and unit ball
SphereInversion(center,radius)
Inversion in a sphere of given center and radius
Vector3d center
double radius
SphereInversion(cx,cy,cz,radius)
Inversion in a sphere with given components of center and radius
double cx
double cy
double cz
double radius
setCenter(val)
Vector3d val
setRadius(val)
Double val
initParams()
Translation
Performs translation in space
Translation()
identity transform
Translation(p)
translation to given point
Vector3d p vector of translation
Translation(tx,ty,tz)
translation to given point
double tx x component of translation
double ty y component of translation
double tz z component of translation
WallpaperSymmetry

Makes transformations to reproduce 17 two dimensional wallpaper symmetry patterns. See Wallpaper Group. Traditional wallpaper patterns are two dimensional. However these tranformations are acting in three dimension.

The diagram below shows the shapes of fundamental domain used for each of 17 groups. Fndamental domain is dark gray shape, which fills the whole plane using symmetry operations marked along the boundary of fundamental domain

    the symmetry operations are the following.
  • Bold lines are mirror (or reflection) lines
  • dotted lines - glide reflection
  • Polygons reperesent rotation axes
    • rhombus 2-fold rotation
    • triangle 3-fold rotation
    • square 4-fold rotation
    • hexagon 6-fold rotation

The WallpaperSymmetry fills the whole plane with copies of fundamental domain using transformation shown in the diagram.

The notations used for wallpaper groups are orbifold notations.

WallpaperSymmetry()
default constructor with default symmetry type WallpaperSymmetry.WP_S2222;
WallpaperSymmetry(symmetryType)
constructor with given symmetry type
int symmetryType possible values are
  • WallpaperSymmetry.WP_O
  • WallpaperSymmetry.WP_XX
  • WallpaperSymmetry.WP_SX
  • WallpaperSymmetry.WP_SS
  • WallpaperSymmetry.WP_632
  • WallpaperSymmetry.WP_S632
  • WallpaperSymmetry.WP_333
  • WallpaperSymmetry.WP_S333
  • WallpaperSymmetry.WP_3S3
  • WallpaperSymmetry.WP_442
  • WallpaperSymmetry.WP_S442
  • WallpaperSymmetry.WP_4S2
  • WallpaperSymmetry.WP_2222
  • WallpaperSymmetry.WP_22X
  • WallpaperSymmetry.WP_22S
  • WallpaperSymmetry.WP_S2222
  • WallpaperSymmetry.WP_2S22
WallpaperSymmetry(symmetryType,width,height)
constructor with given symmetry type and size of fundamental domain
int symmetryType possible values see above
double width width of fundamental domain
double height height of fundamental domain
setDomainWidth(width)
double width width of fundamental domain.
setDomainHeight(height)
double height height of fundamental domain (if used).
setMaxCount(maxCount)
int maxCount
setDomainSkew(skew)
double skew skew parameter of fundamental domain (if used)