def build_collection(data): name_full, index = common.decode_string(data, 0) # This message is not emitted by VRtist, only by Blender, so it is used only for Blender/Blender sync. # In generic mode, it conflicts with generic messages, so drop it if share_data.use_experimental_sync(): logger.warning("build_collection %s, ignored in experimental mode", name_full) return # Blender/Blender in VRtist (non generic) mode visible, index = common.decode_bool(data, index) hide_viewport = not visible offset, index = common.decode_vector3(data, index) temporary_visibility, index = common.decode_bool(data, index) logger.info("build_collection %s", name_full) collection = share_data.blender_collections.get(name_full) if collection is None: collection = bpy.data.collections.new(name_full) share_data.blender_collections[name_full] = collection collection.hide_viewport = hide_viewport collection.instance_offset = offset layer_collection = share_data.blender_layer_collections.get(name_full) if layer_collection: layer_collection.hide_viewport = not temporary_visibility else: # if the layer collection does not exists, store its state for later share_data.blender_collection_temporary_visibility[ name_full] = temporary_visibility
def build_object_visibility(data): name_full, index = common.decode_string(data, 0) hide_viewport, index = common.decode_bool(data, index) hide_select, index = common.decode_bool(data, index) hide_render, index = common.decode_bool(data, index) hide_get, index = common.decode_bool(data, index) logger.debug("build_object_visibility %s", name_full) object_ = share_data.blender_objects.get(name_full) if object_ is None: logger.warning("build_object_visibility %s : object not found", name_full) return object_.hide_viewport = hide_viewport object_.hide_select = hide_select object_.hide_render = hide_render object_.hide_set(hide_get)
def build_camera(data): camera_path, start = common.decode_string(data, 0) logger.info("build_camera %s", camera_path) camera_name, start = common.decode_string(data, start) camera = get_or_create_camera(camera_name) camera.lens, start = common.decode_float(data, start) camera.clip_start, start = common.decode_float(data, start) camera.clip_end, start = common.decode_float(data, start) camera.dof.use_dof, start = common.decode_bool(data, start) camera.dof.aperture_fstop, start = common.decode_float(data, start) colimator_name, start = common.decode_string(data, start) sensor_fit, start = common.decode_int(data, start) camera.sensor_width, start = common.decode_float(data, start) camera.sensor_height, start = common.decode_float(data, start) if sensor_fit == 0: camera.sensor_fit = "AUTO" elif sensor_fit == 1: camera.sensor_fit = "VERTICAL" else: camera.sensor_fit = "HORIZONTAL" get_or_create_object_data(camera_path, camera) # colimator if len(colimator_name) > 0: camera.dof.use_dof = True camera.dof.focus_object = get_or_create_path(colimator_name)
def build_grease_pencil_material(data): grease_pencil_material_name, start = common.decode_string(data, 0) material = share_data.blender_materials.get(grease_pencil_material_name) if not material: material = bpy.data.materials.new(grease_pencil_material_name) share_data._blender_materials[material.name_full] = material if not material.grease_pencil: bpy.data.materials.create_gpencil_data(material) gp_material = material.grease_pencil gp_material.show_stroke, start = common.decode_bool(data, start) gp_material.mode, start = common.decode_string(data, start) gp_material.stroke_style, start = common.decode_string(data, start) gp_material.color, start = common.decode_color(data, start) gp_material.use_overlap_strokes, start = common.decode_bool(data, start) gp_material.show_fill, start = common.decode_bool(data, start) gp_material.fill_style, start = common.decode_string(data, start) gp_material.fill_color, start = common.decode_color(data, start)
def _join_room(command: common.Command): if self.room is not None: _send_error( f"Received join_room but room {self.room.name} is already joined" ) return room_name, index = common.decode_string(command.data, 0) blender_version, index = common.decode_string(command.data, index) mixer_version, index = common.decode_string(command.data, index) ignore_version_check, index = common.decode_bool( command.data, index) generic_protocol, _ = common.decode_bool(command.data, index) try: self._server.join_room(self, room_name, blender_version, mixer_version, ignore_version_check, generic_protocol) except Exception as e: _send_error(f"{e!r}")
def decode_grease_pencil_layer(grease_pencil, data, index): grease_pencil_layer_name, index = common.decode_string(data, index) layer = grease_pencil.get(grease_pencil_layer_name) if not layer: layer = grease_pencil.layers.new(grease_pencil_layer_name) layer.hide, index = common.decode_bool(data, index) frame_count, index = common.decode_int(data, index) for _ in range(frame_count): index = decode_grease_pencil_frame(layer, data, index) return index
def build_collection(data): name_full, index = common.decode_string(data, 0) visible, index = common.decode_bool(data, index) hide_viewport = not visible offset, index = common.decode_vector3(data, index) temporary_visibility, index = common.decode_bool(data, index) logger.info("build_collection %s", name_full) collection = share_data.blender_collections.get(name_full) if collection is None: collection = bpy.data.collections.new(name_full) share_data.blender_collections[name_full] = collection collection.hide_viewport = hide_viewport collection.instance_offset = offset layer_collection = share_data.blender_layer_collections.get(name_full) if layer_collection: layer_collection.hide_viewport = not temporary_visibility else: # if the layer collection does not exists, store its state for later share_data.blender_collection_temporary_visibility[name_full] = temporary_visibility
def build_montage_mode(self, data): index = 0 montage, index = common.decode_bool(data, index) winman = bpy.data.window_managers["WinMan"] if hasattr(winman, "UAS_shot_manager_handler_toggle"): winman.UAS_shot_manager_handler_toggle = montage
def _set_room_keep_open(command: common.Command): room_name, offset = common.decode_string(command.data, 0) value, _ = common.decode_bool(command.data, offset) self._server.set_room_keep_open(room_name, value)
def decode_layer_uv(elmt, layer, data, index): pin_uv, index = common.decode_bool(data, index) uv, index = common.decode_vector2(data, index) elmt[layer].pin_uv = pin_uv elmt[layer].uv = uv return index
def decode_base_mesh(client, obj, data, index): bm = bmesh.new() position_count, index = common.decode_int(data, index) logger.debug("Reading %d vertices", position_count) for _pos_idx in range(position_count): co, index = common.decode_vector3(data, index) bm.verts.new(co) bm.verts.ensure_lookup_table() index = decode_bmesh_layer(data, index, bm.verts.layers.bevel_weight, bm.verts, decode_layer_float) edge_count, index = common.decode_int(data, index) logger.debug("Reading %d edges", edge_count) edges_data = struct.unpack(f"{edge_count * 4}I", data[index:index + edge_count * 4 * 4]) index += edge_count * 4 * 4 for edge_idx in range(edge_count): v1 = edges_data[edge_idx * 4] v2 = edges_data[edge_idx * 4 + 1] edge = bm.edges.new((bm.verts[v1], bm.verts[v2])) edge.smooth = bool(edges_data[edge_idx * 4 + 2]) edge.seam = bool(edges_data[edge_idx * 4 + 3]) index = decode_bmesh_layer(data, index, bm.edges.layers.bevel_weight, bm.edges, decode_layer_float) index = decode_bmesh_layer(data, index, bm.edges.layers.crease, bm.edges, decode_layer_float) face_count, index = common.decode_int(data, index) logger.debug("Reading %d faces", face_count) for _face_idx in range(face_count): material_idx, index = common.decode_int(data, index) smooth, index = common.decode_bool(data, index) vert_count, index = common.decode_int(data, index) face_vertices = struct.unpack(f"{vert_count}I", data[index:index + vert_count * 4]) index += vert_count * 4 verts = [bm.verts[i] for i in face_vertices] face = bm.faces.new(verts) face.material_index = material_idx face.smooth = smooth index = decode_bmesh_layer(data, index, bm.faces.layers.face_map, bm.faces, decode_layer_int) index = decode_bmesh_layer(data, index, bm.loops.layers.uv, loops_iterator(bm), decode_layer_uv) index = decode_bmesh_layer(data, index, bm.loops.layers.color, loops_iterator(bm), decode_layer_color) bm.normal_update() bm.to_mesh(obj.data) bm.free() # Load shape keys shape_keys_count, index = common.decode_int(data, index) obj.shape_key_clear() if shape_keys_count > 0: logger.debug("Loading %d shape keys", shape_keys_count) shapes_keys_list = [] for _i in range(shape_keys_count): shape_key_name, index = common.decode_string(data, index) shapes_keys_list.append(obj.shape_key_add(name=shape_key_name)) for i in range(shape_keys_count): shapes_keys_list[i].vertex_group, index = common.decode_string( data, index) for i in range(shape_keys_count): relative_key_name, index = common.decode_string(data, index) shapes_keys_list[i].relative_key = obj.data.shape_keys.key_blocks[ relative_key_name] for i in range(shape_keys_count): shape_key = shapes_keys_list[i] shape_key.mute, index = common.decode_bool(data, index) shape_key.value, index = common.decode_float(data, index) shape_key.slider_min, index = common.decode_float(data, index) shape_key.slider_max, index = common.decode_float(data, index) shape_key_data_size, index = common.decode_int(data, index) for i in range(shape_key_data_size): shape_key.data[i].co = Vector( struct.unpack("3f", data[index:index + 3 * 4])) index += 3 * 4 obj.data.shape_keys.use_relative, index = common.decode_bool( data, index) # Vertex Groups vg_count, index = common.decode_int(data, index) obj.vertex_groups.clear() for _i in range(vg_count): vg_name, index = common.decode_string(data, index) vertex_group = obj.vertex_groups.new(name=vg_name) vertex_group.lock_weight, index = common.decode_bool(data, index) vg_size, index = common.decode_int(data, index) for _elmt_idx in range(vg_size): vert_idx, index = common.decode_int(data, index) weight, index = common.decode_float(data, index) vertex_group.add([vert_idx], weight, "REPLACE") # Normals obj.data.use_auto_smooth, index = common.decode_bool(data, index) obj.data.auto_smooth_angle, index = common.decode_float(data, index) has_custom_normal, index = common.decode_bool(data, index) if has_custom_normal: normals = [] for _loop in obj.data.loops: normal, index = common.decode_vector3(data, index) normals.append(normal) obj.data.normals_split_custom_set(normals) # UV Maps and Vertex Colors are added automatically based on layers in the bmesh # We just need to update their name and active_render state: # UV Maps for uv_layer in obj.data.uv_layers: uv_layer.name, index = common.decode_string(data, index) uv_layer.active_render, index = common.decode_bool(data, index) # Vertex Colors for vertex_colors in obj.data.vertex_colors: vertex_colors.name, index = common.decode_string(data, index) vertex_colors.active_render, index = common.decode_bool(data, index) return index