Extracting UV map from multipass render



  • On 10/02/2014 at 05:31, xxxxxxxx wrote:

    Using Cinema R15 on OSX; I am trying to using the python API extract a UV map from a mulipass-render.

    This can be done none programatically by going into [ render -> edit render settings ] then enabling multipass and then adding and enabling 'Material UVW'

    The problem is that can't get this to reliably work programatically. Below is the code I trying:

    def test(doc) :
        #creates a new render data object	
        rd1=c4d.documents.RenderData()
        #add multipass
        vuvw=c4d.BaseList2D(c4d.Zmultipass) 
        vuvw.GetDataInstance()[c4d.MULTIPASSOBJECT_TYPE] = c4d.VPBUFFER_MAT_UV 
        rd1.InsertMultipass(vuvw)
        rd=rd1.GetDataInstance()	
        rd[c4d.RDATA_MULTIPASS_ENABLE]=True
        #det dimensions
        xres=800
        yres=800
        rd[c4d.RDATA_XRES]=float(xres)
        rd[c4d.RDATA_YRES]=float(yres)
        #set output
        bmp = c4d.bitmaps.MultipassBitmap(xres, yres, c4d.COLORMODE_RGBw)
        res = c4d.documents.RenderDocument(doc, rd, bmp)
        if res!=c4d.RENDERRESULT_OK:
            print 'Render Failed!!!'
            return False
        else:
            print 'Render Success!!!'
        #print layer names
        for i in range(bmp.GetLayerCount()) :
            print bmp.GetLayerNum(i).GetParameter(c4d.MPBTYPE_NAME)
    

    This code just prints out 'Background' instead of Background and 'Material UV'. (This is confirmed by writing the layers out to a file).

    I am not really sure what I am doing wrong, of course please ask if there is any additional information I can provide.
    Thanks for any help in advance!



  • On 10/02/2014 at 11:03, xxxxxxxx wrote:

    Give this one a try:

    #This script creates a new render preset and sets it to create an RGB & Material UV pass image to your desktop  
    #IMPORTANT!!: Make sure you rememebr to add a matrerial to your objects or the Material UV image will be black!!  
      
    import c4d, os  
    from c4d import bitmaps, documents  
    def main() :  
        
      firstRd = doc.GetFirstRenderData()  
      if not firstRd: return False  
        
      #If our custom render settings already exhist  
      #Use it..Don't create another one  
      if firstRd.GetName() == "Material UV pass":          
          xres = 800  
          yres = 800  
          firstRd[c4d.RDATA_XRES] = float(xres)  
          firstRd[c4d.RDATA_YRES] = float(yres)          
          bmp = bitmaps.BaseBitmap()  
          bmp.Init(int(xres), int(yres), firstRd[c4d.RDATA_FORMATDEPTH])  
          data = doc.GetActiveRenderData().GetData()  
          res = documents.RenderDocument(doc, data, bmp, c4d.RENDERFLAGS_EXTERNAL)  
      
          if res!=c4d.RENDERRESULT_OK:  
              print 'Render Failed!!!'  
              return False  
          else:  
              print 'Render Success!!!'          
            
      #If our custom render settings don't already exhist  
      #Create it first..then render the images  
      else:         
        
          myRd = c4d.documents.RenderData()  
          myRd.SetName("Material UV pass")  
          doc.InsertRenderData(myRd)      
          doc.SetActiveRenderData(myRd)  
      
          xres = 800  
          yres = 800  
          myRd[c4d.RDATA_XRES] = float(xres)  
          myRd[c4d.RDATA_YRES] = float(yres)  
        
          fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP)  
          path = os.path.join(fn,'render')      
          myRd[c4d.RDATA_PATH] = path  
        
          #Enable the Multi-Pass option  
          myRd[c4d.RDATA_MULTIPASS_ENABLE]=True  
        
          #Assign the passes container list of options to a variable  
          uvPass = c4d.BaseList2D(c4d.Zmultipass)      
        
          #Get the Material UV pass option      
          uvPass.GetDataInstance()[c4d.MULTIPASSOBJECT_TYPE] = c4d.VPBUFFER_MAT_UV  
        
          #Add the Material UV pass option to the render settings dialog  
          myRd.InsertMultipass(uvPass)  
        
          #Enable the Save Multi-Pass Image option  
          myRd[c4d.RDATA_MULTIPASS_SAVEIMAGE]=True  
      
          #Set the file path where to put the Material UV pass image  
          fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP)  
          path = os.path.join(fn,'uv')   
          myRd[c4d.RDATA_MULTIPASS_FILENAME] = path  
      
      
          #Set the output format to .png  
          myRd[c4d.RDATA_MULTIPASS_SAVEFORMAT] = c4d.FILTER_PNG  
          bmp = bitmaps.BaseBitmap()  
          bmp.Init(int(xres), int(yres), myRd[c4d.RDATA_FORMATDEPTH])  
      
          data = doc.GetActiveRenderData().GetData()  
          res = documents.RenderDocument(doc, data, bmp, c4d.RENDERFLAGS_EXTERNAL)  
      
          if res!=c4d.RENDERRESULT_OK:  
              print 'Render Failed!!!'  
              return False  
          else:  
              print 'Render Success!!!'  
      
        
      c4d.EventAdd()  
      
    if __name__=='__main__':  
      main()
    

    -ScottA



  • On 10/02/2014 at 15:20, xxxxxxxx wrote:

    Thanks, I'll give it a go in the morning and report back!


Log in to reply