This blog highlights a series of videos which demonstrate a variety of different functional areas in Polygonica based around creating lattice structures and reading and writing 3MF.
But first a digression ...
Did software engineers choose the name 3MF?
I ask that question for the simple reason that in many programming languages, including C, C++ and C#, a variable name can't start with a number. This quickly becomes incredibly frustrating when you're trying to write readable code that takes 3MF files and squirts the data into another system - in this case Polygonica.
But, putting that lame attempt at an eye-catching opening paragraph aside, the core of 3MF is a nicely specified format for working with polygon meshes. However given the amount of negative press the STL file format has received recently, it's odd to note that it's not really all that different to its more celebrated cousin.
The base geometry of both the STL file format and the core of 3MF is a boundary/surface mesh formed of planar polygons. One of the main differences is how those polygons are connected up.
In STL there is just a list of vertex coordinates for each polygon. If two polygons share a vertex, that vertex appears twice in the file, not once. When reading an STL the vertex sharing needs to be inferred by comparing vertex coordinates in floating point and making a decision as to whether two such numbers are equal or otherwise.
In 3MF there is an array of indices referencing common vertices. This allows the connectivity between polygons to be expressed explicitly and unambiguously. STL can be thought of as an OpenGL VBO or a DirectX vertex buffer, and 3MF can be thought of as also providing the indexed equivalents - VBO indexing in OpenGL and vertex index buffers in DirectX.
Obviously 3MF also contains multiple build items, instancing and metadata, all of which is very important for manufacturing. But, should you wish, you could create a nice new format by storing that metadata in an XML file along with references to multiple STL files, then zip the lot up and change the file extension. Yes, it still wouldn't be as nice, nor as useful, as the core of 3MF, but it wouldn't be all that different either.
This zip trick is used by many major file formats including Microsoft Office's .docx, .xlsx etc, Autodesk's DWF / DWFx, and indeed by 3MF itself.
But that's a way big digression.
What's this blog really about?
Well, an alternate title was "lattices, slices and 3MF" but that seemed a little dull. This blog brings together four videos, which you may already have seen if you follow Polygonica on LinkedIn.
- The use of PFSolidMultipleUnion to rapidly union together lots of mesh instances to create larger explicit lattice structures.
- The use of PFWorldCreateSlices, along with PFProfileUnion, PFProfileSubstract and PFProfileIntersect to do similar, creating slices without ever creating the full 3D mesh.
- Our new (unsupported) example code for reading and writing 3MF (Yay!)
- Our new (unsupported) example code for reading and writing the very interesting 3MF Beam Extension.
The workflows demonstrated in each video are described below.
Creating complex lattices using PFSolidMultipleUnion.
In this workflow we create a lattice by creating some repeatable base geometry within a cuboid e.g. an explicit mesh representing a small number of beams and nodes arrange in a grid or a diamond. These are each a PTSolid in Polygonica. Many repeated instances of this base geometry are created, each as a PTWorldEntity with a PTTransform applied to reposition them at the correct location.
Then the whole lot is thrown into PFSolidMultipleUnion, which creates new mesh geometry from the instances where needed and then performs a supermassive Boolean union operation to glue everything together. If asked to, the API also helpfully destroys anything that's no longer needed.
The multiple union operation is multi-threaded internally and the various optimisations that make the Polygonica Boolean so fast for a pair of meshes are applied to many meshes at once.
After creating the cuboid lattice, the target solid is offset (PFSolidOffset) and the lattice is clipped to the interior region (PFSolidIntersect). Then the target solid is hollowed by subtracting the offset surface (PFSolidSubtract) and the final part created by unioning the clipped lattice with the hollowed solid (PFSolidUnion).
Watch the video to see some live examples.
Slicing complex lattices without creating them in 3D.
This alternate workflow is aimed at demonstrating the often overlooked 2D capabilities of Polygonica. As before a base mesh is created and then full lattice is specified by creating PTWorldEntity instances with transforms. However, instead of joining them together in 3D, the instances are added to a new PTWorld, and then they are all sliced in one multi-threaded operation using PFWorldCreateSlices. This useful API has the option to union together any intersecting portions of profile. In this case you get the same result as if you had called PFSolidMultipleUnion followed by PFSolidCreateSlices, but there is no requirement for the relatively computationally expensive 3D union operation.
As with the 3D case described above, the 2D profile operations PFProfileOffset, PFProfileIntersect, PFProfileSubtract and PFProfileUnion are used to clip the lattice, hollow out the part and then join the lattice to the hollowed part, but they are performed on a per slice basis, rather than on the 3D mesh.
The process is described in more detail and demonstrated in this video ...
3MF Core Read and Write
As already noted the core of the 3MF format is based on polygon meshes. We regularly get requests from customers to support 3MF in Polygonica. So far these requests have not been actioned as the intention is to keep the focus of the core development team on generating innovate algorithms that work on meshes, and not divert them to develop, and more importantly maintain, supporting code at the application level.
However the job of the Consulting Engineering team is to improve the experience of software developers who are using the Polygonica API, often for the first time. In that context providing example source code to read and write from 3MF should make at least some people's lives easier.
The video below demonstrates loading and saving meshes using the extremely helpful lib3mf libraries on github and we must pass on thanks to those developers who have provided and maintain this resource.