Friday, April 23, 2021

Importing an Animation Back into DAZ Studio

Update 2021-04-23: 

This method is obsolete. The new way to get an animation from Blender to DAZ Studio is to save it as a pose preset, see https://diffeomorphic.blogspot.com/2021/04/save-pose-preset.html.
 

Original post:

There was a request to import an animation made in Blender back into DAZ Studio. This turned out to be quite difficult, but I came up with a method that works, at least in some cases. However, there are glitches, which may be due to bugs to my code, or to imperfections in Blender's BVH exporter or in DAZ Studio's BVH importer, or some incompatible settings.
Import a DAZ character into Blender and animate her. Before exporting the animation, we need to create a modified action with the new tool Unflip Action, which is found near the bottom of the Pose panel.
The tool options lets us specify the start and end frames. By default both equal one, which corresponds to exporting a single pose. In this case we change the end frame to 250 to export the entire animation. A new, "unflipped", action is created, but nothing has happened to our character. The unflipped action is not meant for her.
 
We need to import the character again, but first we must change some global settings. Set
  • Unit Scale = 1.0
  • Z Up = off
  • Orientation = DAZ Unflipped
These are debug settings which we normally would not use for something that is to be used in Blender. However, in this case we want an armature with the same size and orientation as in DAZ Studio.
Here we have imported Aiko again with the new settings. Note that the new character is 100 times bigger than the original one (the units are centimeters, not meters), that the Y axis points up and the Z axis points forward, and that the bone orientations are weird. This is how the bones are oriented in DAZ Studio, which unlike Blender does not demand that the bones are directed along the local Y axis.
We now open the Action editor. The Unflip Action tool created a new action, whose name ends with "_Unflipped". Select it.
The unflipped rig now has a version of the animation that works for it.
Export the animation as a BVH file (File menu > Export > Motion Capture (.bvh)).
In DAZ Studio, import the BVH file.
And now the animation has been transferred to DAZ Studio.

There are a number of issues with the animation in DAZ Studio. E.g., in Blender Aiko is turning around several times, but in DAZ Studio she is stuck after making half a turn. It seems like the hip bone can not be rotated more than 180 degrees, at least if we use the default settings.

Sunday, April 18, 2021

Simulations moved

Update: 

For updated information, see the documentation on the Simulation Section.

Original post:

When I imported some characters with simulation turned on, Blender complained about dependency loops. Apparently the problem had to do with multiple collision modifiers. To avoid this, and because the philosophy of the Daz Importer is to provide tools rather than doing everything on import, the simulation setup has moved.

The Simulation group in the global settings is gone, except for a single Simulation option in the Meshes section. This checkbox only determines whether pinning groups are loaded.
With Simulation turned on, a pinning group is created as before. The tools for setting up the simulation are now located in the Advanced Setup panel, in the new Simulation group.
  • Make Deflection: Create a low-poly deflection surface for active mesh. Only for Genesis characters.
  • Transfer Vertex Groups: Transfer all vertex groups from the active mesh to selected meshes. The intention here is to transfer vertex groups from the character to the deflection object.
  • Make Collision: Add collision modifiers to the selected meshes.
  • Make Cloth: Add cloth modifiers to the selected meshes.
Here is the original character, the deflection mesh, and the deflection mesh with subsurf applied
Here the vertex groups have been transferred to the deflection mesh.
The Make Collision tool sets up the selected meshes as collsion objects.
The Make Cloth tool adds cloth modifiers to the selected meshes. The options are the ones that use to be in the global settings, except that we can choose the pinning group.
 
With collision and cloth set up, we can now proceed with the simulation.

Sunday, April 11, 2021

DForce Simulations

Update: 

Simulations are no longer created during import. Instead the simulation information is stored inside the imported meshes, and can be recreated with the Advanced Setup > Simulations > Make Simulation tool. See the documentation on the Simulation Section for more information.

Original post:

Many modern clothes use dForce, which simulates draping and movement of garments in DAZ Studio. The corresponding feature in Blender is cloth simulation, which has been considerably improved in Blender 2.90. For some time, Alessandro Padovani has nagged me about including dForce simulations in the DAZ Importer, and finally I got around to do it. Actually, this is not the first time that I attempted to do this, but the previous attempt was half-baked and never took off. Thanks to Alessandro's excellent help, this time things worked out better. We can now import dForce simulations in a useful way with the development version of the DAZ Importer.

First of all, we need to enable Simulation in the Global Settings, otherwise everything simulation-related will be ignored when the file is imported. We then proceed to import the DAZ character as usual. This file contains a Genesis 8 Female with Toulouse hair and the Bardot outfit that ships with DAZ Studio. The Bardot outfit is dForce compatible.
Select the body mesh and open the modifier tab. The body has a new collision modifier, which means that it will act as a collision object. The modifier settings are found inside the Physics tab if you need to change them. The DAZ Importer changes some settings, mainly it increases the collision quality.
The Bardot top has two new modifiers: a cloth modifier and a collision modifier. We can change the settings of both inside the Physics tab, but I left the settings unchanged. For some reason, the Bardot skirt did not receive a collision modifier.
The top and skirt also have subsurf modifiers, but the simulation seems to work better if you delete them. This improved performance from 0.25 fps to 0.30 fps on my machine, and also made the end result better. Perhaps this happens because the Bardot skirt is already a high-poly mesh.
The simulation parameters can be tweaked in the physics tab. One important parameter is the pin group, which is deduced from the dynamics strength parameters in DAZ Studio.
Here is the pin group for the Bardot skirt. The blue region is fully affected by the simulation, the yellow region only slightly.
 
The next step is to load an animation. I used the file provided by Alessandro.
Here is a typical frame in the animation. The garments has some interesting movements, but in my opinion the wrinkles are too extreme. We need to smooth them out.
Before we do anything else, we need to bake the simulation. Otherwise it will be lost as soon as we change anything. So select the top and skirt, and in the physics tab press Current Cache to Bake (for each garment). The simulation is now baked.
There are several ways that we can smooth the animation. We can e.g. add a Smooth Corrective modifier after the Cloth modifier. The default values for the paremeters work well.
Alternatively, we can add a Smooth modifier and change the Repeat value to 5.
Here is the simulation at frame 80, without and with the smoothing modifiers.




Friday, March 26, 2021

More on the Morped Fitting Option

Yesterday I wrote about how to import a morphed character into Blender without a dbz file.The conclusion was that sometimes it works and sometimes it doesn't, and if it doesn't we have to import the morphs manually afterwards. After having investigated the behaviour further I think I understand what is going on.
 
In DAZ Studio, import the Aiko 8 characters. We see that three sliders affect the character shape: Aiko 8, Aiko 8 Body, and Aiko 8 Head. They correspond to the CTRL, FBM and FHM files mentioned in the previous post. If we move the Aiko 8 slider, the body and head sliders follow suit.
But we can also dial the body and head sliders separately. So let us turn off Aiko 8 and turn on Aiko 8 Body and Head, as shown above. This distinction does not matter in DAZ Studio or if we export a dbz file, but it matters when we import the scene into Blender with Mesh Fitting set to Morphed.
 
Here is the result in Blender, with the control morph to the left, and the individual head and body morphs to the right. Note that the armature is morphed correctly in both cases, but the control morph does not affect the mesh.
In the latest commit to version 1.6.0, there is a new Morph Strength slider. It only appears when Mesh Fitting is set to Morphed, and the picture below illustrates what it does.
The usefulness of this option is limited, since it is still impossible to mix several characters in Blender; DAZ Studio must be used for that.

Wednesday, March 24, 2021

Importing a Morphed Character Without a DBZ File

The preferred workflow is to design a character in DAZ Studio, save it and export a dbz file, and then import the duf file with the DAZ Importer and Mesh Fitting set to DBZ. However, both DAZ Studio and Blender are evolving software that put increasingly strong demands on your hardware and software, and if you are on an old computer the latest versions may not work on it. 

One solution would be to uninstall the latest version and stick with an old version that works, but I am not sure if that is possible with DAZ Studio. Another solution is to import the scene directly into Blender, without opening DAZ Studio. This will work as long as the DAZ database is intact. However, it means that you must import the character without having access to a dbz file, since you must open DAZ Studio in order to export it.

It is now possible to import a morphed character directly into Blender, without the need of a dbz file. However, the process is somewhat complicated and involves several steps. It works in the latest version of version 1.6.0 of the add-on. Since this feature is something which may be most interesting on old computers that may not be able to run Blender versions later than 2.79, and Blender 2.79 support has been removed from version 1.6.0, the stable version 1.5.1 has also been updated. Stable version 1.5.1c can be downloaded from

https://www.dropbox.com/s/6ec0e1nzuimlwg2/import_daz-v1.5.1c-20210324.zip

The illustrations below were made with Blender 2.79 and DAZ Importer 1.5.1.

Here is a character in DAZ Studio. We save the scene as a duf file but don't export a dbz file. Perhaps it is an old scene and we can not open DAZ Studio to export a dbz file.

In Blender, import the DAZ scene and set Mesh Fitting to the new Morphed (Characters) setting.

The characters has morphs (FBMPearFigure) but the clothes have not.The armatures have also been morphed, although this may not be entirely obvious in this picture. Merge all rigs to the main character rig as usual. If we render the scene we see that the materials have been imported correctly.
The body mesh has a number of shapekeys that we need to transfer to the other meshes. With the mesh active and all other meshes selected, press Transfer Other Morphs (Transfer Shapekeys in version 1.6.0). Make sure to include all meshes, including hair and eyelashes.
In the options dialog, make sure that all shapekeys are selected. The other settings can be left at their default values.

The shapekeys are now transferred to the clothes and hair. With all meshes selected (the order does not matter in this case), press Apply All Shapekeys.

The shapekeys go away and we have successfully imported the morphed character into Blender. We can now continue with the other steps (merge materials, load morphs, merge geografts, ...) that makes the character ready for animation.

The process above assumes that we have saved the DAZ scene but not the corresponding dbz file. But we can also design new characters from scratch, even if DAZ Studio is not working, as long as the DAZ database is intact.

We want to import Aiko 8 into Blender directly from the character file. Press Import DAZ File (just Import DAZ in version 1.6.0) and navigate to the directory

{DAZ root}/People/Genesis 8 Female/Characters/

Select Aiko 8.duf or one of the corresponding png files, and import the DAZ file with Mesh Fitting set to Morphed.

In this case the morphs are not imported, and the imported mesh is a realistic Caucasian woman instead of a cartoonish Asian woman.However, we note that the morph has been imported to the armature, e.g. the brow and eye bones are distinctively below the matching location on the mesh. The difference compared to the previous case is that the FBMPearFigure morph is referenced directly from the duf file, whereas the duf file in this case refers to a control file (CTRLAiko8.dsf) which in turn refers to the two morph files FBMAiko8.dsf (full body morph) and FHMAiko8.dsf (full head morph). The Import DAZ tool does not handle such indirection, so instead we must load the individual morphs manually.

With the Aiko mesh selected, press Import Custom Morph and go to the directory that contains the Aiko morphs, i.e.

{DAZ root}/data/DAZ 3D/Genesis 8/Female/Morphs/DAZ 3D/Aiko 8/

This tool should start in the directory

{DAZ root}/data/DAZ 3D/Genesis 8/Female/Morphs/

by default, so the Aiko 8 directory is only two clicks away. (If several root directories have subdirectories with Genesis 8 Female morphs, the tool may pick something that is far away from the right directory. That is a nuisance.).

Do not pick the CTRLAiko8.duf file. As explained above, it contains pointers to the FBM and FHM files, and the morphs are not loaded, at least not in version 1.5.1.

Pick instead the FBM and FHM files in the same directory directly.

Now the two Aiko morphs are loaded, and we can turn them on in the Custom Morphs panel. Notice that the brows and eyes are now aligned with the armature. Also notice that the shapekeys are driven, i.e. the sliders are purple. This will be important below.

Just importing the nude character is not so interesting, we want to add clothes and hair too. So let us import them with the Import DAZ File button, with Mesh Fitting set to Unmorphed this time.

Clothes and hair are imported, but clearly they do not fit the character. So again we use the Transfer Other Shapekeys tool.
Select all meshes (clothes, hair and eyelashes) and make sure to transfer all morphs.
 
The transfer settings are not so important. What is important is that we turn off the morphs in the Custom Morphs panel before making the transfer. If some shapekeys are left at a non-zero value, the result of the shapekey transfer can be a disaster.

 

This problem did not appear for the previous character, because in that case the shapekeys were not driven. The Transfer Other Shapekeys tool automatically turns all shapekeys off before transfer and turn them on again once the transfer is complete. However, if the shapekey values are driven, this does not work, and we must turn them off manually instead.

Once the morphs have been transferred, we can turn the morphs back on a gain.
And finally we Apply All Shapekeys to get our final character. A fully dressed, rigged and morphed character has been created in Blender, without ever opening DAZ Studio.

Monday, March 22, 2021

Easy Import

After we have imported a DAZ character into Blender, we usually need to perform a number of operations on it before it is suitable for animation. The philosophy behind this is that the add-on can not foresee the need of every user, so the best thing is to import the scene as faithfully as possible, and then provide tools to turn the raw import into something useful. However, this flexibility can make it difficult to choose which tools to use and in which order. The new tool "Easy Import DAZ" is provided to facilitate import in the most common case, a single human character in rest pose.

 
We emphasize that flexibility is traded for simplicity, and there are limits to what can be done with the new tool.
  • Easy Import DAZ is mainly intended for importing a single human character in rest pose. There are no guarantees if the scene contains something else, e.g. multiple characters, characters not in rest pose, animals, environments, props. Things may work, or they may not.
  • The tool can import standard morphs (face morphs, body morphs, JCMs) but not custom morphs. Adding custom morphs to the character or its geografts must be done in a separate step afterwards.
  • The tool has options for merging geografts and eyelashes to the main character. However, if those have been merged, it is not possible to add further morphs because vertex numbers have changed. If you plan on adding custom morphs after import, you must the disable the Merge Geografts and Merge Lashes options.
  • Easy Import DAZ has an option to convert the native DAZ rig to the more animator-friendly MHX and Rigify rigs. However, again it is not possible to add more morphs after the rig has been converted.
  • Easy Import does not work with nested geografts. E.g., Roasty is a geograft for Futalicious, which in turn is a geograft for female characters. In this situation you must uncheck the Merge Geografts option, and instead merge the geografts in a two-stage process afterwards.

When we invoke the Easy Import DAZ tool, a file selector with many options appear. This lets us decide how the character is treated during and after it is imported into Blender.

  • Mesh Fitting: This option is the same as for the Import DAZ button, see this.
  • Viewport Color: This option is the same as for the Import DAZ button, see this.
  • Rig Type:
    •   DAZ: Leave the native DAZ rig unchanged.
    •   Custom Shapes: Add custom shapes to the native DAZ rig.
    •   MHX: Convert the rig to MHX.
    •   Rigify: Convert the rig to Rigify.
  • Mannequin:
    •   None: Don't add a mannequin.
    •   Nude: Add a mannequin for the body mesh only.
    •   All: Add a mannequin for all meshes.
  • Merge Materials: Merge identical materials into a single material.
  • Merge Rigs: Merge clothes rigs with the main character rig. 
  • Merge Toes: Merge the individual toe bones into a single toe bones which moves all bones.
  • Merge Geografts: Merge geografts to the main character. Body shapekeys (JCMs and flexions) are transferred to the geografts first.
  • Merge Lashes: Merge eyelashes to the main character. Face shapekeys are transferred to the eyelashes first.
  • Extra Face Bones: Add an extra layer of face bones, which remain posable after face morphs have been loaded. This is done before morphs are loaded.
  • Make All Bones Poseable: Add an extra layer of poseable bones for bones that are driven. This is done after morphs have been loaded.
  • Convert Hair: Convert strand-based hair (SBH) into particle hair in Blender.
  • Face Units: Import face unit morphs.
  • Expressions: Import expression morphs.
  • Visemes: Import viseme morphs.
  • FACS: Import FACS units morphs.
  • FACS Expressions: Import FACS expression morphs.
  • Body: Import body morphs.
  • JCMs: Import JCMS (joint corrective morphs).
  • Flexions: Import flexion morphs.
  • Transfer Shapekeys (only visible if JCMs or Flexions is selected): Transfer JCMs and flexions to all clothes. Shapekeys are always transferred to geografts and eyelashes before merging irrespective of this setting.

After a little wait, a fully rigged character appears which can be posed with a few clicks. This character was imported in 212 seconds, complete with face units, expressions, visemes and JCMs, and converted to the MHX rig.

Tip: It can take quite a while to import a scene with the Easy Import DAZ tool. You can follow the progress in the system console. This is normally not visible unless you start Blender from a command prompt, but it can be made visible from the Window > Toggle System Console menu.




Wednesday, March 3, 2021

New Morph System

Loading morphs and their associated drivers was done with one of the thorniest pieces of code in version 1.5 of the DAZ Importer. The code had grown organically over the years, with patches layered on patches. A major goal of version 1.6 is a complete rewrite of the morph system, something that is now almost done. There are still some known issues, but most things seem to work, in some aspects considerably better than before.

The new morph system is based on two suggestions.

engetudouiti suggested to use intermediate properties, to mimic how formulas are evaluated in DAZ Studio. I was initially skeptical about this idea because I was worried about update problems, but so far I have not encountered any. The old morph system attempted to flatten this hierarchy by computing the intermediate properties at load time. This worked reasonably well for most morphs, but for the recently introduced FACS morphs the size of the drivers blew out of propertions. 

Xin pointed out that the drivers can be rewritten solely in terms of simple expressions, using even more intermediate properties that are eventually added with a sum driver. Unlike scripted expressions which are limited to strings with less than 512 characters (used to be 256), sum drivers do not have a limit on the number of variables. The limitation of scripted expressions was the reason why the custom drivers were introduced in the first place. Using simple expressions rather than custom drivers has several advantages:

  1. Performance is apparently much better, since simple drivers are evaluated in C++.
  2. The drivers can be easily inspected in the driver window.
  3. Animations will work even if the DAZ Importer is disabled, which means that you can send your files to a render farm without including the stripped runtime system.

You can choose whether to use the new simple drivers or the old custom drivers with the global setting Use Python Drivers (the name will change to Use Custom Drivers). However, the custom drivers are deprecated and will probably be removed eventually, even if the custom driver functions will be kept to not break old files.

There are still a number glitches with the new morph system, the most obvious is probably that you can only import morphs of a given type (face units, expressions, visemes, ...) once. For custom morphs, you can only import morphs to a given category once. If you need to import more morphs, reimport the old ones too.

One improvement can be seen already. Most expressions are a combination of a pose of the face rig and a shapekey, but in the previous system the shapekeys were ignored, leading to rather dull expressions. The picture above shows Genesis 8 Female with the Triumph expression, loaded with the old system (pose only) and the new system (pose + shapekey). The expression would be even more interesting if combined with the normal or displacement maps generated by Xin's addon. This is something I hope to implement eventually.