Issues with the C4D to Unity Import python plugin - missing some types of objects



  • ExecutePasses worked for Polygon Reduction objects! That is a huge benefit to LOD versioning in Unity 👍 👍 👍

    Added here:

    #
    #SNIPPET FROM MAIN CODE
    #
    
    class ExportThread(threading.C4DThread):
    
        def __init__(self, doc, exportPath):
            self.doc = doc
            self.status = False
            self.exportPath = exportPath
            #ADDED THE LINE BELOW
            doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_EXPORT)
    
        def Main(self):
            # Export document to FBX
            self.status = documents.SaveDocument(self.doc, self.exportPath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, FBX_EXPORTER_ID)
    
        def GetStatus(self):
            return self.status
    
    #
    #SNIPPET FROM MAIN CODE
    #
    

    Cloners are still not working if they reference a spline. Any ideas why that is still giving us trouble?

    Leah



  • Sometime its needed to call it multiple time. So try to call ExcecutePass multiple time (maximum 3 is enough).

    Cheers,
    Maxime



  • @m_adam Shoot, tried calling it 3X and still nothing on the cloner (spline mode) object.

    (failing) test file attached
    fbxtest_v04.c4d



  • Currently the Spline Deformer breaks other objects in the scene, while the Bevel Deformer and Cloner Object in Spline Object mode only break themselves.

    GetContour? SetOptimizeCache? Anything else worth investigating? Maybe this is happening because it's being called via Unity automatically?



  • If I understand correctly, the issue is that the spline are not saved in the fbx?

    If yes make sure to set fbxExport[c4d.FBXEXPORT_SPLINES] = True

    At least here is working correctly, loading the saved fbx give me back the same result than previously.
    Cheers,
    Maxime.



  • @m_adam Then maybe the issue is that the command line fbx export is being executed from within Unity and not through C4D itself?

    Is there some kind of document referencing error that could happen if another program (other than C4D) were to call this script? Would caches behave differently?

    To answer your question, yes, I have FBXEXPORT_SPLINES set to True



  • I forgot to mention, Instances also fail to cache into Unity as well.

    I am thinking these are all related and to do with the cache being unavailable unless the script is being run within the C4D gui



  • Hi @jenandesign sorry for the delay and to not have spotted the issue earlier.

    But SaveDocument needs to be called in the main thread. So one solution for you is to send a CoreMessage with c4d.SendCoreMessage to catch it in a MessageData and process it.

    import c4d
    
    FBX_EXPORTER_ID = 1026370
    
    FBXEXPORT_TEXTURES = True
    FBXEXPORT_EMBED_TEXTURES = False
    FBXEXPORT_SAVE_NORMALS = True
    FBXEXPORT_ASCII = False
    
    
    
    # Main function
    def main():
        sourcePath = r"C:\Users\graphos\Downloads\fbxtest_v04.c4d"
        destinationPath = r"C:\Users\graphos\Documents\test.fbx"
        
        plug = c4d.plugins.FindPlugin(FBX_EXPORTER_ID, c4d.PLUGINTYPE_SCENESAVER)
        if plug is None:
            logger.appendMessage("FBX Export plugin not found")
            return False
    
        op = {}
        # Retrieve FBX Eporter settings object
        if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op) :
            if "imexporter" not in op:
                return False
    
            # BaseList2D object stored in "imexporter" key hold the settings
            fbxExport = op["imexporter"]
            if fbxExport is None :
                return False
    
            # Change export settings
            
            #THE FOLLOWING TWO LINES OF CODE WERE ADDED TO FIX SDS OBJECT IMPORT
            fbxExport[c4d.FBXEXPORT_SDS_SUBDIVISION] = True
            fbxExport[c4d.FBXEXPORT_SDS] = False
            fbxExport[c4d.FBXEXPORT_TEXTURES] = FBXEXPORT_TEXTURES
            fbxExport[c4d.FBXEXPORT_EMBED_TEXTURES] = FBXEXPORT_EMBED_TEXTURES
            fbxExport[c4d.FBXEXPORT_SAVE_NORMALS] = FBXEXPORT_SAVE_NORMALS
            fbxExport[c4d.FBXEXPORT_ASCII] = FBXEXPORT_ASCII
    
            doc = c4d.documents.LoadDocument(sourcePath, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS, None)
            status = False
            doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_EXPORT)
    
            # Export document to FBX
            status = c4d.documents.SaveDocument(doc, destinationPath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, FBX_EXPORTER_ID)
            c4d.documents.KillDocument(doc)
    
            # Retrieve export status and return it
            print status
    
    
    
    # Execute main()
    if __name__=='__main__':
        main()
    

    Cheers,
    Maxime.



  • Hi Maxime! Thanks for the suggestion, though I don't quite understand what you mean by your example... I don't see any use of SendCoreMessage in your snippet?

    SaveDocument is already present in the original code in the extended threading class "ExportThread" under definition Main(). How are you suggesting I change this?

    Thank you for the continued help ☺



  • SaveDocument is already present in the original code in the extended threading class "ExportThread"

    TO not make it happens in a thread.
    So to directly execute it in ExecuteConversion.

    The use of SendCoreMessage is a way, from a thread (and it's the case for you in ExportThread::Main) to send a message, that Cinema 4D will process on the Main thread (I didn't use in my code because in my case I'm in the main thread).
    So you can react to this message and do something (in your case SaveDocument). It was just for your information, regarding what's your thread is doing (only calling SaveDocument) I would say that using a thread here make no sense, and you should directly call SaveDocument in your ExecuteConversion function.

    Hope it's more clear.
    Cheers,
    Maxime.