|Version||0.8||Author(s)||Addam Dominec (Emu)|
|Current version download||https://github.com/addam/Export-Paper-Model-from-Blender/|
|Python modules||mathutils, bgl|
This script generates a flat net of a given mesh. It creates SVG files suitable for direct printing and paper modeling. The main goal is a maximal possible automation of the whole process. Common tasks like baking the model's texture into the output document are also offered by the UI.
- Download the file directly from the Git repository. If you directly use the "Save Link as..." function of your web browser, it should work. Or you can open the link and use "Save Page as...", just make sure that the file name ends in ".py".
- Launch Blender. In User Preferences (CtrlAltU), section Addons, click the Install From File... button below. Choose the file you downloaded. Then find an addon called Import-Export: Export Paper Model and enable it.
Select the mesh you want to export so that it is the active one. If you want to get results quickly, just execute this script from the File → Export menu (or find the Export Paper Model operator in the Space menu). It will ask for a file name and do everything else automatically. All related settings are in the bottom left corner. These are described in more detail below.
If you are somehow unhappy with the generated net, you can edit it manually. For this, you have to execute the Make Unfoldable operator first (available in the 3D View Toolbox or via the Space menu). Edges that will be cut in order to flatten the mesh must be marked as edit mode seams. You can use Clear Seam and Mark Seam tools to organize them as you wish. If you export the model afterwards, it will take the given seams and add some more cuts as necessary.
You can call the Make Unfoldable operator just to have a preview of the net. It will list all islands of the produced net in 3d View T toolbox and if you enable so in the operator's settings, it will also create an UV layout showing the islands. Note that island positions are not calculated, so that they will just lay on top of each other. You can use Blender's Pack Islands operator to see them all.
N-gon faces that are not perfectly flat will not get exported correctly and may distort the whole net. You will not be warned about that (except for a messy message in the console), so if you have a suspicion, better convert the mesh to triangles (CtrlT).
Exporting Textured Meshes
To export your model with a texture on it, switch the Textures dropdown menu during export (it is displayed along with the file chooser dialog) to Face Texture. The object should be exported as it looks like in the viewport in Textured shading mode.
You have several options how to include the images in the file. These are explained several paragraphs below.
The script cannot process the texture directly; rather, it exploits Blender's bake render functionality to do so. The script makes an attempt to sanitize all the related settings so that the result does not depend on their original state. If you find something (a switch in the properties panel, perhaps) that breaks the export, please report it to the Issues tracker on Github or in the BlenderArtists thread.
3d View Toolbox
The Paper Model tab in the toolbox offers two buttons for calling the Make Unfoldable and Export Paper Model operators conveniently.
Once the Make Unfoldable operator is called, the model is split into islands and these are presented in a list between the two buttons. The list allows you to change the label of each island, but that currently has no effect (but will in the future).
If you select an island and enable the Highlight Selected Island button (and the mesh you unfolded is the active one), the island will be highlighted in orange in the 3d View. Using the slider below, you can change the highlighting opacity.
Make Unfoldable Operator
The first option is Create UVMap. If enabled, a new UVMap will be generated to show all the islands. However, their positions are not calculated yet at this time of the export process, so they are all just placed in the bottom left corner. They are all in the same scale, which need not correspond to their scale during export. This option is useful when editing the cutting lines by hand. You can use the Unwrap operator to get a similar result.
The operator has three sliders, which all adjust edge cutting priority (namely: Face Angle Convex, Face Angle Concave, Edge Length). A high value gives an edge with the corresponding property more chance to be cut. Because of that, it is usually better to set Edge Length to a negative value, letting long edges stay connected. Blindly moving them may often help to reduce the count of islands in the net. For information about the meaning of these values, read the How It Works → Make Unfoldable part of this document.
Export Paper Model
When the export is initiated, the script silently unfolds the mesh (without marking any seams) and divides all faces into islands, which may take a few seconds for complex meshes. Then, a file select window is displayed. The file name you choose will get a "_page<number>.svg" suffix, even if only one page was needed. If images are needed, they are saved under the same name with an extension ".png".
Settings of this operator are presented in the bottom left corner of the file select window.
Model Scale can be used to scale the whole net. It is very important because currently the script often produces islands bigger than the page. By default, it is set so that even the biggest island fits the page size. If set to one, the real model should have the same dimensions as the virtual one.
Create UVMap has a similar effect as the eponymous option of the Make Unfoldable operator, but not the same. It will create a new UV Map that exacly reflects the placement of all the model's islands. Unfortunately, islands from all pages are placed atop of each other, since it is not easy to group them apart.
Settings closely related to the format of the output document are in the frame Document Settings.
First list box allows you to choose one of the most common paper sizes quickly. If you need something else, choose User Defined and
The Page Margin makes it easier to export models in exact scale (if you set the Model Scale slider to 1). You can set it to the width of the non-printable border of your printer, in order for the resulting SVG document to be printable without further scaling. However, exporting in-scale models is still difficult, as the script does not automatically split oversize islands.
The next value is DPI, which defines the overall resolution of the net. That is, not only resolution of baked images (if any), but also line thickness.
Create Tabs controls if the sticking tabs are created at all. For example, uncheck this if you want to stick the model using duct tape.
Create Numbers adds numbers to some edge pairs that are to be sticked together. These numbers are excluded if the correct destination is easy to guess from the neighboring edges. However, the resulting SVG will be bigger and may not render correctly in some programs. Disabling this option may help solve such issues. If Create Tabs is disabled, the numbers will be rendered inside of the net.
Tabs and Text Size sets maximal width of the sticking tabs around islands. The actual size of each tab is adjusted to be at most half the length of the corresponding edge. In some special cases, tabs are made not to overlap with real faces, but it does not work reliably yet. If Create Tabs is disabled, this slider controls the size of numbers on edges.
The Textures drop-down menu lists options for exporting textured meshes. By default, it is switched to No Texture, which just creates the net on a white background (it used to be called Pure Net). The remaining options invoke Bake Render and therefore are noticeably slower. Face Texture exports the image that is assigned to each of the model's faces (regardless of their material), likely as you see it in the Texture Paint mode. Full Render and Selected to Active correspond to the respective Bake Render options. They both render all the materials and illumination: Full Render renders the model only, while Selected to Active projects other nearby selected objects onto the model. It may be helpful for creating patterns such as fur or leaves procedurally.
The Images drop-down menu allows you to choose how to include the baked images in the SVG file. If you want to edit the layout of the net in an SVG editor, choose either Linked or Embedded. The Embedded option creates stand-alone SVG files, making them bigger but portable.
A plentiful of options related to the drawing style is packed in the Colors and Style frame. I believe these are all self-explanatory. Please note that the line width is in units of pixels, so increasing the DPI option above makes the lines thinner.
Feature requests, bug reports and all other constructive comments are most welcome. A publicly accessible TODO list is managed along with the git repository. Or if you prefer so, you may comment on the script at Blenderartists.org thread.
How It Works
Firstly, the algorithm assigns every edge a "priority", depending on its angle and length. Edges with higher priority will more probably be cut apart in the final net. Shorter edges have higher priority (they are easier to glue on) and sharper angles too (that makes the net easier to understand).
Faces form a concave angle if their normals are pointing against each other. Such angles have even a bit higher priority, because they need to be cut in many typical models. If face normals are flipped, the algorithm thinks their angle is always convex (as there is no way to tell until the whole net is produced).
If more than two faces are connected by an edge, two of them are chosen arbitrarily as the main ones and all others will have to be glued.
The actual priority effect of each of these properties may change the resulting net very much. The default values were chosen as good for common models, but may be a bad choice for others. If you want to tweak them, the Make Unfoldable operator allows you to: they are the operator's three only settings.
The cutting algorithm begins with all faces separated and tries to connect them to form bigger islands, ordered by the connecting edge's priority. If some of the faces of the resulting island would overlap, the operation is canceled and the algorithm continues with another edge. The process stops as soon as all edges of the mesh have been visited.
The overlap check is basically Bentley-Ottmann algorithm for line segment intersection. It is reliable and quick, but does not detect face overlaps that do not consist of any lines crossing each other. Such cases are fortunately extremely rare, but have to be fixed manually if they occur (it may happen to geometrically precise and at least partially concave solids).
Positioning the Nets on Pages
Because the nets are not consisting only of the real faces, but also of the gluing tabs around, they cannot be positioned by the internal Blender operator (Pack Islands). Therefore, a stand-alone algorithm had to be written.
For a great simplification of the process, all nets are packed into (smallest possible) bounding rectangles. These are then ordered by size (largest first) and in this order they are tried to be placed on a page. When any of them is placed, a buffer of free space (also saved as rectangles) is updated: the used one gets removed, two new rectangles are added and all others that overlap with the new net are cut off (see images 1b, 1c below). The free space cache is used to determine quickly whether a given rectangle can be placed on the page.
When there are any rectangles left that could not be placed onto the page, a new free page is created.
Polygon packing is a very difficult problem and no simple and good algorithm is yet known. However, the one used is really stupid. One of its problems that could be solved is that "free space rectangles" that have the left-lower corner flowing in free space will not be recognized at all (see images 2a, 2b). Unfortunately, these are often the biggest rectangles on the page.