Beispiel #1
0
 def test_index_by_nested(self):
     l = [
         {
             "id": 1,
             "age": 30,
             "person": {
                 "name": "Mike"
             }
         },
         {
             "id": 2,
             "age": 31,
             "person": {
                 "name": "Bob"
             }
         },
     ]
     k = utils.index_by(l, "person__name")
     res = {
         'Bob': {
             'age': 31,
             'id': 2,
             'person': {
                 'name': 'Bob'
             }
         },
         'Mike': {
             'age': 30,
             'id': 1,
             'person': {
                 'name': 'Mike'
             }
         }
     }
     self.assertEqual(k, res)
Beispiel #2
0
def get_node_object_name(node):
    idn_to_child = index_by(node["childs"], "header__idn")
    name_idn = "0x962"
    assert name_idn in idn_to_child, ("The node does not have "
                                      "a child with needed identifier")
    obj_name = idn_to_child[name_idn]["parsed"]
    return obj_name
Beispiel #3
0
def dump_cameras(max_fname):
    """Найти все камеры в данном макс файле.

    Найти все объекты Node, которые ссылаются на объекты камер.
    Собрать и вернуть имена этих объектов.
    """
    class_list = terse_class(storage_parse(max_fname, "ClassDirectory3"))
    scene = get_scene(max_fname, class_list)
    cameras_objs = get_scene_cameras(scene, class_list)
    cameras_indicies = index_by(cameras_objs, "self_idx")

    names = []
    name_to_class = index_by(class_list, "name")
    node_idx = name_to_class["Node"]["idx"]
    idn_to_scene_objects = group_by(scene[0]["childs"], "header__idn")
    for node_obj in idn_to_scene_objects[node_idx]:
        for ref in get_node_refs(node_obj):
            if ref in cameras_indicies:
                names.append(get_node_object_name(node_obj))
    return names
Beispiel #4
0
 def test_index_by(self):
     l = [
         {
             "id": 1,
             "age": 30
         },
         {
             "id": 2,
             "age": 31
         },
     ]
     k = utils.index_by(l, "id")
     res = {1: {'age': 30, 'id': 1}, 2: {'age': 31, 'id': 2}}
     self.assertEqual(k, res)
Beispiel #5
0
def get_node_refs(node):
    """Return node references.

    A Node usually contains a chunk with indexes to other objects in the Scene
    stream. The objects look like childs of the Node.
    """
    idn_to_child = index_by(node["childs"], "header__idn")
    ref_idn = "0x2035"
    assert ref_idn in idn_to_child, ("The node does not have "
                                     "a child with needed identifier")
    refs_hex = bytes.fromhex(idn_to_child[ref_idn]["hex_spaced"])
    refs_hex_io = io.BytesIO(refs_hex)
    refs = []
    while True:
        b = refs_hex_io.read(INT_S)
        if not b:
            break
        i, = unpack('i', b)
        refs.append(i)
    return refs