JMesh

JMesh is a JSON-based portable and extensible file format for the storage and interchange of unstructured geometric data, including discretized geometries such as triangular and tetrahedral meshes, parametric geometries such as NURBS curves and surfaces, and constructive geometries such as constructive solid geometry (CGS) of shape primitives and meshes. Built upon the JData specification, a JMesh file utilizes the JSON and Universal Binary JSON (UBJSON) constructs to serialize and encode geometric data structures, therefore, it can be directly processed by most existing JSON and UBJSON parsers. The JMesh specification defines a list of JSON-compatible constructs to encode geometric data, including N-dimensional (ND) vertices, curves, surfaces, solid elements, shape primitives, their interactions (such as CGS) and spatial relations, together with their associated properties, such as numerical values, colors, normals, materials, textures and other properties related to graphics data manipulation, 3D fabrication, computer graphics rendering and animations.

JMesh file example
The following mesh (a tetrahedral mesh of a unit cube) contains 8 3-D vertices, 12 triangular faces and 6 tetrahedral elements



The above mesh can be stored in the JMesh/JSON format as The optional  record can contain additional metadata according to JData specification.

Instead of using dimension-specific mesh data constructs, i.e.,  , and  , one can also replace those with the corresponding flexible mesh data containers,  ,  , and  , respectively. It is recommended to add  in the   metadata header to help parsers correctly process the numerical data in each entry.

Alternatively, according to JMesh and JData specifications, the above JSON-styled 2-D arrays can be stored as a structure using JData annotated N-D array format to add additional binary data type support, as below

For large mesh data files, record-level compression is supported via the JData specification. Just for illustration purposes, the above JMesh data can also be written as where the strings in  store the row-major serialized, Zlib-compressed and Base64 encoded binary stream of the raw binary array data in the precision specified in. Record-level data compression may offer significant size reduction in storing large mesh files.

JMesh syntax
All JMesh files are JData specification compliant. Same as JData, it has both a text-format based on JSON serialization scheme and a binary format based on the UBJSON serialization scheme.

Nearly all supported mesh data containers (i.e. named JData nodes) can be defined using one of the two forms: an N-D array or a structure.

Array form
For simple data, one can use the "array form" to store the data under a JMesh keyword. In such case, the format of the data must follow the "N-Dimensional Array Storage Keyword" rules defined in the JData specification. For example, one can store a 1-D or 2-D array using the direct storage format as or using the "annotated storage" format as

Structure form
One can also use a JData structure to store the primary data as well as to support additional metadata associated with the container. For example, a structure-based container may have the below subfields: Only the  subfield is required, and it must have the same data stored in the "array form" (either in direct or annotated format) as shown above.

The optional  subfield allows one to store additional data with this shape/mesh element. The  subfield can be an array or structure with additional subfields.

The optional  is the JData construct for storing metadata associated with this structure. It can be used to store simple metadata, such as data acquisition date, operator name, or version number. The strategies how to split the metadata between  and   is user-dependent.

Summary of JMesh keywords
Most of the data container keywords associated with discretized geometries have a prefix of ; keywords associated with parametric shape constructs have a prefix of  ; keywords associated with constructive solid geometries have a prefix. Many of the keywords ends with a numerical value which typically represents the column number of the data when stored in the array format.


 * Mesh grouping:,  ,
 * Vertices:, , ,
 * Lines:, ,
 * Surfaces:, , ,
 * Solid:, , ,
 * Flexible containers:, , ,
 * CSG operators:, , ,
 * Texture:, ,
 * 2-D shape primitives:, , , ,  , ,
 * 3-D shape primitives:, , , ,  , , , , , ,    , ,
 * Extrusion and revolving:, ,
 * Properties:, , , ,

Vertices
"MeshVertex1": [x1,x2,x3,...]
 * defines a 1-D position vector. It must be defined as an N-by-1 or 1-by-N numerical vector, where N equals to the total number of vertices. The values in this vector shall be the coordinates of the 1-D vertices.
 * defines a 2-D position vector. It must be defined as an N-by-2 numerical array where N is the total number of vertices. Each row of this array contains the coordinates of the vertex.
 * defines a 3-D position vector. Similar to MeshVertex2, it must be defined as an N-by-3 numerical array.

Line segments and curves
"MeshPolyLine": [N1, N2, N3, ... ]
 * defines a set of line segments using an ordered 1-D list of node indices (starting from 1). It must be defined by an 1-by-N or N-by-1 vector of integers. If an index is 0, it marks the end of the current line segment and starts a new line segment from the next index.
 * defines a set of line segments using a 2-D array with a pair of node indices in each row of the array. It must be defined by an N-by-2 integer array, where N is the total number of edges.

Surfaces

 * defines a discretized surface made of triangles with a triplet of node indices in each row of the array. It must be defined by an N-by-3 integer array, where N is the total number of triangles.
 * defines a discretized surface made of quadrilateral with a quadruplet of node indices in each row of the array. It must be defined by an N-by-4 integer array, where N is the total number of quadrilaterals.
 * defines a discretized surface made of polygons (piecewise linear complex) of uniform or varied edge sizes. It must be defined by an array with elements of integer vectors of equal or varied lengths.

Solid Elements
The first 4 columns of the array specifies the indices of the 4 vertices of the tetrahedron, identical to, and the last 6 columns of the array specifies the mid-edge node indices, sorted in the below order: [N1, N2, N3, N4, N12, N13, N14, N22, N23, N34]
 * defines a discretized volumetric domain made of tetrahedral elements, with each element made of a quadruplet of node indices. It must be defined by an N-by-4 integer array, where N is the total number of tetrahedra.
 * defines a discretized volumetric domain made of 8-node hexahedral elements, with each element specified by a 8-tuple node index. It must be defined by an N-by-8 integer array, where N is the total number of hexahedra.
 * defines a discretized volumetric domain made of 5-node pyramid elements, with each element specified by a 5-tuple node index. It must be defined by an N-by-5 integer array, where N is the total number of pyramid.
 * defines a discretized volumetric domain made of 10-node straight-line tetrahedral elements, with each element specified by a 10-tuple node index. It must be defined by an N-by-10 integer array, where N is the total number of 10-node tetrahedra.

Flexible mesh data containers
Flexible mesh data containers allow one to encode a wide range of mesh data using a simple 2-D array.
 * defines a flexible container for the storage of vertex coordinates and the associated properties. It must be defined by an N-by-M array, where N is the number of vertices, and M is the number of coordinates (D) plus the number of numerical properties (P) attached along each vertex, i.e. M = D + P
 * defines a flexible container for the storage of fix-node-length surface patches and the associated properties. It must be defined by an N-by-M array, where N is the number of surface elements, and M is the number of vertices per element (K) plus the number of numerical properties (P) attached along each vertex, i.e. M = K + P
 * defines a flexible container for the storage of variable-node-length surface patches and the associated properties. Similar to, it must be defined by an array with elements of integer vectors, but it can contain additional metadata in each element. For each vector representing a surface patch, the first non-numerical entry, for example, a structure or sub-array, of the vector marks the start of the property data.
 * defines a flexible container for the storage of volumetric elements and the associated properties. It must be defined by an N-by-M array, where N is the number of surface elements, and M is the number of vertices per element (K) plus the number of numerical properties (P) attached along each vertex, i.e. M = K + P

Shape primitives
"ShapeBox2": {"O":[x0,y0], "P": [x1,y1]} "ShapeDisc2": {"O":[x0,y0], "R": r} "ShapeEllipse": {"O":[x0,y0], "R": [r1,r2], "Angle":theta0} "ShapeLine2": {"O":[x0,y0], "V": [v1,v2]} "ShapeArrow2": {"O":[x0,y0], "V": [v1,v2], "Size": s} "ShapeAnnulus": {"O":[x0,y0], "R": [r1,r2]} "ShapeGrid2": {"O":[x0,y0], "P": [x1,y1], "Step":[Nx,Ny]} "ShapeLine3": {"O":[x0,y0,z0], "V": [v1,v2,v3]} "ShapePlane3": {"O":[x0,y0,z0], "N": [v1,v2,v3]} "ShapeBox3": {"O":[x0,y0,z0], "P": [x1,y1,z1]} "ShapeDisc3": {"O":[x0,y0,z0], "R": r, "N"=[v1,v2,v3]} "ShapeGrid3": {"O":[x0,y0,z0], "P": [x1,y1,z1], "Step":[Nx,Ny,Nz]} "ShapeSphere": {"O":[x0,y0,z0], "R": r} "ShapeCylinder": {"O":[x0,y0,z0], "P":[x1,y1,z1], "R": r} "ShapeEllipsoid": {"O":[x0,y0,z0], "R": [rx,ry,rz], "Angle":[theta0, phi0]} "ShapeTorus": {"O":[x0,y0,z0], "R": r1, "Rtube": r2, "N":[v1,v2,v3]} "ShapeCone": {"O":[x0,y0,z0], "P": [x1,y1,z1], "R": r}
 * ShapeBox2: A 2-D axis-aligned-bounding-box (AABB) defined by the two diagonal points ("O" as one end and "P" as the other end)
 * ShapeDisc2: A 2-D disc defined by the center ("O") and radius "r"
 * ShapeEllipse: A 2-D ellipse defined by the center ("O"), x and y axes in the un-rotated coordinate system ("rx" and "ry"), and rotation angle "theta0"
 * ShapeLine2: A 2-D line defined by one point along the line ("O"), and a 2-D vector ("V") aligns with the direction of the line
 * ShapeArrow2: A 2-D arrow object defined by one point along the line ("O"), and a 2-D vector ("V") aligns with the direction of the line, and the arrow-head size is indicated by scalar "s"
 * ShapeAnnulus: A 2-D annulus defined by the center ("O"), and the outer radius (r1) and inner radius (r2)
 * ShapeGrid2: A 2-D grid defined by the one end of the diagonal line ("O"), and the other end ("P"); the numbers of segments along the first and second coordinates are indicated by "Nx" and "Ny", respectively
 * ShapeLine3: A 3-D line defined by one point along the line ("O"), and a 3-D vector ("V") aligns with the direction of the line
 * ShapePlane3: A 3-D plane defined by one point along the line ("O"), and a 3-D vector ("N") pointing to the normal direction of the plane
 * ShapeBox3: A 3-D axis-aligned-bounding-box (AABB) defined by the two diagonal points ("O" as one end and "P" as the other end)
 * ShapeDisc3: A 3-D disc defined by the center ("O") and radius "R"; the normal direction of the disc is specified in "N"
 * ShapeGrid3: A 3-D grid defined by the one end of the diagonal line ("O"), and the other end ("P"); the numbers of segments along the x/y/z coordinates are indicated by "Nx", "Ny" and "Nz", respectively
 * ShapeSphere: A 3-D sphere defined by the center ("O") and radius "r"
 * ShapeCylinder: A 3-D cylinder defined by one end of the cylindrical axis ("O") and the other end of the axis "P"; the radius of the cylinder is specified in "r"
 * ShapeEllipsoid: A 3-D ellipsoid defined by the center position ("O"), x, y and z axes in the pre-rotated coordinate system (rx, ry, rz), and the azimuthal rotation angle theta0 and zenith rotation angle phi0
 * ShapeTorus: A 3-D torus defined by the center of the torus ("O"), the radius of the torus (r1) and the tube radius (r2) and the normal direction vector "N"
 * ShapeCone: A 3-D cone defined by the center of the bottom circle of the cone ("O"), the radius of the bottom circle (r) and the tip position "P"

Software library
Because JMesh specification is defined base on the JData specification, it shares the same underlying data serialization formats, i.e. JSON for text-based JMesh files (.jmsh) and BJData/UBJSON for binary-based JMesh files (.bmsh). Most existing JSON parsers can readily parse the text-based JMesh files, and similarly, existing UBJSON parsers can be used to parse .bmsh files without modification.

In MATLAB/GNU Octave, saving mesh data to the JMesh format is supported in Iso2Mesh - a 3-D mesh generation toolbox - via the  function.