Add-on: make vertex colors unique across selected objects

Say you have carefully assigned vertex colors to your mesh to be used as a color ID mask in a texturing program. And now you want two copies of this mesh and you want to assign different materials while using the same texture set for both objects to save on the number of textures. Assuming you have given each mesh a uv-mapping that covers a different set of uv-coordinates this shouldn't be an issue if you could make the vertex colors unique across this meshes.
This is where this add-on comes in handy: it will count the number of vertex colors used in all selected objects and reassign colors in such a way that all the colors are unique with the selected objects.
For example, starting with two meshes with identical color assignments








You will end up with something like this:



Note that none of the colors used in the left mesh appear in the right mesh and vice versa.

Availability

As usual the add-on is available for download from my GitHub repository (right click on the link and select Save as ...)
After you have installed and enabled the add-on, a new menu entry will be available in object mode: Object → Make vertex colors unique.
It might be a bit odd not to have this in vertex paint mode but it operates on more than one selected object and selecting objects is not possible in vertex paint mode so this is a bit less inconvenient.

Version 20170918 of IDMapper available on Blender Market

I have released an update version of the IDMapper add-on to Blender Market.

In the video I demo the new functionality and I have listed the release notes at the end of this article.

If you would like more information on all the functionality, have a look at this article. A complete workflow demonstration is available in this demo video.


Release notes

Version 20170918

  • Add ID Color List management
  • it is now possible to load, manage and save named lists of colors and to pick colors from this list when working in Face Paint mode. This is convenient if your studio uses smart materials for example and you have a list of predefined ID map colors you want to use for many different assets. Unlike Blender's built-in palettes, these colors have names, can be searched and sorted and loaded/saved as .csv files.
  • Add color picking outside select object in Face Paint mode
  • Number of undo levels in Face Paint mode is now configurable

Colorramp picker updated

Made a small update to the colorramppicker add-on. You can now use it on compositor colorramp nodes as well (and theorectically on any colorramp node but I didn't test it on Blender internal texture node group).
Read more on its use or watch the video in the original article.

Availability

You can download the add-on from GitHub. (click right on the Raw button and save the python file anywhere you like and then in Blender select File->User preference, Add-ons, Install from file... Don't forget to remove the old one first and don't forget to enable the add-on after installing it.)

If you would like to write add-ons yourself, you might want to take a look a my books on BlenderMarket.

New version of IDMapper available on Blender Market

I have released an update version of the IDMapper add-on to Blender Market.

In the video I demo the new functionality and I have listed the release notes at the end of this article.

If you would like more information on all the functionality, have a look at this article. A complete workflow demonstration is available in this demo video.


Release notes

Version 20170827


  • Add detection of sharp edges
  • When creating the initial ID map you now have the option to respect any edges marked as sharp as region boundaries
  • Help display in face paint mode 
  • All available keyboard shortcuts in Face Paint Mode are now shown in the lower left corner for easy reference. This can be toggled with the H-key
  • Respect sharp faces when smoothing, expanding or shrinking a region
  • When smoothing, expanding are shrinking an area in Face Paint Mode it is now possible to respect any sharp edges or uv-seams
  • Improved navigation
  • Most keys on the numpad now work as expected so panning and orbiting is now possible in Face Paint Mode
  • Bug fix: paint selected faces now sets undo stack
  • Nodeset: additional features and clean-up

    In a reply on a previous post monari suggested some additional functionality and in the true spirit of open source even supplied a new implementation.

    So in this version I incorporated most of his new code: if you now import a texture set with an associated shader you get a height map correctly wired to a normal node with the help of a bump node.

    In addition I added the option to create a nodeset that is suitable for use with microdisplacement, i.e. that wires the height map with a multiply to the displacement socket of the material output (the option is available on the left side of the fileselector).



    The two variants of the node setup are shown below:


    As usual the add-on is available from my GitHub repository.

    Avoiding repetition artifacts with chaos mosaic

    Chaos mosaic or chaos mapping is a method to extend limited size textures to huge uv-mapped surfaces while avoiding repetition artifacts.
    You might have for example a grass covered ground texture that is detailed and would map to a 2 x 2 meter square quite well. If you would apply this to a 10 x 10 meter field and scale to its proper size, obvious repetition artifacts would be visible:

    A chaos mosaic on the other hand would take randomly selected squares from a texture giving the appearance of an endless texture without repetition:

    At close range you would still be able to make out the seams but for large objects seen from a distance this probably wouldn't be noticeable.
    This technique only gives good results for non-patterned textures like groundcover, asphalt, plaster etc. but in those cases it might be just what you are looking for and it is quite fast.
    In an older article I showed a chaos mosaic implementation in Open Shading Language but I like to work with the GPU as much as possible so I implemented the same technique in just nodes.

    Node group


    The noodle takes the uv-coordinates and then you can plug in the transformed coordinates into you texture. The scale can then be adjusted as needed. The rotation gives an additional amount of randomness to the final material but depending on the texture this might not always improve the visual quality.
    The .blend file with the node group is available from my GitGub repository. Just download the chaosmap.blend and then in your own .blend use File → Append to select the nodegroup Chaosmap. It will then become available in the Add → Group menu of the node editor.

    Improvements

    To reduce the visibility of the seams between the tiles you can mix two chaos mosaics: the second one should use slightly offset and rotated uv-coordinates and then you can use for example a noise texture with a scale comparable to the actual textures to mix the two:

    The result has less visible seams but is also somewhat blurred:

    The highlighted area shows a visible seam:



    Especially at close range:



    Some details

    You can examine the details of the nodegroup if you like but the basic principle is that it takes the original uv-coordinate, determines in which grid section this falls and then maps the relative position of the point inside this grid to a relative position inside randomly selected square in the unit uv-map. (This square is randomly selected but always the same square for the same grid section)

    Tiny Blender Addon: Snap and transform

    I was doing some arch-viz the other day and I was placing a lot of objects in a large scene. The objects where placeholders that I created on the spot and more often than not I needed to move the origin of the new mesh object to a selected vertex for easy positioning, scaling, rotating etc.

    This is of course simple enough: select Snap cursor to selected in edit mode, switch to object mode and then select Transform → origin to 3d cursor.
    But it is also a lot of actions for a simple operation, especially if you doing this a hundred times in a scene...

    Another common scenario that I encounter is that I want to position the origin at the lowest point of a mesh. This is a little bit more involved as far as the code is concerned, a small explanation below for those who are interested in doing this on large meshes in a fast way.

    Anyway, here is a small add-on: Edit mode origin tools. It does nothing fancy, it will just create two new menu entries in edit mode:
    Mesh → Snap → Origin to selected,
    Mesh → Snap → Origin to lowest vertex (along z-axis)
    and save you some time :-)

    Code availability

    Download it from my GitHub repository (right-click on the first link and select save as ...) and in Blender go to File → User preferences → Add-ons → install from file ... (don't forget to enable it after installation. Note that the downloaded file is called snapandtransform.py while the add-on will appear as Edit mode transform tools)

    Finding the location of the lowest vertex (fast)

    If we want to get all the vertex coordinates fast, we got to switch to object mode first (line 2), get the number of vertices present (line 4) and the allocate an empty numpy array to hold all coordinates (line 7). Then we can use the foreach_get() method to get all coords (the co attribute of the verts array) in one go (line 8). It will be a flattened array so we have to reshape it to an array of 3-vectors (line 9).
     def execute(self, context):
      bpy.ops.object.editmode_toggle()
      me = context.active_object.data
      count = len(me.vertices)
      if count > 0:  # degenerate mesh, but better safe than sorry
       shape = (count, 3)
       verts = np.empty(count*3, dtype=np.float32)
       me.vertices.foreach_get('co', verts)
       verts.shape = shape
       verts2 = np.ones((count,4))
       verts2[:,:3] = verts
       M = np.array(context.active_object.matrix_world,
           dtype=np.float32)
       verts = (M @ verts2.T).T[:,:3]
       min_co = verts[np.argsort(verts[:,2])[0]]
       context.scene.cursor_location = min_co
       bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
      bpy.ops.object.editmode_toggle()
      return {'FINISHED'}
    
    Now all the coordinates will be in object space so we will want to convert all of them to world space. For this we need to multiply each of them with the matrix_world of the object. This is necessary because due to rotations the lowest vertex in object space need not be the lowest vertex in world space!

    The world matrix is a 4x4 matrix (one that holds not only scale and rotation but translation as well) so we need to extend all our coordinate vectors with a fourth coordinate of 1 (lines 10,11). We also convert the matrix_world to a numpy array (line 12).

    Line 14 is then where all the magic happens: we multiply our numpy world matrix M with our array of extend coordinates using the new @ operator. (new since Python 3.5 and especially added to allow numpy code to be better readable). The double transpose is to allow matrix multiplication of a 4x4 matrix with a list of 4-vectors and transform the result back again. The fourth coordinate of the result is dropped by the [:,:3] slice index.

    Now that we have converted all coordinates to world space, all we have to do is the find the index of the coordinate with the lowest z-coordinate with argsort() and assign this to the position of the 3d-cursor before calling the origin-set() operator.