Results 1 to 11 of 11
  1. #1

    Force material update OpenGL render active viewport

    Sometimes doing OpenGL render active viewport is a very fast way of rendering an animation, especially 2D animations, when no lighting or fancy shading is needed.

    There is a problem where materials don't update in the viewport, like switching textures or animating UV's.

    This little script helped me to fix that problem for both scrubbing through the timeline, and rendering/playblasting the viewport:

    Tested in Blender v2.77. Just run it once after opening the .blend you are working on.

    Code:
    import bpy
    
    
    mats = bpy.data.materials
    
    
    def my_handler(scene):
    	for m in mats:
    		m.invert_z = False
    		
    bpy.app.handlers.frame_change_pre.append(my_handler)
    It adds a custom handler that loops through all the materials and sets a material property so Blender thinks it needs an update. I just picked invert_z because it has that value by default, and it doesnt ruin anything else.

    I hope this helps some other people out!

    Edit: Thanks for the code wrapping tip MCHammond and proxe!
    Last edited by Sammey; 30-Aug-16 at 03:47.



  2. #2
    Please remove cursor indicator after you paste the code in the thread below. The code in this thread is incorrect. See below.
    Attached Images Attached Images
    Last edited by bkjernisted; 23-May-16 at 09:45.



  3. #3

    made a mistake cursor indicator needs to be removed after you paste

    Attached Images Attached Images
    Last edited by bkjernisted; 23-May-16 at 09:34. Reason: cursor indicator needs to be removed



  4. #4
    When I tried to enable the script, I could not get it to load. Any suggestions? Sammey, sorry about the mistakes in my posts. I was not sure what you meant by tab and was looking for some clarification. Is the quotation mark supposed to be in the script? I am not a code guy. Once the script is enabled what is the procedure with the addon? Thanks



  5. #5
    Member
    Join Date
    Jan 2012
    Posts
    1,003
    Thank you for your tip



  6. #6
    Member MCHammond's Avatar
    Join Date
    Oct 2007
    Location
    Derby, UK
    Posts
    755
    Code:
    import bpy
    
    mats = bpy.data.materials
    
    def my_handler(scene):
        for m in mats:
            m.invert_z = False
    
    bpy.app.handlers.frame_change_pre.append(my_handler)



  7. #7
    Member proxe's Avatar
    Join Date
    Mar 2012
    Location
    Unknown
    Posts
    920
    Originally Posted by MCHammond View Post
    Code:
    import bpy
    
    mats = bpy.data.materials
    
    def my_handler(scene):
        for m in mats:
            m.invert_z = False
    
    bpy.app.handlers.frame_change_pre.append(my_handler)
    Indeed, Sammey you need to encase the properly formatted text in CODE brackets or edit your post and click Go Advanced properly format the code, select it and click the # in the toolbar region of the editor.

    Thanks for the share



  8. #8
    Member
    Join Date
    May 2012
    Location
    Barcelona, Spain
    Posts
    584
    so if I want to do this for 1 geometry?... how would it be when there is a linked character?



  9. #9
    Exactly what I was looking for!
    Really helpfull
    This script should be directly included!

    Thanks! It's the first time I copy/paste a script code inside Blender


    If someone could do a .py file of it, it will be cool. I tried and failed (lol)

    I want a .py script file cause I could add it to my user preference. (Actually we have to copy paste the script each time we launch blender...)
    Last edited by CurtYoung; 12-Oct-17 at 20:13.



  10. #10
    Member
    Join Date
    Sep 2013
    Location
    paris
    Posts
    93
    Hi thanks a lot for the little script ! i didn't have a chance to test it yet, but this is super useful !
    Does it work with animated texture ? this has always been a problem in the viewport in blender for me...
    Anyway i put together a little installable script (like any other addon) which put a texture icon in the down header of the 3d view. It's an on off toggle for the forcing of materials update, i thought it could be great as an addon but you don't need it all the time, and the handler can make performance decrease in playback... Feel free to modify it in any way !
    and thanks again !
    https://www.dropbox.com/s/14jt6w4m32...e%20v1.py?dl=0

    edit : i confirm, it works perfectly with video texture, i tested the script in 2.78 and 2.79 on mac so far, when playing (not going frame to frame with right or left arrow, when playback with shift A), it allows to update the video texture
    glad to find this script after 1 year of existence !
    Last edited by tonton; 13-Oct-17 at 11:55.



  11. #11
    Great!
    Thanks for the addon, I still use 2.77 and it works fine

    It's really helpful



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •