daz3d / DazToC4D

Daz to Cinema 4D Bridge
https://www.daz3d.com/daz-to-cinema-4d-bridge
Other
29 stars 11 forks source link

Mistake in Morphs.py #41

Open brucek5 opened 2 years ago

brucek5 commented 2 years ago

The bridge is not removing linked mesh morphs resulting in large file size. Making the below change made a Cinema 4D file go from 263MB to 19MB, plus animation and UI performance was much faster.

In the file Morphs.py, line 28: if type(pm_tag) != "c4d.modules.character.CAPoseMorphTag":

should be (qoutes removed): if type(pm_tag) != c4d.modules.character.CAPoseMorphTag:

danielbui78 commented 2 years ago

Thanks, very much!

brucek5 commented 2 years ago

Hi danielbui78, I found the mistake while making a standalone script that “bakes” the linked mesh morphs into the Morph tag when importing a FBX file. In my script, I created a null called “Removed Morph Meshes” at the top of the project, and rather than deleting the meshes, I simply moved them to the null after the conversions. If I don’t need the meshes, then I delete the null and the meshes with it. Rather than re-inventing the wheel, I used your Morph.py code, hence how I found the mistake.

I also removed the two lines: if "Default:" in morph_name: continue The default pose doesn’t need to be a linked mesh.

Another change I made was to change the morph tag to just points: pm_tag[c4d.ID_CA_POSE_POINTS] = True pm_tag[c4d.ID_CA_POSE_P] = False pm_tag[c4d.ID_CA_POSE_R] = False pm_tag[c4d.ID_CA_POSE_S] = False

Position, Rotation and Scale are for using the tag as a “Correctional PSR Morph” where each morph strength is automatically driven by the Position, Rotation and Scale of a linked joint (which the Bridge isn’t using). I my script, it works fine, but if I make the same change to the Bridge code, for some reason I haven’t figure out, none of the morphs don’t do anything. So since having Position, Rotation and Scale in the Bridge doesn’t add much memory, I left it as is.

Bruce

danielbui78 commented 2 years ago

Sorry, I'm not fully understanding your last message. Can you give a test case scenario with step-by-step instructions which I can run before and after making your proposed code modifications to understand the effects? Also, I am assuming you propose to add the additional instructions here? https://github.com/daz3d/DazToC4D/blob/d5d27f4433f3326d469129d26b1c67ec0a977178/Cinema%204D/appdir_common/plugins/DazToC4D/lib/Morphs.py#L42

brucek5 commented 2 years ago

danielbui78,

Just ignore my last message, doesn't hurt anything leaving it the way it is and the extra memory is very, very small.

FYI - The Pose P, R, S settings being "True" (a PSR Morph Tag) is for when you want Cinema 4D to perform joint correction for you based on the position, scale, and rotation of a supplied joint (or object). Since the Bridge is not providing links to joints, it's only using Points. If the DAZ3D JCM morphs where a linear function (which they're not) to joint rotation, this would be a preferred means to control the morph strength because the morph tag itself would be performing the tasks that all the joint pythons scripts are doing. You'll see in the Morph Tag they're extra PSR variables being shown for variables that normally are not shown when using the tag for just user defined and controlled morphs like the Bridge is using it for. In addition, if you make them all false, then the morph tag will clear all it's memory (because it's a very different type of Morph tag) requiring all the morphs to be re-installed into the tag. That's why when I modify the Bridge code to what I posted above, the morphs stopped working because the morphs we're already populated.

Bruce