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.