daz3d / DazToBlender

Daz to Blender Bridge
https://www.daz3d.com/daz-to-blender-bridge
Other
213 stars 45 forks source link

DTB 2.1.0 - Issues with drivers relating bones to shapekeys #14

Open andy-m-github opened 3 years ago

andy-m-github commented 3 years ago

Hi,

I've posted this issue from the Daz3D Blender forum (https://www.daz3d.com/forums/discussion/469551/daz-to-blender-update-2-0). My configuration is:

The Issue

I've noticed that an imported figure (g3f or g8f) has issues with the shape of the mesh around the joints (i.e. shoulders, elbows and feet). This occurs if the figure is imported in a non-default pose or is imported with a default pose and subsequently posed in Blender.

  1. Load Genesis 8 figure
  2. Run the script. In the DAZ to Blender: Morph Names dialog, copy/paste the morphs below to be exported with the figure.
  3. Export figure from DAZ.
  4. Import figure in Blender.
Face Controls
Expressions
Visemes
All Body Morphs
pJCMAbdomen2Fwd_40
pJCMAbdomen2Side_24_L
pJCMAbdomen2Side_24_R
pJCMAbdomenFwd_35
pJCMAbdomenLowerFwd_Navel
pJCMAbdomenUpperFwd_Navel
pJCMBigToeDown_45_L
pJCMBigToeDown_45_R
pJCMChestFwd_35
pJCMChestSide_20_L
pJCMChestSide_20_R
pJCMCollarTwist_n30_L
pJCMCollarTwist_n30_R
pJCMCollarTwist_p30_L
pJCMCollarTwist_p30_R
pJCMCollarUp_55_L
pJCMCollarUp_55_R
pJCMFootDwn_75_L
pJCMFootDwn_75_R
pJCMFootUp_40_L
pJCMFootUp_40_R
pJCMForeArmFwd_135_L
pJCMForeArmFwd_135_R
pJCMForeArmFwd_75_L
pJCMForeArmFwd_75_R
pJCMHandDwn_70_L
pJCMHandDwn_70_R
pJCMHandUp_80_L
pJCMHandUp_80_R
pJCMHeadBack_27
pJCMHeadFwd_25
pJCMIndex1Dwn_90_L
pJCMIndex1Dwn_90_R
pJCMIndex2Dwn_105_L
pJCMIndex2Dwn_105_R
pJCMIndex3Dwn_90_L
pJCMIndex3Dwn_90_R
pJCMMid1Dwn_95_L
pJCMMid1Dwn_95_R
pJCMMid2Dwn_105_L
pJCMMid2Dwn_105_R
pJCMMid3Dwn_90_L
pJCMMid3Dwn_90_R
pJCMNeckBack_27
pJCMNeckFwd_35
pJCMNeckLowerSide_40_L
pJCMNeckLowerSide_40_R
pJCMNeckTwist_22_L
pJCMNeckTwist_22_R
pJCMNeckTwist_Reverse
pJCMPelvisFwd_25
pJCMPinky1Dwn_95_L
pJCMPinky1Dwn_95_R
pJCMPinky2Dwn_105_L
pJCMPinky2Dwn_105_R
pJCMPinky3Dwn_90_L
pJCMPinky3Dwn_90_R
pJCMRing1Dwn_95_L
pJCMRing1Dwn_95_R
pJCMRing2Dwn_105_L
pJCMRing2Dwn_105_R
pJCMRing3Dwn_90_L
pJCMRing3Dwn_90_R
pJCMShinBend_155_L
pJCMShinBend_155_R
pJCMShinBend_90_L
pJCMShinBend_90_R
pJCMShldrDown_40_L
pJCMShldrDown_40_R
pJCMShldrFront_n110_Bend_n40_L
pJCMShldrFront_n110_Bend_p90_L
pJCMShldrFront_p110_Bend_n90_R
pJCMShldrFront_p110_Bend_p40_R
pJCMShldrFwd_110_L
pJCMShldrFwd_110_R
pJCMShldrUp_90_L
pJCMShldrUp_90_R
pJCMThighBack_35_L
pJCMThighBack_35_R
pJCMThighFwd_115_L
pJCMThighFwd_115_R
pJCMThighFwd_57_L
pJCMThighFwd_57_R
pJCMThighSide_85_L
pJCMThighSide_85_R
pJCMThumb1Bend_50_L
pJCMThumb1Bend_50_R
pJCMThumb1Up_20_L
pJCMThumb1Up_20_R
pJCMThumb2Bend_65_L
pJCMThumb2Bend_65_R
pJCMThumb3Bend_90_L
pJCMThumb3Bend_90_R
pJCMToesUp_60_L
pJCMToesUp_60_R
pJCMFlexBiceps_L
pJCMFlexBiceps_R
pJCMFlexCalf_L
pJCMFlexCalf_R
pJCMFlexCollarUpperBack_L
pJCMFlexCollarUpperBack_R
pJCMFlexHamstring_L
pJCMFlexHamstring_R
pJCMFlexTriceps_L
pJCMFlexTriceps_R

If the figure is in its default pose, there is no issue. However if the figures is posed, it becomes apparent that some of the shapekeys are not being applied correctly. In the example below, I have posed the feet - the figures right foot is the correct shape (after a fix I applied to the driver), whilst the left foot has the original driver and shows the issue.

image

There are 2 types of issues with the drivers:

  1. The formula is wrong (i.e. the result of the formula is not a positive value and so the shapekey is not applied).
  2. The rotation axis the shapekey is applied to is wrong.

I went digging through the bridge files and found Database.py in AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\DTB. The two sections of interest are _tbl_mdriveg3 and _tblmdrive. These tables set up the drivers and the properties in these tables backed up what I was seeing in Blender, so if I was to fix the issues I was seeing, it would be here.

The Solution

Two tables have been modified. Below is a snapshot of the changes I've made. I should note that, I don't know what happens with characters beyond G3F and G8F base figures or to clothing.

tbl_mdrive_g3=[                                                             # Rotations: X = 0, Y = 1, Z = 2
    ['pJCMShldrDown_75_L', 'lShldrBend', 0, 'val*-0.764'],                  # G3F ORIGINAL WAS 2, 'val*0.764'],
    ['pJCMShldrDown_75_R', 'rShldrBend', 0, 'val*0.764'],                   # G3F ORIGINAL WAS 2, 'val*-0.764'],
    ['pJCMShldrFwd_95_L', 'lShldrBend', 2, 'val*-0.603'],                   # G3F ORIGINAL WAS 0
    ['pJCMShldrFwd_95_R', 'rShldrBend', 2, 'val*-0.603'],                   # G3F ORIGINAL WAS 0
    ['pJCMShldrUp_35_L', 'lShldrBend', 0, 'val*1.637'],                     # G3F ORIGINAL WAS 2, 'val*-1.637'],
    ['pJCMShldrUp_35_R', 'rShldrBend', 0, 'val*-1.637'],                    # G3F ORIGINAL WAS 2, 'val*1.637'],
    ['pJCMCollarUp_50_L', 'lCollar', 0, 'val*1.146'],                       # G3F ORIGINAL WAS 'val*-1.146'],
    ['pJCMCollarUp_50_R', 'rCollar', 0, 'val*-1.146']                       # G3F ORIGINAL WAS 'val*1.146'],
]

tbl_mdrive = [                                                               # Rotations: X = 0, Y = 1, Z = 2
    # G3F Drivers should not be here unless they are shared with other models.
    # Doing so defines the driver twice in Blender.
    #['pJCMShldrDown_75_L', 'lShldrBend', 0, 'val*-0.764'],                  # G3F ORIGINAL WAS 2, 'val*0.764'],
    #['pJCMShldrDown_75_R', 'rShldrBend', 0, 'val*0.764'],                   # G3F ORIGINAL WAS 2, 'val*-0.764'],
    #['pJCMShldrFwd_95_L', 'lShldrBend', 2, 'val*-0.603'],                   # G3F ORIGINAL WAS 0
    #['pJCMShldrFwd_95_R', 'rShldrBend', 2, 'val*-0.603'],                   # G3F ORIGINAL WAS 0
    #['pJCMShldrUp_35_L', 'lShldrBend', 0, 'val*1.637'],                     # G3F ORIGINAL WAS 2, 'val*-1.637'],
    #['pJCMShldrUp_35_R', 'rShldrBend', 0, 'val*-1.637'],                    # G3F ORIGINAL WAS 2, 'val*1.637'],
    #['pJCMCollarUp_50_L', 'lCollar', 0, 'val*1.146'],                       # G3F ORIGINAL WAS 'val*-1.146'],
    #['pJCMCollarUp_50_R', 'rCollar', 0, 'val*-1.146'],                      # G3F ORIGINAL WAS 'val*1.146'],

    # Unknown
    ['lShldrBend_CTRLMD_N_YRotate_n110', 'lShldrBend', 1, 'val*-0.521'],
    ['lShldrBend_CTRLMD_N_ZRotate_90', 'lShldrBend', 2, 'val*0.637'],
    ['lShldrBend_CTRLMD_N_ZRotate_n40', 'lShldrBend', 2, 'val*-1.433'],

    # G8F Drivers
    ['pJCMAbdomen2Fwd_40', 'abdomenUpper', 0, 'val*1.433'],                 # GOOD
    ['pJCMAbdomen2Side_24_L', 'abdomenUpper', 2, 'val*-2.389'],             # GOOD
    ['pJCMAbdomen2Side_24_R', 'abdomenUpper', 2, 'val*2.389'],              # GOOD
    ['pJCMAbdomenFwd_35', 'abdomenLower', 0, 'val*1.638'],                  # GOOD
    ['pJCMAbdomenLowerFwd_Navel', 'abdomenLower', 0, 'val*1.638'],          # GOOD
    ['pJCMAbdomenUpperFwd_Navel', 'abdomenUpper', 0, 'val*1.433'],          # GOOD
    ['pJCMBigToeDown_45_L', 'lBigToe', 0, 'val*-1.274'],                    # ORIGINAL WAS 'val*1.274'],
    ['pJCMBigToeDown_45_R', 'rBigToe', 0, 'val*-1.274'],                    # ORIGINAL WAS 'val*1.274'],
    ['pJCMChestFwd_35', 'chestLower', 0, 'val*1.638'],                      # GOOD
    ['pJCMChestSide_20_L', 'chestLower', 2, 'val*-2.866'],                  # GOOD
    ['pJCMChestSide_20_R', 'chestLower', 2, 'val*2.866'],                   # GOOD
    ['pJCMCollarTwist_n30_L', 'lCollar', 1, 'val*-1.911'],                  # ORIGINAL WAS 'val*1.911'],
    ['pJCMCollarTwist_n30_R', 'rCollar', 1, 'val*1.911'],                   # ORIGINAL WAS 'val*-1.911'],
    ['pJCMCollarTwist_p30_L', 'lCollar', 1, 'val*1.911'],                   # ORIGINAL WAS 'val*-1.911'], 
    ['pJCMCollarTwist_p30_R', 'rCollar', 1, 'val*-1.911'],                  # ORIGINAL WAS 'val*1.911'], 
    ['pJCMCollarUp_55_L', 'lCollar', 0, 'val*1.042'],                       # ORIGINAL WAS 2, 'val*-1.042'],
    ['pJCMCollarUp_55_R', 'rCollar', 0, 'val*-1.042'],                      # ORIGINAL WAS 2, 'val*1.042'],
    ['pJCMFootDwn_75_L', 'lFoot', 0, 'val*-0.764'],                         # ORIGINAL WAS 'val*0.764'],
    ['pJCMFootDwn_75_R', 'rFoot', 0, 'val*-0.764'],                         # ORIGINAL WAS 'val*0.764'],
    ['pJCMFootUp_40_L', 'lFoot', 0, 'val*1.433'],                           # ORIGINAL WAS 'val*-1.433'],
    ['pJCMFootUp_40_R', 'rFoot', 0, 'val*1.433'],                           # ORIGINAL WAS 'val*-1.433'],
    ['pJCMForeArmFwd_135_L', 'lForearmBend', 0, '(val-1.309)*0.955'],       # ORIGINAL WAS '(val+1.309)*-0.955'],
    ['pJCMForeArmFwd_135_R', 'rForearmBend', 0, '(val+1.309)*-0.955'],      # GOOD
    ['pJCMForeArmFwd_75_L', 'lForearmBend', 0, 'val*0.764'],                # ORIGINAL WAS 'val*-0.764'],
    ['pJCMForeArmFwd_75_R', 'rForearmBend', 0, 'val*-0.764'],               # GOOD
    ['pJCMHandDwn_70_L', 'lHand', 0, 'val*-0.819'],                         # ORIGINAL WAS 2, 'val*0.819']
    ['pJCMHandDwn_70_R', 'rHand', 0, 'val*0.819'],                          # ORIGINAL WAS 2, 'val*-0.819']
    ['pJCMHandUp_80_L', 'lHand', 0, 'val*0.717'],                           # ORIGINAL WAS 2, 'val*-0.717']
    ['pJCMHandUp_80_R', 'rHand', 0, 'val*-0.717'],                          # ORIGINAL WAS 2, 'val*0.717']
    ['pJCMHeadBack_27', 'head', 0, 'val*-2.123'],                           # GOOD
    ['pJCMHeadFwd_25', 'head', 0, 'val*2.293'],                             # GOOD
    ['pJCMIndex1Dwn_90_L', 'lIndex1', 0, 'val*-0.637'],                     # ORIGINAL WAS 2, 'val*0.637'],
    ['pJCMIndex1Dwn_90_R', 'rIndex1', 0, 'val*0.637'],                      # ORIGINAL WAS 2, 'val*-0.637'],
    ['pJCMIndex2Dwn_105_L', 'lIndex2', 0, 'val*-0.546'],                    # ORIGINAL WAS 2, 'val*0.546'],
    ['pJCMIndex2Dwn_105_R', 'rIndex2', 0, 'val*0.546'],                     # ORIGINAL WAS 2, 'val*-0.546'],
    ['pJCMIndex3Dwn_90_L', 'lIndex3', 0, 'val*-0.637'],                     # ORIGINAL WAS 2, 'val*0.637'],
    ['pJCMIndex3Dwn_90_R', 'rIndex3', 0, 'val*0.637'],                      # ORIGINAL WAS 2, 'val*-0.637'],
    ['pJCMMid1Dwn_95_L', 'lMid1', 0, 'val*-0.603'],                         # ORIGINAL WAS 2, 'val*0.603'], 
    ['pJCMMid1Dwn_95_R', 'rMid1', 0, 'val*0.603'],                          # ORIGINAL WAS 2, 'val*-0.603'],
    ['pJCMMid2Dwn_105_L', 'lMid2', 0, 'val*-0.546'],                        # ORIGINAL WAS 2, 'val*0.546'],
    ['pJCMMid2Dwn_105_R', 'rMid2', 0, 'val*0.546'],                         # ORIGINAL WAS 2, 'val*-0.546'],
    ['pJCMMid3Dwn_90_L', 'lMid3', 0, 'val*-0.637'],                         # ORIGINAL WAS 2, 'val*0.637'],
    ['pJCMMid3Dwn_90_R', 'rMid3', 0, 'val*0.637'],                          # ORIGINAL WAS 2, 'val*-0.637'],
    ['pJCMNeckBack_27', 'neckUpper', 0, 'val*-0.7581'],                     # GOOD
    ['pJCMNeckBack_27', 'neckLower', 0, 'val2*-1.197'],                     # GOOD
    ['pJCMNeckFwd_35', 'neckUpper', 0, 'val*0.76203'],                      # GOOD
    ['pJCMNeckFwd_35', 'neckLower', 0, 'val2*1.20327'],                     # GOOD
    ['pJCMNeckLowerSide_40_L', 'neckLower', 2, 'val*-1.911'],               # GOOD
    ['pJCMNeckLowerSide_40_R', 'neckLower', 2, 'val*1.911'],                # GOOD
    ['pJCMNeckTwist_22_L', 'neckLower', 1, 'val*2.606'],                    # GOOD
    ['pJCMNeckTwist_22_R', 'neckLower', 1, 'val*-2.606'],                   # GOOD

    # Unknown
    ['pJCMNeckTwist_Reverse', 'neckLower', 0, 'val*1.433'],

    # G8F
    ['pJCMPelvisFwd_25', 'pelvis', 0, 'val*-2.293'],                        # ORIGINAL WAS 'val*2.293'],
    ['pJCMPinky1Dwn_95_L', 'lPinky1', 0, 'val*-0.637'],                     # ORIGINAL WAS 2, 'val*0.637'],
    ['pJCMPinky1Dwn_95_R', 'rPinky1', 0, 'val*0.637'],                      # ORIGINAL WAS 2, 'val*-0.637'],
    ['pJCMPinky2Dwn_105_L', 'lPinky2', 0, 'val*-0.546'],                    # ORIGINAL WAS 2, 'val*0.546'],
    ['pJCMPinky2Dwn_105_R', 'rPinky2', 0, 'val*0.546'],                     # ORIGINAL WAS 2, 'val*-0.546'],
    ['pJCMPinky3Dwn_90_L', 'lPinky3', 0, 'val*-0.637'],                     # ORIGINAL WAS 2, 'val*0.637']
    ['pJCMPinky3Dwn_90_R', 'rPinky3', 0, 'val*0.637'],                      # ORIGINAL WAS 2, 'val*-0.637'],
    ['pJCMRing1Dwn_95_L', 'lRing1', 0, 'val*-0.637'],                       # ORIGINAL WAS 2, 'val*0.637'],  
    ['pJCMRing1Dwn_95_R', 'rRing1', 0, 'val*0.637'],                        # ORIGINAL WAS 2, 'val*-0.637'],
    ['pJCMRing2Dwn_105_L', 'lRing2', 0, 'val*-0.546'],                      # ORIGINAL WAS 2, 'val*0.546'],
    ['pJCMRing2Dwn_105_R', 'rRing2', 0, 'val*0.546'],                       # ORIGINAL WAS 2, 'val*-0.546'],
    ['pJCMRing3Dwn_90_L', 'lRing3', 0, 'val*-0.637'],                       # ORIGINAL WAS 2, 'val*0.637'],
    ['pJCMRing3Dwn_90_R', 'rRing3', 0, 'val*0.637'],                        # ORIGINAL WAS 2, 'val*-0.637'],
    ['pJCMShinBend_155_L', 'lShin', 0, '(val-1.571)*0.882'],                # GOOD
    ['pJCMShinBend_155_R', 'rShin', 0, '(val-1.571)*0.882'],                # GOOD
    ['pJCMShinBend_90_L', 'lShin', 0, 'val*0.637'],                         # GOOD
    ['pJCMShinBend_90_R', 'rShin', 0, 'val*0.637'],                         # GOOD
    ['pJCMShldrDown_40_L', 'lShldrBend', 0, 'val*-1.433'],                  # ORIGINAL WAS 2, 'val*1.433'],
    ['pJCMShldrDown_40_R', 'rShldrBend', 0, 'val*1.433'],                   # ORIGINAL WAS 2, 'val*-1.433'],
    ['pJCMShldrFwd_110_L', 'lShldrBend', 2, 'val*-0.521'],                  # ORIGINAL WAS 0
    ['pJCMShldrFwd_110_R', 'rShldrBend', 2, 'val*-0.521'],                  # ORIGINAL WAS 0
    ['pJCMShldrUp_90_L', 'lShldrBend', 0, 'val*0.637'],                     # ORIGINAL WAS 2, 'val*-0.637'],
    ['pJCMShldrUp_90_R', 'rShldrBend', 0, 'val*-0.637'],                    # ORIGINAL WAS 2, 'val*0.637'],
    ['pJCMThighBack_35_L', 'lThighBend', 0, 'val*1.638'],                   # GOOD
    ['pJCMThighBack_35_R', 'rThighBend', 0, 'val*1.638'],                   # GOOD
    ['pJCMThighFwd_115_L', 'lThighBend', 0, '(val+0.995)*-0.988'],          # GOOD
    ['pJCMThighFwd_115_R', 'rThighBend', 0, '(val+0.995)*-0.988'],          # GOOD
    ['pJCMThighFwd_57_L', 'lThighBend', 0, 'val*-1.006'],                   # GOOD
    ['pJCMThighFwd_57_R', 'rThighBend', 0, 'val*-1.006'],                   # GOOD
    ['pJCMThighSide_85_L', 'lThighBend', 2, 'val*-0.674'],                  # GOOD
    ['pJCMThighSide_85_R', 'rThighBend', 2, 'val*0.674'],                   # GOOD
    ['pJCMThumb1Bend_50_L', 'lThumb1', 0, 'val*1.146'],                     # GOOD
    ['pJCMThumb1Bend_50_R', 'rThumb1', 0, 'val*-1.146'],                    # ORIGINAL WAS 'val*1.146'],
    ['pJCMThumb1Up_20_L', 'lThumb1', 2, 'val*-2.866'],                      # GOOD
    ['pJCMThumb1Up_20_R', 'rThumb1', 2, 'val*-2.866'],                      # ORIGINAL WAS 'val*2.866'],
    ['pJCMThumb2Bend_65_L', 'lThumb2', 0, 'val*-0.882'],                    # ORIGINAL WAS 'val*0.882'],
    ['pJCMThumb2Bend_65_R', 'rThumb2', 0, 'val*0.882'],                     # GOOD
    ['pJCMThumb3Bend_90_L', 'lThumb3', 0, 'val*-0.637'],                    # ORIGINAL WAS 'val*0.637'],
    ['pJCMThumb3Bend_90_R', 'rThumb3', 0, 'val*0.637'],                     # GOOD
    ['pJCMToesUp_60_L', 'lToe', 0, 'val*0.955'],                            # ORIGINAL 'val*-0.955'],
    ['pJCMToesUp_60_R', 'rToe', 0, 'val*0.955'],                            # ORIGINAL 'val*-0.955'],

    # Unknown
    ['rShldrBend_CTRLMD_N_YRotate_110', 'rShldrBend', 1, 'val*0.521'],
    ['rShldrBend_CTRLMD_N_ZRotate_40', 'rShldrBend', 2, 'val*1.433'],
    ['rShldrBend_CTRLMD_N_ZRotate_n90', 'rShldrBend', 2, 'val*-0.637'],
  #  ['EyesSideSide', 'sight', 2, 'val * -0.955'],
  #  ['EyesSideR', 'sight', 2, 'val * -0.955'],
  #  ['EyesSideL', 'sight', 2, 'val * 0.955'],
  #  ['EyesUpDown', 'sight', 0, 'val * 0.955'],
]
samjay3d commented 3 years ago

Awesome thanks for adding this here!

We will take a look at this and see If we can implement your fix.