Exemplo n.º 1
0
def animate(animation, things, geometries, now):
    elapsed_time = (now - animation["time_start"])
    if animation["loop"]:
        elapsed_time = (elapsed_time % animation["duration"])
    action = None
    for frame in animation["actions"]:
        if (elapsed_time > frame["time"]):
            action = frame
    if (action == None):
        return
    thing = animation["thing"]
    if array_in_string(action.keys(), "geometry_name"):
        geometry = geometries[action["geometry_name"]]
        thing["geometry"] = geometry
    elif array_in_string(action.keys(), "children_names"):
        new_children = []
        action_children = action["children_names"]
        for name in action_children:
            new_child = things[name]
            new_children.append(new_child)
        thing["children"] = new_children
    else:
        for key in action.keys():
            if (key == "time"):
                continue
            thing[key] = action[key]
    return
Exemplo n.º 2
0
def animate(animation, things, geometries, now):
    elapsed_time = (now - animation["time_start"])
    if animation["loop"]:
            elapsed_time = (elapsed_time % animation["duration"])
    action = None
    for frame in animation["actions"]:
            if (elapsed_time > frame["time"]):
                        action = frame
    if (action == None):
            return 
    thing = animation["thing"]
    if array_in_string(action.keys(), "geometry_name"):
            geometry = geometries[action["geometry_name"]]
            thing["geometry"] = geometry
    elif array_in_string(action.keys(), "children_names"):
            new_children = []
            action_children = action["children_names"]
            for name in action_children:
                        new_child = things[name]
                        new_children.append(new_child)
            thing["children"] = new_children
    else:
            for key in action.keys():
                        if (key == "time"):
                                        continue
                        thing[key] = action[key]
    return 
Exemplo n.º 3
0
def thing_read(state, filename):
    thing = []
    text = None
    with open("/".join([state["things_dir"], filename])) as f:
        text = f.read()
    name, ext = filename_type(filename)
    map = json.loads(text)
    children = []
    geometry = None
    if array_in_string(map.keys(), "children_names"):
            child_names = map["children_names"]
            for child_name in child_names:
                        child = {"name" : child_name}
                        children.append(child)
    else:
            geometry_name = map["geometry_name"]
            geometry = state["geometries"][geometry_name]
    thing = thing_new(new_id(state), "", [0.0, 0.0, 0.0], [], children, geometry, None)
    thing.update(map)
    if (array_in_string(thing.keys(), "name") == False):
            thing["name"] = name
    return thing
Exemplo n.º 4
0
def thing_read(state, filename):
    thing = []
    text = None
    with open("/".join([state["things_dir"], filename])) as f:
        text = f.read()
    name, ext = filename_type(filename)
    map = json.loads(text)
    children = []
    geometry = None
    if array_in_string(map.keys(), "children_names"):
        child_names = map["children_names"]
        for child_name in child_names:
            child = {"name": child_name}
            children.append(child)
    else:
        geometry_name = map["geometry_name"]
        geometry = state["geometries"][geometry_name]
    thing = thing_new(new_id(state), "", [0.0, 0.0, 0.0], [], children,
                      geometry, None)
    thing.update(map)
    if (array_in_string(thing.keys(), "name") == False):
        thing["name"] = name
    return thing
Exemplo n.º 5
0
def thing_load(state, name):
    thing = {}
    text = None
    with open("/".join([state["things_dir"], name])) as f:
        text = f.read()
    map = json.loads(text)
    children = []
    geometry = None
    if array_in_string(map.keys(), "children_names"):
            child_names = map["children_names"]
            for child_name in child_names:
                        child = thing_load(state, child_name)
                        children.append(child)
    else:
            geometry_name = map["geometry_names"][int(map["geometry_index"])]
            geometry = state["geometries"][geometry_name]
    thing = thing_new(new_id(state), "", [0.0, 0.0, 0.0], [], children, geometry, None)
    thing.update(map)
    return thing
Exemplo n.º 6
0
def thing_load(state, name):
    thing = {}
    text = None
    with open("/".join([state["things_dir"], name])) as f:
        text = f.read()
    map = json.loads(text)
    children = []
    geometry = None
    if array_in_string(map.keys(), "children_names"):
        child_names = map["children_names"]
        for child_name in child_names:
            child = thing_load(state, child_name)
            children.append(child)
    else:
        geometry_name = map["geometry_names"][int(map["geometry_index"])]
        geometry = state["geometries"][geometry_name]
    thing = thing_new(new_id(state), "", [0.0, 0.0, 0.0], [], children,
                      geometry, None)
    thing.update(map)
    return thing