def load_from_json(self, node_data: dict, import_version: float): if 'geom' not in node_data: return # looks like a node was empty when it was imported geom = node_data['geom'] name = node_data['params']["obj_name"] geom_dict = json.loads(geom) if not geom_dict: print(self.name, 'contains no flatten geom') return unrolled_geom = unflatten(geom_dict) verts = unrolled_geom['Vertices'] edges = unrolled_geom['Edges'] polygons = unrolled_geom['Polygons'] materials = unrolled_geom.get('MaterialIdx', []) matrix = unrolled_geom['Matrix'] if self.do_not_add_obj_to_scene: self.node_dict[hash(self)] = unrolled_geom self.obj_name = name return with self.sv_throttle_tree_update(): bm = bmesh_from_pydata(verts, edges, polygons) if materials: for face, material in zip(bm.faces, materials): face.material_index = material obj = generate_object(name, bm) obj.matrix_world = matrix # rename if obj existed if not obj.name == name: node_data['params']["obj_name"] = obj.name self.obj_name = obj.name
def storage_set_data(self, storage): geom = storage['geom'] name = storage['params']["obj_name"] geom_dict = json.loads(geom) if not geom_dict: print(self.name, 'contains no flatten geom') return unrolled_geom = unflatten(geom_dict) verts = unrolled_geom['Vertices'] edges = unrolled_geom['Edges'] polygons = unrolled_geom['Polygons'] matrix = unrolled_geom['Matrix'] bm = bmesh_from_pydata(verts, edges, polygons) obj = generate_object(name, bm) obj.matrix_world = matrix # rename if obj existed if not obj.name == name: storage['params']["obj_name"] = obj.name self.id_data.freeze(hard=True) self.obj_name = obj.name self.id_data.unfreeze(hard=True)
def storage_set_data(self, storage): geom = storage['geom'] name = storage['params']["obj_name"] geom_dict = json.loads(geom) if not geom_dict: print(self.name, 'contains no flatten geom') return unrolled_geom = unflatten(geom_dict) verts = unrolled_geom['Vertices'] edges = unrolled_geom['Edges'] polygons = unrolled_geom['Polygons'] materials = unrolled_geom.get('MaterialIdx', []) matrix = unrolled_geom['Matrix'] with self.sv_throttle_tree_update(): bm = bmesh_from_pydata(verts, edges, polygons) if materials: for face, material in zip(bm.faces, materials): face.material_index = material obj = generate_object(name, bm) obj.matrix_world = matrix # rename if obj existed if not obj.name == name: storage['params']["obj_name"] = obj.name self.obj_name = obj.name