Thursday, October 10, 2024

Diffeomorphic Add-Ons version 4.2.1 Released

It is time for a new stable release of the DAZ Importer and the other Diffeomorphic add-ons. The main novelty is that the add-ons have been converted to Blender extensions in Blender 4.2, cf the posts on Blender Extensions and GPL and Addon Scripting and Blender Extensions. The add-ons can also be installed in earlier versions of Blender. As usual, several bugs have also been fixed.

The DAZ Studio export script (export_to_blender.dsa) has also been updated and should be copied to the Scripts folder in a DAZ Studio directory. The specialized HD export script (export_highdef_to_blender.dsa) has been merged with the main export script and is now obsolete. Old versions of the script still work in most situations.

DAZ Importer

The DAZ Importer is a Blender add-on for importing native DAZ Studio files (.duf, .dsf) into Blender. It also contains some tools to make the assets more animation friendly.
Download:
https://www.dropbox.com/scl/fi/hka5ej1dv65gk04p1pn5x/import_daz-4.2.1.zip?rlkey=9ukju1y5zai4pryp5atblcbe9
Documentation:
https://bitbucket.org/Diffeomorphic/import_daz/wiki/Home

MHX Runtime System

The MHX Runtime System is a Blender add-on for posing the MHX rig, that can be generated by the DAZ Importer.
Download:
https://www.dropbox.com/scl/fi/ry8nwojh62s3y23w4g5bp/mhx_rts-4.2.1.zip?rlkey=mx0worrq46afetxumvmo8yhg8
Documentation:
https://bitbucket.org/Diffeomorphic/mhx_rts/wiki/Home

BVH and FBX Retargeter

The purpose of the BVH and FBX Retargeter is loading animations from BVH or FBX files to a given armature, and editing these animations in various useful ways. It can also import facial animations in FaceCap, LiveLink, VMD and FBX formats.
Download:
https://www.dropbox.com/scl/fi/qh6czqobslto9q0ea6kh6/retarget_bvh-4.2.1.zip?rlkey=g9xpumgp6xzh94frzromb8psy
Documentation:
https://bitbucket.org/Diffeomorphic/retarget_bvh/wiki/Home


The next two add-ons were recently spawned from the DAZ Importer in order to keep down its size somewhat. They contain rather specialized tools that are probably not of interest to most users. They are also poorly documented and result in warnings about policy errors. The the previous release there was a third add-on for exporting pose presets back to DAZ Studio, but that has been merged with the main DAZ Importer add-on again.

Important: The DAZ Importer must be enabled first, before any of these two add-ons can be used.

DAZ Rigging

Some specialized tools for rigging certain types of figures, link chains and tails.
Download:
https://www.dropbox.com/scl/fi/xqgb698891hlwqr3bon7z/rig_daz-4.2.1.zip?rlkey=k5mhdxlwi7civx5uzrozk6svz
Documentation:
https://bitbucket.org/Diffeomorphic/rig_daz/wiki/Home

Shell Editor

Contains some tools for manipulating shells imported from DAZ Studio.Download:
https://www.dropbox.com/scl/fi/bqh6cu4o33jdpwr4nspct/shell_edit-4.2.1.zip?rlkey=09ls8m6em95dicc4kvk54r000
Documentation:
https://bitbucket.org/Diffeomorphic/shell_edit/wiki/Home

Wednesday, October 2, 2024

Addon Scripting and Blender Extensions

As mentioned in the previous post on Blender Extensions and GPL, the DAZ Importer is now a Blender extension under Blender 4.2. It still works as a legacy addon in earlier Blender versions. This poses some challenges when using the addon in scripts. Here is an example.

import bpy
import import_daz

relpath = "/scenes/aiko-basic-wear.duf"
abspaths = import_daz.get_absolute_paths([relpath])
import_daz.set_selection(abspaths)
bpy.ops.daz.easy_import_daz(
   useExpressions = True,
   useJcms = True,
   clothesColor = (0,0,1,1.000),
   useTransferClothes = True,
   useMakePosable = True,
)
print("Loaded %s" % import_daz.get_selection())


This script loads a scene with Aiko dressed in Basic wear. The scene is located in the scenes directory under one of the DAZ root paths. The corresponding absolute path depends on the root paths specified in the global settings, and we use the import_daz.get_absolute_paths() function to retrieve it. Since a relative path may correspond to multiple absolute paths, this function returns a list.

Easy import is done with the bpy.ops.daz.easy_import_daz() operator, but we have to tell it which files to import first. This is done with the import_daz.set_selection() function, which should be called before any operator that acts on a list of strings.

The script above works fine in Blender 4.1 and earlier versions of Blender (some keyword argument may be different in very old addon versions), but in Blender 4.2 it causes an error:

ModuleNotFoundError: No module named 'import_daz'

The culprit is the line

import import_daz

which doesn't work because the import_daz module is not in the Python path anymore. To resolve this, we first notice that the entire DAZ Importer API is located in the import_daz.api submodule, which can be imported into the script with the line

from bl_ext.user_default.import_daz import api

Since we have imported the api module rather than the import_daz one, all function calls must change. E.g.,

abspaths = import_daz.get_absolute_paths([relpath])

is replaced by

abspaths = api.get_absolute_paths([relpath])


With these modifications, the full script becomes

import bpy
from bl_ext.user_default.import_daz import api

relpath = "/scenes/aiko-basic-wear.duf"
abspaths = api.get_absolute_paths([relpath])
api.set_selection(abspaths)
bpy.ops.daz.easy_import_daz(
   useExpressions = True,
   useJcms = True,
   clothesColor = (0,0,1,1.000),
   useTransferClothes = True,
   useMakePosable = True,
)
print("Loaded %s" % api.get_selection())

The new script works fine in Blender 4.2, but now we get an error when running the script in Blender 4.1.

ModuleNotFoundError: No module named 'bl_ext.user_default'; 'bl_ext' is not a package

To make the script work both in Blender 4.2 and earlier Blender versions, we can replace the code at the top with

try:
    from import_daz import api
except ModuleNotFoundError:
    from bl_ext.user_default.import_daz import api