Ejemplo n.º 1
0
def update_object(obj, min_interval):
    url = obj["elmyra-url"]
    last_hash = obj.get("elmyra-hash")
    last_updated = obj.get("elmyra-updated")

    if last_updated and min_interval and time() - last_updated < min_interval:
        return False
    else:
        if path.exists(url):
            with open(url, "rb") as file:
                stl = file.read()
        else:
            # Get binary file with requests library
            stl = requests.get(url).content

        hasher = hashlib.sha1()
        hasher.update(stl)
        new_hash = hasher.hexdigest()

        if new_hash == last_hash:
            obj["elmyra-updated"] = int(time())

            return False
        else:
            # TODO: Save stl file temporarily into viz dir , not global tmp
            stl_path = path.join("/tmp", "{0}.stl".format(new_hash))

            with open(stl_path, "wb") as file:
                file.write(stl)

            bpy.ops.import_mesh.stl(filepath=stl_path)

            remove(stl_path)

            obj_new_geometry = bpy.context.scene.objects.active

            if obj.type == "EMPTY":
                common.remove_object(obj.name)
                obj = obj_new_geometry
            else:
                update_geometry(obj, obj_new_geometry)
                common.remove_object(obj_new_geometry.name)

            obj["elmyra-url"] = url
            obj["elmyra-hash"] = new_hash
            obj["elmyra-updated"] = int(time())

            return True
Ejemplo n.º 2
0
def update_object(obj):
    stl = get_stl(obj["elmyra-url"])
    new_hash = get_hash(stl)

    if new_hash != obj["elmyra-hash"]:
        stl_filepath = temp_write(stl, new_hash)

        bpy.ops.import_mesh.stl(filepath=stl_filepath)
        bpy.ops.object.shade_smooth()

        remove(stl_filepath)

        obj_new_geometry = bpy.context.scene.objects.active
        update_geometry(obj, obj_new_geometry)
        remove_object(obj_new_geometry.name)

        obj["elmyra-hash"] = new_hash

        return True
    else:
        return False
Ejemplo n.º 3
0
def update_object(obj):
    stl = get_stl(obj["elmyra-url"])
    new_hash = get_hash(stl)

    if new_hash != obj["elmyra-hash"]:
        stl_filepath = temp_write(stl, new_hash)

        bpy.ops.import_mesh.stl(filepath=stl_filepath)
        bpy.ops.object.shade_smooth()

        remove(stl_filepath)

        obj_new_geometry = bpy.context.scene.objects.active
        update_geometry(obj, obj_new_geometry)
        remove_object(obj_new_geometry.name)

        obj["elmyra-hash"] = new_hash

        return True
    else:
        return False