Getting the frame from movie in material [SOLVED]



  • On 31/07/2015 at 08:14, xxxxxxxx wrote:

    I have a material with a movie loaded in the Color channel. When I apply the material to an object and set the Editor->Animate Preview option on, scrubbing the timeline, I see the movie playing in the object surface.
    However, when I try to get the bitmap from the material, using this python code, it always gets me the first frame, no matter where I have the play-head:

      
    import c4d   
    #Welcome to the world of Python   
      
    def main() :   
        mat=op[c4d.ID_USERDATA,1]   
        # is there anything in the Link user data?   
        if mat==None: return   
           
        # is it a Material?   
        if mat.GetType()!=5703: return   
           
        color_ch=mat[c4d.MATERIAL_USE_COLOR]   
        # is the Color channel turned on?   
        if color_ch==0: return   
           
        texture=mat[c4d.MATERIAL_COLOR_SHADER]   
        # is there anything in the Texture slot?   
        if texture==None: return   
           
        # is it a bitmap/movie?   
        if texture.GetType()!=5833: return   
           
        # render the bitmap to the Picture Viewer   
        irs = c4d.modules.render.InitRenderStruct()   
        if texture.InitRender(irs)==c4d.INITRENDERRESULT_OK:   
            bitmap = texture.GetBitmap()   
            texture.FreeRender()   
            if bitmap is not None:   
                c4d.bitmaps.ShowBitmap(bitmap)
    

    Yes, I do get a "RuntimeError: illegal operation, invalid cross-thread call" error in the last line of code but, even so, I get an image in the Picture Viewer and it is ALWAYS the first frame of the movie.

    How can I get the correctly calculated frame, according to the parameters set in the Animation tab inside the material channel?



  • On 31/07/2015 at 15:52, xxxxxxxx wrote:

    I managed to find a way to make it work...

    filename=texture[c4d.BITMAPSHADER_FILENAME]
        
        fps=doc.GetFps()
        
        t_min=doc.GetMinTime().GetFrame(fps)
        t_max=doc.GetMaxTime().GetFrame(fps)
        curr_time=doc.GetTime().GetFrame(fps)
        
        ml=c4d.bitmaps.MovieLoader()
        movie=ml.Open(filename)
        framecount, ml_fps = ml.GetInfo()
        
        new_frame=c4d.utils.RangeMap(curr_time,t_min,t_max,0,framecount,False)
        
        result,image=ml.Read(int(new_frame))
        
        if result==c4d.IMAGERESULT_OK:
            c4d.bitmaps.ShowBitmap(image)

    But it only works with movies. For image sequences, it doesn't. Must I do it by hand?



  • On 03/08/2015 at 02:42, xxxxxxxx wrote:

    Hi Rui,

    you might set the right frame with: Shader[c4d.BITMAPSHADER_TIMING_FROM] etc.
    Please have a look at this thread:

    Grabbing bitmap data off a shader

    Hope this helps?
    Best wishes
    Martin



  • On 03/08/2015 at 04:52, xxxxxxxx wrote:

    Thank you. I did found that thread.
    But I will have to calculate the frame by myself, right?
    I was expecting that, once we had a material with a movie or image sequence loaded in the Color channel and we had all the parameters of the animation set (by pressing Calculate for an image sequence, for example), there was a way to get the calculated frame automatically.



  • On 03/08/2015 at 05:28, xxxxxxxx wrote:

    Actually I´m not aware of any other way to get the corresponding image than calculating it by yourself.



  • On 03/08/2015 at 05:44, xxxxxxxx wrote:

    I understand that now. I just assumed that, since it happens automatically when when the editor animation preview is turned on, it would be something that could be accessed in code.



  • On 04/08/2015 at 05:39, xxxxxxxx wrote:

    Hi Rui,

    just want to confirm, there's no such functionality available. As Martin said, you will need to do it yourself. Sorry.


Log in to reply