Tuesday, May 17, 2022

Geometry Nodes and Shells

Geometry nodes is a powerful way to manipulate meshes that was introduced in Blender 3.1. They are used in the development version of the DAZ Importer as an alternative way to import geoshells and geografts from DAZ Studio. This could not have happened without the help of commenter Midnight Arrow, who explained to me about geometry nodes in general, and how they could be used in these specific cases.

This blog post describes how to import a geoshell as a geometry node setup in Blender. Later posts will cover geografts and how to import characters with shells and geografts directly from the DAZ database, without taking the detour over DAZ Studio.

Here we have a dirty character in DAZ Studio. The dirt is added with a geoshell called FX layer 01.
In the Parameters tab we find that the shell is pushed away from the main mesh by a small distance; Offset Distance = 0.0050 cm. There is also the list of surfaces affected by the shell.
By default a shell in DAZ Studio corresponds to a node group in the Blender materials. To generate a geometry node tree instead, we change the global setting Shell Method to Geometry Nodes (Experimental).
The body mesh looks strange in the viewport. This is because the shell becomes a second mesh which is located in almost the same place as the body mesh.
The shell by itself is an empty mesh, i.e. it does not have any vertices, edges or faces. But it has materials and a nodes modifier which generates the mesh. The modifer has a number of parameters:
  • Figure: The mesh that the shell copies.
  • Shell Offset: This is the Offset Distance parameter in DAZ Studio. In this case it is 0.005 cm = 0.00005 m.
  • Material slots: There is an entry for each material where the shell is visible and not totally transparent.

We can inspect the node tree in the geometry node editor. The nodes modifier generates a new mesh where the body materials are replaced by the shell materials.

Here is the shell mesh by itself, with viewport shading set to sold and rendered, respectively.

Here is a rendered example, with the two different Shell Method settings.
 
There is a problem with previewing the shell materials. Geometry nodes require that the materials pick up the UV maps with named UV Set or Attribute nodes, but Blender 's previewer only works if we use a Texture Coordinate node for that.
Here is how one of the shell materials is previewed. Since it uses a Attribute node, the previewer doesn't find the UV coordinates but uses the value of the first pixel at (0,0).
Fortunately, we can use the new Make Palette tool to preview the shell materials. This tool was originally intended for storing materials for the new asset browser, but it can also be used for previewing. Select the shell in the outliner and make a palette.
Here is the palette viewed from above, in solid and rendered viewport shading. The shell mesh has nine materials, but there are only eight material slots in the nodes modifier. This is because the Irises material (material number 8) is visible but purely transparent.

Sunday, January 16, 2022

Softbody Simulations

 

In real life body fat tends to have motion of its own - female breasts bounce, the belly and posterior of a fat persion jiggles, etc. - and that is best handled by softbody simulations. In DAZ Studio we have dForce, but simulations are not easy to transfer between applications. Moreover, dForce is a cloth simulator without pressure, and thus it can’t do softbodies properly. This is evident when the dForce “softbody“ collides with a prop, it doesn’t preserve the volume. At its best dForce can do bouncings, but not softbody collisions as Blender's softbody simulator can.

The DAZ Importer now has a new tool that adds a softbody simulation to Genesis characters directly in Blender. The setup was suggested by Alessandro Padovani in this thread, using ideas by Aneesh Arts explained in https://www.youtube.com/watch?v=eggOO9CIyp4. The Blender manual for softbody animations can be found at https://docs.blender.org/manual/en/3.0/physics/soft_body/index.html.

It should be stated from the outset that I am not an expert in simulations. The softbody simulation created by this tool works quite well in most cases, provided that the animation is believable. However, if the softbody object is subject to excessive force, either due to acceleration or to collsions, the softbody objects may collapse, giving the impression of a broken breast implant. Probably not the effect you were looking for. In such cases you either have to tweak the simulation parameters or modify the animation. But in most cases the softbody simulation does work and gives plausible results.

This is work in progress and available only in the development version of the DAZ Importer. It is not part of stable version 1.6.1.

The tool that adds a softbody simulation is called Add Softbody and is located at the top of the Finishing section. It is very important that the softbody simulation is added before the main body mesh is modified in any way, e.g. by merging geografts or eyelashes to it. Therefore the button is located before the merging tools.

Easy Import also has an option to add softbody simulations.

Three kinds of softbody objects can be added; chest, belly and glutes. You probably want all three kinds to simulate an obese person with much body fat everywhere, whereas for a slender woman the chest option may suffice. There is also an option to combine all there softbodies into a single object. Keeping multiple softbody objects makes it possible to tweak the simulation parameters independently, but adds to the complexity.

Collision objects for arms and legs can be added. If you only add softbody for the chest you probably only want to add collision objects for the arms, since it is unlikely that the chest will collide with the legs.

Finally there are options to add a corrective smooth modifier to the meshes and to remove existing softbody objects.

A new collection called Simulation is added. It contains the collision and softbody objects. The collection is hidden, but we may unhide it in the viewport to tweak the simulation parameters.
When visible, the softbody objects are red and the collision objects are green in the viewport. If the simulation does not work as intended, the simulation parameters may be tweaked here. The video by Aneesh Arts explains the meaning of the simulation parameters well. The Blender documentation is also a valuable resource.
If you create a combined softbody objects, you can still assign different masses to the parts with the MASS vertex group

The simulation goal is the vertex group that is pinned during the simulation. By default the goal is the vertex group PIN. The tool defines another vertex group, PIN BRA, which may be a more suitable goal if the character wears a bra which prevents the bottom of the breasts from bouncing freely. You can of course also define your own vertex groups if your character is wearing clothes that keeps parts of the body fat in place.

The simulation is only using the softbody and collision objects. Since those have a low polygon count, the simulation is quite fast. The deformation of the meshes is done by surface deform modifers.

Note that the surface deform must be unbound before any changes to the mesh is done. The Merge Geografts and the new Merge Meshes tools are aware of that, and unbind any surface deform modifiers first and rebind them again once they have finished.

Tuesday, January 11, 2022

DAZ Importer and MHX Runtime System Version 1.6.1 Released

Stable versions 1.6.1 of the DAZ Importer and MHX Runtime System have been released. They can be downloaded from https://www.dropbox.com/s/ufps8ip4xqxyqy3/import_daz_mhx_rts_v1_6_1.zip

Main new features:

  • Support for Blender 3.0. 
  • Many bug fixes

The new versions also contains some new features.

  • Support for ERC morphs (morphing armatures).
  • Improved UI for morphs.
  • Better support for instancing.
  • Better metal materials.
  • Support for DAZ decals and layered images.

I want to thank Xin, Jeroen B, and especially Alessandro Padovani for helpful suggestions, and Suttisak Denduangchai and ViSlArT for contributing code.


Xin's HD Morph Add-on

Xin's daz_hd_morphs add-on was bundled with the DAZ Importer in version 1.6.0, but not in 1.6.1. The latest version can be downloaded from
https://bitbucket.org/Diffeomorphic/import_daz/issues/attachments/814/Diffeomorphic/import_daz/1640639852.54/814/v0_81_1-0_82_1.7z

The source is also available in the following repository: https://gitlab.com/x190/daz-hd-morphs . There you can find compilation details for the .dll under MinGW on windows x64 (the code should work on Linux too with some small modifications).

Information about how to use the tool can be found in
https://bitbucket.org/Diffeomorphic/import_daz/issues/357/blender-addon-to-generate-rigged-hd-meshes
https://bitbucket.org/Diffeomorphic/import_daz/issues/814/blender-addon-to-generate-rigged-hd-meshes


Removing Old Versions

Old versions of the add-ons can cause conflicts when you install the new versions, because they will prevent that the new files are copied to the right location. We must therefore remove them first.

Open Blender and the Blender Preferences window. In the Add-ons tab, unstall the add-ons (DAZ Importer, MHX Runtime System, etc.).
Quit Blender and go to the location where Blender stores the add-ons. On my computer it is C:/Users/Thomas/AppData/Roaming/Blender Foundation/Blender/2.83/scripts/addons.
Delete the folders that contain the old versions of the add-on. Now the old add-ons will not cause any conflicts and we can proceed to install the add-ons as described in the documentation.

 

 

Wednesday, December 29, 2021

Using Old Morphs in Version 1.6.1

In version 1.6.0 of the DAZ Importer the new morph system was introduced. It is not compatible with the old morph system from version 1.5.1, but old characters could still be used in version 1.6.0 because code necessary to deal with old morphs was kept. However, in the current development version, which will eventually become 1.6.1, support for the old morphs has been dropped. So morphs made for characters in version 1.5.1 do not work in the current version. Fortunately, there is a way to fix this, using stripped runtime system that was included in the 1.6.0 release.

Here we have created a character in version 1.5.1 ( the last version compatible with Blender 2.79) of the DAZ Importer, and loaded some morphs.
If we append the character into a new Blender file and run the latest version of the DAZ Importer, the morphs do not work. The sliders show up in the Morph panel, but nothing happens if we change them.
To fix this, go to the Scripting tab and open the stripped runtime system which was included in the 1.6.0 release. We need to load the file runtime_stripped_28x.py in the runtime_stripped folder.
Register the script in the Text menu, save the blend file and reload it. This is important because the script does not take effect until the file is reloaded.
And now the old morphs work.

There is an important limitation to this approach. The old and new morph systems do not work together, so the old morphs will stop working if you load new ones in version 1.6.1. If you want to add morphs, you need to go back to version 1.5.1 and load the morphs there.

Before the old morph system was introduced, there was an even older morph system. There was a conversion utility, which was described in the announcement, but I haven't tested to use it.

Wednesday, December 15, 2021

Custom JCMs and Adjusters

Recently some problems with loading custom JCMs (Joint Corrective Morphs) were reported. It turned out that the code contained a hack to avoid problems with reloading JCMs, and that piece of code didn't work well. The problem should be resolved in the latest development version, but looking into this made me better understand how custom JCMs work and how they are related to the corresponding FBMs (Full Body Morphs).

First we import Aiko into Blender with Mesh Fitting set to DBZ File.

Import the standard JCMs (Import JCMs button) and bend the left elbow. The corrective shapekeys are driven by the bone rotation as expected. However, these shapekeys where made for the basic Genesis 8 Female, and we get better deformation if we import the JCMs that were designed specifically for Aiko.
For this we use the Import Custom Morphs tool. In the file selector, use "pjcm" as the filter to limit the selection to the JCMs (more precisely to the pJCMs, eJCMs are not imported), and import everything.
And we see that the Aiko-specific shapekeys are also driven by the bone rotations.

However, there is a catch. The final shapekey values are multiplied with the strength of the Aiko FBM (Full Body Morph). If the Aiko FBM is not imported, which it wasn't since we only imported the pJCMs, behind the scenes the FBM strength is set to 1, and everything is fine. But let's see what happens if we import the Aiko morphs.

So we import the Aiko FBM and FHM, and suddenly the Aiko corrective shapekeys are set to zero.
What happens was that by importing the Aiko FBM, we created a new property that multiplies the strength of the JCMs, and since that property was set to zero, the JCMs are zero too.
So if Aiko 8 Body = 0, the left forearm JCMs are zero too, even if the elbow is bent.
If we set Aiko 8 Body = 1, the non-zero JCM values reappear.
Alas, we can not set the Aiko FBM and FHM to one, because the Aiko morphs were already baked into the mesh when it was loaded with Mesh Fitting set to DBZ File, and thus the Aiko morphs are applied twice.

The way to decouple the JCM strength from the FBM strength is to use adjusters. Let us go back and import the Aiko JCMs again, but this time we enable the Use Adjusters option.
Now a new slider called Adjust Custom/aiko appears at the to of the aiko category. This property replaces the FBM value as a JCM multiplier. So if Adjust Custom/aiko = 1.0, the Aiko JCMs have the right values even if the Aiko FBM = 0.
If we reduce the value of the adjuster, the morph values are reduced accordingly. This can be used if you have mixed character. If you create a character which is 30% Aiko and 70% Victoria, say, you can import both the Aiko and Victoria custom JCMs, and set Adjust Custom/aiko = 0.3 and Adjust Custom/victoria = 0.7, to get the JCM mix which is right for that character.

Sunday, December 12, 2021

Better Decals

A decal is projected from an empty (the projector) onto a mesh. In an earlier post we discussed a tool for adding decals to DAZ meshes. However, there were some shortcomings which made the decal tool rather unusable:
  1. The decal were also projected on surfaces that are facing away from the empty.
  2. Decals could not cross material boundaries, forcing us to some very convoluted constructions.
  3. Only images with an alpha channel were supported, but not jpeg images with masks.
  4. There was no indication in which direction the decal was projected.

Recently Alessandro Padovani and Xin made me revisit the decal tool, with some nice improvements.

Select the mesh and press Advanced Setup > Materials > Make Decal. A file selector opens.

First we can select the materials that the decal will be added too. We can select one or several materials. The buttons at the top work in the same way as in the material editor or the UDIM tool. The remaining options are:

  • Channel: The channel that the decal should be added to, e.g.
    • Diffuse Color
    • Principled Base Color
    • Bump
  • Reuse Empty: If selected, an existing empty in the scene is used to project the decal, otherwise a new empty is created. If the decal affects multiple channels, enable this after the first channel has been loaded.
  • Empty: A list of available empties. If None is selected, a new empty is created.
  • Use Mask: Use a separate mask image for transparency. If disabled the image's alpha channel is used instead.
  • Decal Mask: Path to the mask file. A file selector for the mask is below the Make Decal button.
  • Blend Type: How the decal is blended with the base texture (Mix, Multiply, etc.). The default is Mix.
An empty with the shape of a flattened cube is created at the origin. The extent of the cube is approximately the region where the decal lives. Move, scale and rotate the empty until the decal looks as desired.

 
Next we want to add a second decal, which is a jpeg file. Since jpeg images don't have an alpha channel, we need to add a separate mask image. Before pressing Make Decal, set the Decal Mask below it, using the folder icon. In the file selector that opens, select the heart-mask.jpg file.

Now press Make Decal again and enable Use Mask. A new field with the previously selected mask file appears. Now select the heart.jpg file.

There are now two nodes that modify the diffuse texture. The node groups have the same label, but they are really different node groups because different empties control the location of the decal.

 Position the second decal in the same way as the first.

To make a decal cross a material boundary, it must be assigned to both materials. The Skin button selects the skin materials, i.e. the torso, face, arms and legs materials in this case. We select the jpeg version of the heart, but if we set the blend type to Multiply the white background will not show up.

Position the decal on the shoulder where the torso and arm materials meet. Note how the problems we encountered in the previous post do not arise anymore.

Finally we import a star decal. Only the arms material is selected, and we enable Reuse Empty. In the list of available empties, select the one that we created last.

The star decal immediately appears on the shoulder. Note that the tip of the star is cut off, since it was only assigned to the arms material. This is a rather artificial example. Normally we reuse an empty if we load related decals to different channels, e.g. diffuse and bump.

The shape of the cube gives a visual cue about the extent of the decal. If the cube is scaled in the local Z direction, i.e. it is made deeper, the decal may show up on the other side of the mesh as well, as in the picture below.

We can control the visibility of the decals with the Set Shell Visibility tool which appears in the Visibility panel when the mesh is the active object. In the popup dialog there is an entry for each decal. The same tool also controls the visibility of the shell nodes. The Insert Keys option allows us to animate the decal visibility.

Finally we vertex parent the decal empties to the mesh, so they move with the mesh when it is posed.

And here the mesh is posed with the decals in place.