How to attach a template_list to objects' visibility

I have converted the add-on Flares Wizard to run on Blender 2.8. I am not the original author of the add-on. The add-on ran on Blender 2.79, but it appears that the author has not responded to questions to update it to 2.8, so I took it upon myself to do an update, as it’s a really fantastic add-on.

I have all but two things working. One of them involves the Lens Fare Elements list:


In the v dropdown button to the right of the list, there are options to Show All, Hide All, and Solo the selected list element. I have gotten these three options to work. Here is an example of how the Solo option works (which both shows and hides flare elements):

def solo_selected_element():
    obj = bpy.context.scene.objects
    elements = get_flare_elements()
    coll, index = get_element_group()
    if len(coll) > 0:
	active_element = obj[coll[index].object]        
	for element in elements:
    if len(elements) > 0:
	elements[0].animation_data.drivers[0].driver.expression = elements[0].animation_data.drivers[0].driver.expression                     

What I can’t figure out is how to make the individual elements in the list hide/show by clicking on its associated eyeball icon to the right of the element name. I can click on the eyeball icons and it appears something happens (Cycles redraws the image), but nothing really happens. Likewise, when I perform one of the Show All, Hide All, or Solo options, it doesn’t change the eyeball icon status for the individual elements.

Here is where the Lens Flare Elements list is set up:

# Lens Flare Elements            
class FLARES_WIZARD_PT_LensFlaresElements(Panel):
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "Lens Flares"
    bl_label = "Lens Flare Elements"
    bl_context = "objectmode"
    def poll(self, context):
	return len(context.scene.flare_group.coll)>0
    def draw(self, context):        
	scn = context.scene
	layout = self.layout           
	row = layout.row()
	row.template_list("UI_UL_element", "coll", scn.element_group, "coll", scn.element_group, "index", rows = 2)
	col = row.column(align=True)"FLARES_WIZARD_MT_add_element_menu", icon="ADD", text="")
	col.operator("flare.delete_flare_element", icon='REMOVE', text="")"FLARES_WIZARD_MT_element_settings_menu", icon="DOWNARROW_HLT", text="")

It appears that I’m missing some sort of link between the items in the template list and the objects behind the scenes…but I don’t know what it is, or even what to look for.

I’m thinking that it has something to do with this…

def register():
    for cls in classes:

    bpy.types.Scene.flare_group = bpy.props.PointerProperty(type=FlareGroup)

…where flare_group is attached to FlareGroup. I’ve gone down this rabbit hole and haven’t been able to see anything that looks wrong.

Here is my altered code for 2.8:

Also, you can download the original script that worked on 2.79 here as a reference (it also includes all of the flare graphics).

I install your 2.80 version and got this error : “fake_module: addon missing ‘bl_info’ gives bad performance!”.
I order to avoid this, add a folder in your zip file.
I find an error in the init file, line 1607, you wrote set_select instead of select_set.

1 Like

Good find on line 1607. I fixed that and re-uploaded the files (plus the supporting graphics files) here, so you won’t get the “fake_module” error:

I’m still scratching my head over why I haven’t been able to connect the visibility of the items in the Lens Flare Elements list with the actual objects in the project.

Your problem is in line 2557 in the init file, hide_select. It should be hide_set which isn’t working here. But with hide_viewport, I got no problem.

P.S. If you take a look at the info in scripting tab and click on the eye icon(outliner), you should see the name of the property but it shows for cube :[“Cube”].(null) = True.

1 Like

Terrific – thanks, @Elreenys! That fixes that issue. I added some additional code to keep the Lens Flare Elements items’ visibility in sync when you choose the Show All, Hide All, and Solo options, so that’s all working as it should.

Here’s a fixed version:

There’s just one last issue I’m trying to work through. When I click on the “Use obstacles” checkbox and there is an object in the “Use obstacles” listbox, the flare goes away (when Viewport Shading is set to Rendered) and an error is thrown in the console window:

Error in Driver: The following Python expression failed:
	'fac * Hit('Light','Controller')'

Traceback (most recent call last):
  File "<bpy driver>", line 1, in <module>
  File "V:\Video\Lens Flare test\Lens Flare test 04.blend\", line 70, in Hit
    index = RayCast(check, a,b )
  File "V:\Video\Lens Flare test\Lens Flare test 04.blend\", line 37, in RayCast
    bvh = tree.FromObject(obj, scn)
TypeError: expected 'Depsgraph' type found 'Scene' instead

It appears the problem is in in the RayCast() function, where it’s using mathutils.bvhtree (the tree.FromObject(obj, scn) call):

def RayCast(obj, start, end):
    """ Ray cast wraper """ 
    scn = bpy.context.scene
    bvh = tree.FromObject(obj, scn)    

I can only find the math.bvhtree documentation for the 2.78 API, so I’m not sure what changed in the 2.80 API. I thought that since it’s complaining about finding a scene, I needed to set scn to bpy.context.view_layer (as I have had to do in other spots of the code), but that doesn’t seem to work.

Here is a blend file that is set up to show the issue. Simply click on the “Use obstacles” checkbox and you’ll see the behavior.

Lens Flare test 05 - blockade.blend (1.4 MB)

Any ideas?

EDIT: I learned one thing, which is that the FromObject() call does not take a scene anymore; it takes a depsgraph. And I think the way to call it is like this:

def RayCast(obj, start, end):
    """ Ray cast wraper """ 
    depsgraph = bpy.context.evaluated_depsgraph_get()
    bvh = tree.FromObject(obj, depsgraph)

Still, I’m getting basically the same error after I made this change. :neutral_face:

I have found this discussion about the same problem. I tried with Blender 2.81 with the same lines depsgraph = bpy.evaluated_depsgraph_get() but Blender freeze when I activate the checkbox.

Back to 2.80 version, I change :

  • in init file, line 1612 error ( ->
  • in init file, line 1804 error (driver = dupli.driver_add(“hide”)) -> driver = dupli.driver_add("hide_viewport")
  • line 1894 same

Now Blender 2.80 freeze too with the checkbox activation.

Ah, that’s too bad. Thanks for checking, though. At least I have 99% of the features working. Hopefully this will be fixed in 2.81 and I’ll give it another try.

I wondered if there had been any progress on this since August :slight_smile:

It’s on my TODO list, but it’s a low priority at the moment. Feel free to download the version I have in my Aug 26 post and experiment. If you can fix it, great! If not, I’ll look into it…eventually :wink:

I believe this is what you’re looking for…

depsgraph = bpy.context.view_layer.depsgraph
bvh = tree.FromObject(obj, depsgraph)

This is working for me, but now there’s another error after activing Use Obstacles hehe…

Error in Driver: The following Python expression failed:
	'fac * Hit('Light','Controller')'

Traceback (most recent call last):
  File "<bpy driver>", line 1, in <module>
NameError: name 'Hit' is not defined

I’ll look into this more when I get some spare time :wink:

Nevermind, I have it all working now.

def RayCast(obj, start, end):
    """ Ray cast wraper """ 
    depsgraph = bpy.context.view_layer.depsgraph    
    bvh = tree.FromObject(obj, depsgraph)    
    localStart = obj.matrix_world.inverted() @ start
    localEnd = obj.matrix_world.inverted() @ end
    direction = localEnd- localStart
    ray = bvh.ray_cast(localStart, direction, get_distance(localEnd, localStart))

First of all I mistakenly disabled from auto running, which defined Hit(target, controller)

There was one extra error sorted out as well:
TypeError: Element-wise multiplication: not supported between 'Matrix' and 'Vector' types

This error is referring to both

localStart = obj.matrix_world.inverted() * start
localEnd = obj.matrix_world.inverted() * end

Simply change it to:

localStart = obj.matrix_world.inverted() @ start
localEnd = obj.matrix_world.inverted() @ end

Those changes work nicely. There’s a remaining niggle - if you add ghosts to the flare, an error of the form

Traceback (most recent call last):
  File "C:\Users\phils\AppData\Roaming\Blender Foundation\Blender\2.81\scripts\addons\Flares Wizard\", line 2187, in execute
  File "C:\Users\phils\AppData\Roaming\Blender Foundation\Blender\2.81\scripts\addons\Flares Wizard\", line 511, in Create_Ghost_Element
    GhostElementMat(element, os.path.join(elementsFolder, 'circle_smooth.jpg'))
  File "C:\Users\phils\AppData\Roaming\Blender Foundation\Blender\2.81\scripts\addons\Flares Wizard\", line 66, in GhostElementMat
    mapping.use_min = True
AttributeError: 'ShaderNodeMapping' object has no attribute 'use_min'

is reported.

use_min and use_max seem to no longer exist, just remove all occurrences of it.
I’ll upload a fully working version that has been tweaked to work with eevee when I can. :wink:

There’s also an issue with the drivers in the ghosts :

driver = material['Mapping'].driver_add("scale", 0)
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: bpy_struct.driver_add(): property "scale" not found

I’ve altered some of the internal math that seemed to have been skewing the results of a few elements (specifically Star and LensDirt)
There seemed to have been some hardcoded ‘magic numbers’ that didn’t make much sense in my debugging.

But anyways, here’s a fully working version (EEVEE ONLY):

PS. The initial global scale (under general settings) defaults to 1, which seems to be way too high. I usually set it to around 0.1 for nicer results.

Thanks so much for this update for 2.8! It took some searching but I finally found it!
So, I realize this is a rather old thread, but I had some issues with the add-on I though maybe you could help.

The issue I ran into is when I check “Transparent” under the Film settings in the Render Properties, the flares don’t show up in the render at all, they do in the rendered viewport, but not the actual render. The reason I’d like to render with a transparent background is because these flares lag my scene quite a bit, and I figured since the lens flare is basically just an overlay, I can render just those out on a transparent background and add them back to the final render later.

So, I’m not sure if there’s a fix for this, but if you know one, I’d be very grateful if you could help me out.


Hey! :smile:
I was able to reproduce the problem and it had me stumped for a moment hehe…
But even though the rendered result looks like an empty image, the color information is still there.

Here is an example of overlaying the ‘empty’ image over pure black in the compositor:

I hope this helps! :wink:

Thanks! Huh, that is weird, I did notice something along the lines like the flares need something “behind” it to show up. But I’m not sure if this will solve my problem, I’d like to export the render results as PNGs with alpha channels, and overlay the image sequence over the finished render. Can that be done in the compositor somehow?

My best advice would be to just try out some ideas and explore. The compositor is very powerful for image manipulation! :smiley:

I’ve been trying out stuff over the past 2 hours but the best I could come up with is to plug the image output of the render layer to the alpha socket of the composite node haha. In the meantime I’ve been looking for answers and found the culprit. It’s the add shader in the lens flare material nodes. I found this question where the person had the same issue. I’ll think what I’ll do is render out my animation first, then composite the flares over afterwards with the alpha over node. I think it’s my best shot.