def do_rename(camname, old_id, new_id): if new_id == old_id: return obj = scene.get_persisted_obj(old_id) scene.add_object( Object(object_id=new_id, persist=obj.persist, **obj.data.__dict__)) if new_id in scene.all_objects: USERS[camname].target_id = new_id print(f"Duplicating {old_id} to {new_id}") arblib.delete_obj(scene, old_id)
def do_rename(camname, old_id, new_id): if new_id == old_id: return pobjs = arena.get_network_persisted_obj(old_id, BROKER, SCENE) if not pobjs: return data = json.dumps(pobjs[0]["attributes"]) arena.Object(objName=new_id, persist=True, data=data) USERS[camname].target_id = new_id print("Duplicating " + old_id + " to " + new_id) arblib.delete_obj(REALM, SCENE, old_id)
def show_redpill_scene(enabled): # any scene changes must not persist # show gridlines glen = arblib.GRIDLEN y = arblib.FLOOR_Y hcolor = arblib.rgb2hex(arblib.CLR_GRID) for z in range(-glen, glen + 1): name = "grid_z" + str(z) if enabled: arena.Object(objName=name, objType=arena.Shape.line, line=arena.Line((-glen, y, z), (glen, y, z), 1, hcolor)) else: arblib.delete_obj(REALM, SCENE, name) for x in range(-glen, glen + 1): name = "grid_x" + str(x) if enabled: arena.Object(objName=name, objType=arena.Shape.line, line=arena.Line((x, y, -glen), (x, y, glen), 1, hcolor)) else: arblib.delete_obj(REALM, SCENE, name) pobjs = arena.get_network_persisted_scene(BROKER, SCENE) for pobj in pobjs: obj = arblib.ObjectPersistence(pobj) # show occluded objects if obj.transparent_occlude: name = "redpill_" + obj.object_id if enabled: arena.Object( objName=name, objType=obj.object_type, location=obj.position, rotation=obj.rotation, scale=obj.scale, color=obj.color, clickable=True, url=obj.url, transparency=arena.Transparency(True, 0.5), ) print("Wrapping occlusion " + name) else: arblib.delete_obj(REALM, SCENE, name)
def scene_callback(msg): # This is the MQTT message callback function for the scene json_msg = json.loads(msg) if "action" not in json_msg or "data" not in json_msg or "object_id" not in json_msg: return if json_msg["action"] == "create" and json_msg["data"][ "object_type"] == "camera": # camera updates define users present camname = json_msg["object_id"] if camname not in USERS: USERS[camname] = arblib.User(camname, panel_callback) # save camera's attitude in the world USERS[camname].location = (json_msg["data"]["position"]["x"], json_msg["data"]["position"]["y"], json_msg["data"]["position"]["z"]) USERS[camname].rotation = (json_msg["data"]["rotation"]["x"], json_msg["data"]["rotation"]["y"], json_msg["data"]["rotation"]["z"], json_msg["data"]["rotation"]["w"]) rx = json_msg["data"]["rotation"]["x"] ry = json_msg["data"]["rotation"]["y"] # floating controller if not USERS[camname].follow_lock: ty = -(ry + USERS[camname].locky) / 0.7 * math.pi / 2 tx = -(rx + USERS[camname].lockx) / 0.7 * math.pi / 2 px = arblib.PANEL_RADIUS * -math.cos(ty) py = arblib.PANEL_RADIUS * math.sin(tx) pz = arblib.PANEL_RADIUS * math.sin(ty) USERS[camname].follow.position(location=(px, py, pz)) # else: # TODO: panel lock location drop is inaccurate # users[camname].lockx = rx + arblib.LOCK_XOFF # users[camname].locky = -(ry * math.pi) - arblib.LOCK_YOFF # mouse event elif json_msg["action"] == "clientEvent": # print(json_msg["object_id"] + " " + # json_msg["action"] + " " + json_msg["type"]) objid = json_msg["object_id"] # camera updates define users present camname = json_msg["data"]["source"] if camname not in USERS: USERS[camname] = arblib.User(camname, panel_callback) # show objects with events if json_msg["type"] == "mouseenter": if USERS[camname].redpill: show_redpill_obj(camname, objid) else: USERS[camname].set_textstatus(objid) elif json_msg["type"] == "mouseleave": USERS[camname].set_textstatus("") # handle click elif json_msg["type"] == "mousedown": # clicked on persisted object to modify update_controls(USERS[camname].target_id) USERS[camname].target_id = objid # always update if USERS[camname].mode == Mode.DELETE: arblib.delete_obj(REALM, SCENE, objid) elif USERS[camname].mode == Mode.MOVE: do_move_select(camname, objid) elif USERS[camname].mode == Mode.NUDGE: do_nudge_select(camname, objid) elif USERS[camname].mode == Mode.SCALE: do_scale_select(camname, objid) elif USERS[camname].mode == Mode.STRETCH: do_stretch_select(camname, objid) elif USERS[camname].mode == Mode.ROTATE: do_rotate_select(camname, objid) elif USERS[camname].mode == Mode.COLOR: arblib.color_obj(REALM, SCENE, objid, USERS[camname].target_style) elif USERS[camname].mode == Mode.OCCLUDE: arblib.occlude_obj(REALM, SCENE, objid, USERS[camname].target_style) elif USERS[camname].mode == Mode.RENAME or USERS[ camname].mode == Mode.PARENT: if len(USERS[camname].typetext) > 0: # edits already made new_id = USERS[camname].typetext USERS[camname].typetext = "" if USERS[camname].mode == Mode.PARENT: arblib.parent_obj(REALM, SCENE, objid, new_id) else: do_rename(camname, objid, new_id) else: # no edits yet, load previous name to change USERS[camname].typetext = objid USERS[camname].set_textright(USERS[camname].typetext)
def show_redpill_scene(enabled): # any scene changes must not persist # show gridlines name = "grid_redpill" path = [] glen = arblib.GRIDLEN y = arblib.FLOOR_Y for z in range(-glen, glen + 1): if (z % 2) == 0: path.append(Position(-glen, y, z)) path.append(Position(glen, y, z)) else: path.append(Position(glen, y, z)) path.append(Position(-glen, y, z)) for x in range(-glen, glen + 1): if (x % 2) == 0: path.append(Position(x, y, glen)) path.append(Position(x, y, -glen)) else: path.append(Position(x, y, -glen)) path.append(Position(x, y, glen)) if enabled: scene.add_object( ThickLine(object_id=name, path=path, color=arblib.CLR_GRID)) else: arblib.delete_obj(scene, name) objs = scene.get_persisted_objs() for object_id in objs: obj = objs[object_id] # show occluded objects if "material-extras" in obj.data and "transparentOccluder" in obj.data[ "material-extras"]: name = "redpill_" + obj.object_id if enabled: object_type = "box" if "object_type" in obj.data: object_type = obj.data.object_type position = Position() if "position" in obj.data: position = obj.data.position rotation = Rotation() if "rotation" in obj.data: rotation = obj.data.rotation scale = Scale() if "scale" in obj.data: scale = obj.data.scale url = None if "url" in obj.data: url = obj.data.url color = Color() if "material" in obj.data and "color" in obj.data.material: color = obj.data.material.color scene.add_object( Object( object_id=name, object_type=object_type, position=position, rotation=rotation, scale=scale, clickable=True, url=url, material=Material(color=color, transparent=True, opacity=0.5), )) print("Wrapping occlusion " + name) else: arblib.delete_obj(scene, name)
def scene_callback(_scene, event, msg): # This is the MQTT message callback function for the scene object_id = action = msg_type = object_type = None if "object_id" in msg: object_id = msg["object_id"] if "action" in msg: action = msg["action"] if "type" in msg: msg_type = msg["type"] if "data" in msg and "object_type" in msg["data"]: object_type = msg["data"]["object_type"] # print(f'{object_type} {action} {msg_type} {object_id}') if object_type == "camera": # camera updates define users present camname = object_id if camname not in USERS: USERS[camname] = arblib.User(scene, camname, panel_callback) # save camera's attitude in the world USERS[camname].position = Position(msg["data"]["position"]["x"], msg["data"]["position"]["y"], msg["data"]["position"]["z"]) USERS[camname].rotation = Rotation(msg["data"]["rotation"]["x"], msg["data"]["rotation"]["y"], msg["data"]["rotation"]["z"], msg["data"]["rotation"]["w"]) rx = msg["data"]["rotation"]["x"] ry = msg["data"]["rotation"]["y"] # floating controller if not USERS[camname].follow_lock: ty = -(ry + USERS[camname].locky) / 0.7 * math.pi / 2 tx = -(rx + USERS[camname].lockx) / 0.7 * math.pi / 2 px = arblib.PANEL_RADIUS * -math.cos(ty) py = arblib.PANEL_RADIUS * math.sin(tx) pz = arblib.PANEL_RADIUS * math.sin(ty) scene.update_object(USERS[camname].follow, position=Position(px, py, pz)) # else: # TODO: panel lock position drop is inaccurate # users[camname].lockx = rx + arblib.LOCK_XOFF # users[camname].locky = -(ry * math.pi) - arblib.LOCK_YOFF # mouse event elif action == "clientEvent": object_id = msg["object_id"] # camera updates define users present camname = msg["data"]["source"] if camname not in USERS: USERS[camname] = arblib.User(scene, camname, panel_callback) # show objects with events if msg_type == EVT_MOUSEENTER: if USERS[camname].redpill: show_redpill_obj(camname, object_id) else: USERS[camname].set_textstatus(object_id) elif msg_type == EVT_MOUSELEAVE: USERS[camname].set_textstatus("") # handle click elif msg_type == EVT_MOUSEDOWN: # clicked on persisted object to modify update_controls(USERS[camname].target_id) USERS[camname].target_id = object_id # always update if USERS[camname].mode == Mode.DELETE: arblib.delete_obj(scene, object_id) elif USERS[camname].mode == Mode.MOVE: do_move_select(camname, object_id) elif USERS[camname].mode == Mode.NUDGE: do_nudge_select(camname, object_id) elif USERS[camname].mode == Mode.SCALE: do_scale_select(camname, object_id) elif USERS[camname].mode == Mode.STRETCH: do_stretch_select(camname, object_id) elif USERS[camname].mode == Mode.ROTATE: do_rotate_select(camname, object_id) elif USERS[camname].mode == Mode.COLOR: arblib.color_obj(scene, object_id, Color(USERS[camname].target_style)) elif USERS[camname].mode == Mode.OCCLUDE: arblib.occlude_obj(scene, object_id, USERS[camname].target_style) elif USERS[camname].mode == Mode.RENAME or USERS[ camname].mode == Mode.PARENT: if len(USERS[camname].typetext) > 0: # edits already made new_id = USERS[camname].typetext USERS[camname].typetext = "" if USERS[camname].mode == Mode.PARENT: arblib.parent_obj(scene, object_id, new_id) else: do_rename(camname, object_id, new_id) else: # no edits yet, load previous name to change USERS[camname].typetext = object_id USERS[camname].set_textright(USERS[camname].typetext)