data_cache

I’ve tried to implement a sort of data storage, that keeps properties associeted with edges of a mesh object. There are some parts in Looptools script, that makes it look possible.

Below is a simplified part of the script. It produces desired result, but it refuses to include other edges with acompanying variables into this dictionary, it just rewrites the existing one. If I introduce a line of code that provides method by adding other edges in this mesh, it just produces error - complaining it will not tolerate the object.name(‘ControlPolygon’) any longer.


cache = {}

def cache_read(object, bm):
    if object.name not in cache:
        return(False, False, False, False, False)
    
    indices = [e.index for e in bm.edges]
    if indices != cache[object.name]["edges"]:
        return(False, False, False, False, False)
    
    input = [e.index for e in bm.edges if e.select and not e.hide]
    if input:
        idx = input[0]
    else:
        idx = 0
    if idx != rsurf_cache[object.name]["index"]:
        return(False, False, False, False, False)
    
    #reading cache values
    var_a = rsurf_cache[object.name][idx]["A"]
    var_b = rsurf_cache[object.name][idx]["B"]
    var_c = rsurf_cache[object.name][idx]["C"]
    
    return(True, input, var_a, var_b, var_c)

def cache_write(object, bm, var_a, var_b, var_c):
    indices = [e.index for e in bm.edges]
    input = [e.index for e in bm.edges if e.select and not e.hide]
    if input:
        idx = input[0]
    else:
        idx = 0
            
    rsurf_cache[object.name] = {"edges": indices, "index": idx}
    rsurf_cache[object.name][idx] = {"A": var_a, "B": var_b, "C": var_c}