Profile Picture

Cinema 4d Python Script for FBX issues with CC characters

Posted By Comma 7 Years Ago
You don't have permission to rate!

Cinema 4d Python Script for FBX issues with CC characters

Author
Message
Comma
Comma
Posted 7 Years Ago
View Quick Profile
Junior Member

Junior Member (221 reputation)Junior Member (221 reputation)Junior Member (221 reputation)Junior Member (221 reputation)Junior Member (221 reputation)Junior Member (221 reputation)Junior Member (221 reputation)Junior Member (221 reputation)Junior Member (221 reputation)

Group: Forum Members
Last Active: 7 Years Ago
Posts: 1, Visits: 103
Hi, as some of you know there are some issues when importing an FBX into Cinema 4D:

1. The fingertips have a 90 ° twist
2. The alpha channel textures are inverted (black/white)
3. The Cornea material Specular Strength makes the eyes white

Because I have to import a lot of characters into c4d, changing all these settings by hand became a tedious job.
So I wrote a Python script which automates the process of rotating the fingertip joints, inverting all the alpha channels and sets the Cornea Specular Strength to 0. All with the push of one button :)
Here's the code for anyone who wants to use it while we wait for a future update. Just copy/paste the script in the Python Script Manager and hit Execute. Change the code however you please.

I'm using iClone 7.2, Cinema 4D Studio R19 and the characters are created in Character Creator v2.3. My guess is that it only works with CC characters because the script searches for specific objects, joints and material names. Non-CC characters will have different naming.

Disclaimer: I'm not a programmer but have some experience with JS, CSS, HTML. With my friend google and a lot of failed attempts the following code works for me:

import c4d
from c4d import gui

def main():
    # create Array
    A_Fingers = ["R_Finger", "L_Finger"]
    
    # Puts CC_Base_Body weight tag in a variable
    wTag = doc.SearchObject('CC_Base_Body').GetTag(c4d.Tweights) 
    
    # Calls "Reset Bind Pose" button in the weight tag
    c4d.CallButton(wTag, c4d.ID_CA_WEIGHT_TAG_RESET)
    
    # A loop where the corresponding fingers are reset to 0
    for k in A_Fingers:
        for i in range(0,5):
            doc.SearchObject(str(k) + str(i) + '2').SetAbsRot(c4d.Vector(0,0,0))
            
    # Calls "Set Bind Pose" button in the weight tag   
    c4d.CallButton(wTag, c4d.ID_CA_WEIGHT_TAG_SET)
    
    # Popup dialog to confirm that the fingers have been reset  
    gui.MessageDialog('Fingers reset')
    
    # Invert alpha shaders
    mat = doc.GetFirstMaterial()
    while(mat):
        channel = mat[c4d.MATERIAL_ALPHA_SHADER]
        if channel:
            mat[c4d.MATERIAL_ALPHA_SHADER][c4d.BITMAPSHADER_BLACKPOINT] = 1
            mat[c4d.MATERIAL_ALPHA_SHADER][c4d.BITMAPSHADER_WHITEPOINT] = 0  
        mat = mat.GetNext()    
    
    # Popup dialog to confirm alpha shaders are inverted
    gui.MessageDialog('Alpha shaders inverted')
    
    # Set specular strength to 0 in the Cornea reflectance channel
    refMat = doc.SearchMaterialInc('Cornea')
    refLayerCount = refMat.GetReflectionLayerCount()
    for i in range(0,refLayerCount):
        refLayer = refMat.GetReflectionLayerIndex(i)
        if refLayer.GetName() == 'Specular':
            refMat[c4d.REFLECTION_LAYER_MAIN_VALUE_SPECULAR + refLayer.GetDataID()] = 0
    
    # Popup dialog to confirm Specular Strength has been set to 0
    gui.MessageDialog('Cornea Specular Strength set to 0')
    
if __name__=='__main__':
    main()


Threaded View




Reading This Topic