Add-on to fit a cylinder to vertices

I previously updated two small add-ons that can fit a line or a plane to a collection of vertices and was asked if it was possible to create an add-on that fits a cylinder.

That is a bit more challenging though, but luckily there are people who spend some serious time on designing an algorithm and even providing code (see references below).

Based on that I created a small add-on that can indeed fit a cylinder to a collection of selected vertices. Note that it fits a cylinder where the vertices lie as closely as possible on the surface of the cylinder (see image). If you want to fit a cylinder that encloses all vertices, so more of a solid rod, simply use the linefit add-on and align a cylinder to the best fit line.


Usage

Simply download cyclinderfit.zip from the repo and install and enable the add-on from this zip-file.

Then select the mesh with the vertices you want to fit the cylinder to and select Fit cylinder from the Add menu (in edit mode). The new cylinder object will be added as a separate object that will be in edit mode.

Code availability

The code is available in this GitHub repository.

References

The cylinder fitting code was adapted from code in Xing Jiepan's repo, which in turn was based on the algorithms described in this paper by David Eberly.

To remove dependencies on external packages (except numpy, which is included with Blender), we replaced calls to the scikit.optimize.minimize function with a different implementation of Powells' minimization function from the Sherpa code-base of the Chandra project. 














Planefit.py and linefit.py updated for Blender 4.x

Always happy to see any of my add-ons being used, even if it's a really old one, so based on a BlenderArtists request I updated planefit.py and linefit.py.





Planefit adds a plane (=face) to your mesh that fits any selected vertices as well as possible (details in this post), and linefit is similar and adds a line (=edge) (details here). The articles also explain the math involved a bit if you are interested.

The updated add-ons can be found on GitHub:


Both add-ons can be downloaded in the same manner: Near the top right of the linked pages is a download button; click it to save the .py file, then (re)install the add-on in the usual manner.

Technical details

For any nerds out there: even though the commits seem large, that's mainly because I now use the Black formatter in all my Python projects so lots of whitespace was changed 😁. The actual change to planefit.py was only 1 line (the current line 116): the loop_total property of a polygon is read only nowadays so we cannot (and need not) set it: It is automatically updated when we add the vertex indices.

The change to linefit.py was a bit more involved, mainly because it was even older: Properties in an Operator are now annotated class variables (and have been since version 2.8 I think), so we had to change line 53 from

size = bpy.props.FloatProperty( ....

to

size : bpy.props.FloatProperty(...

A small but necessary change that does not even give you a warning anymore, so something to look out for if you revisit very old add-ons.

Likewise, the function bpy.utils.register_module() doesn't exist anymore and had to be replaced by bpy.utils.register_class()


Blender Market Black Friday Cyber Sale

 

Of course BlenderMarket does Black Friday and my add-ons are in it too. Check my BlenderMarket shop if you were thinking about purchasing one. Whether you think it's all commercial bullshit or not, there are some nice discounts to be had 

WeightLifter add-on updated for Blender 4.0

WeightLifter has been been updated for 4.0 compatibility. It has been tested with the daily built of November 3rd  and only minor modifications were needed to make it compatible. If you still encounter a bug, please let me know so that I can have a look at it.

WeightLifter is available on BlenderMarket. This update is free for customers who bought previous versions of WeightLifter.

WeightLifter is an add-on that can calculate all sorts of information and store this into vertex groups or vertex color layers. It can for example determine the visibility of vertices for a certain camera or the distance to some light source and much, much more (the add-on comes with a 30 page fully illustrated manual), information that can for example be used as a density map in particle systems. You can even bake this information if your scene is animated. 

The future

The code in the add-on is very old (9 years, which in Internet terms is ancient) and it does show its age in the way it is structured and also, as I experience myself, it is not very fast, especially on large meshes.

I was tempted to modernize it, and improve its speed if possible, but this might also be an opportunity to add features. So if you have an idea or suggestion, please drop me a note in the contact box at the top right of the page or via BlenderMarket and I'll be happy to consider it.

IDMapper add-on ported to Blender 4.0

 


I am pleased to announce that IDMapper is now available for Blender 4.0. 

It has been tested against the daily of November 3rd, but I expect no changes will be needed for the 4.0 release candidate or the final release.

Blender 4.0 introduced quite a few breaking changes, so this version is not backwards compatible with 3.x

Although no new functionality was introduced in this release, please be aware of the following:

  • IDMapper can currently not work with facemaps, because they are no longer supported in 4.0. This may change in the future (hopefully, see this discussion) and if possible I will try to get this back into IDMapper. Meanwhile, I did create a small, free add-on to make selecting faces from facemaps possible in 4.0 which may be useful in some workflows.
  • Color picking in Face Paint Mode (with the S-key) is no longer restricted to the 3d-View area, so colors can be picked from anywhere in the Blender application (although still not outside of it).

IDMapper simplifies creation and editing of vertex color layers that can be used as ID-maps in texturing software like Substance Painter or Quixel. It aims to reduce the time it takes to create an ID-map significantly, especially for complex hard surface models. It uses powerful heuristics to create an ID-map from scratch and lets you interactively adjust the results. It offers options to use existing information, like uv-seams, but can also intelligently assign the same color to similar mesh parts. 

The new version is available on BlenderMarket.

This previous article showcases some of IDMapper's functionality.

Snap! add-on ported to Blender 4.0

Snap! has been updated to run on Blender 4.0.

It has been tested against the daily of November 3rd, but I expect no changes will be needed for the 4.0 release candidate or the final release.

Blender 4.0 introduced quite a few breaking changes, so this version is not backwards compatible with 3.x

For an introduction to Snap! see this article and for the new functionality added in the April 2022 release, see this article. Both articles have links to demo videos as well.



Snap! is a time saving tool for people who often work with modular assets packs or creators of asset packs who want to make there product easier to use.

Snap! allows you to define snap-points with a predefined location and orientation on objects which can then be used to interactively snap objects together without the hassle of precise positioning.

Snap! is available in a personal and a redistributable version on my BlenderMarket shop.

Adding selecting from face maps to Blender 4.0

Because it is currently not possible to select faces based on the values in a face map, and because creating new face maps is cumbersome (First: Add attribute, select name, domain and type, then: Mesh -> Set attribute), I decided to create a tiny add-on that provides this functionality for the time being.

It is called facemap_select.py and can be downloaded from this GitHub repository (or you can right click and this link directly and select download.)

It is a bit rough-and-ready, but once downloaded, you can install and enable it in the usual way by selecting Edit -> Preferences -> Add-ons -> Install and then locating the file you downloaded. Don't forget the check the enable checkbox.

The add-on will add two options to the Select menu (in mesh edit mode):


From facemap will select faces based on the currently active face map, while Create facemap will create a new facemap and set its values to reflect the currently selected faces.

From facemap will be grayed out if no suitable facemap is selected.

A created face map will have a name starting with 'Facemap' and will be in the FACE domain and have a boolean type.

Note: face maps are not typically called that in the Blender documentation but are custom attributes (to be found in the Object data properties of a mesh object in the Attributes panel:

There might be more and different kinds of attribute layers here as well, like a uv map, as shown in the image).

I don't think (hope?) this add-on will last forever, as I expect this missing bit of functionality to be added to Blender sometime in the future (or someone might take my code and incorporate it, that's fine too of course). In the mean time I hope this might help some people with multiple complex selections to switch easily between those.