Thursday, July 13, 2017

JSON fitting

It turned out that the FBX fitting method had flaws as well. However, since then I have come up with yet another way to extract the information about mesh and bone locations, and this time it seems to work, at least for all files that I have tried.

The idea is simply to write an export script for Daz Studio, that exports exactly the necessary information to a custom file. There were some initial hurdles, because I have not written scripts for Daz Studio before. The scripting language is not Python but something similar to Java or QT, which is not terribly difficult although something I have little experience with. What was tricky was that the API is poorly documented, but I managed to find some examples on the Internet that were sufficient for my simple script.

The script is located in the folder to_daz_studio and is called  export_basic_data.dsa. Before we can use it, we need to tell Daz Studio about it. This is done as follows.

In Daz Studio, select Window > Workspace > Customize.

In the customize windows that opens, right-click on Custom and select Create New Custom Action.

Change the Menu Text to Export Basic Data (or whatever you want to scripts name to be). Make sure that DAZ Script File is selected and press the ... button to the right.

A file selector opens. Navigate to the .dsa file and Open it.

The file name now appears in File field. Press Accept to close the dialog window.

The script now appears as a subitem under Custom. In the pane to the right, choose the Menus tab, and drag the script to the place you want it to appear. Since it is an export script, I find it natural to group it with the Import and Export menu items. Press Apply to make the changes take place, and then press Accept to close the dialog.

The new export script now appears in the File menu. Select it to export the basic data for the current scene.
Export the scene with the same name as the .duf file, but with the extension .json instead. My scene was unimaginably called test.duf, so the file name must be test.json. The script actually ignores the extension, so if you just call the file test it will still get the right extension automatically.

A dialog informs when the file has been exported. I don't know what happens if the script fails for some reason, because it has actually never happened so far.

Finally in Blender, select Json File for Mesh Fitting. The scene should now be imported, and the meshes and bones should look as they do in Daz Studio.

Here is the same character that we imported with Obj, Collada, and Fbx fitting in the previous post. There are, as far as I can tell, no obvious glitches. In particular, the feet fit correctly into the high-heeled boots, something that always required manual tweaking with the other fitting methods.

With this addition, I think that the Daz Importer is ready for the next stable release. I have not spent much time improving the code recently, but I have actually used the importer quite a bit myself, and to me the tool set feels rather finished.