def set_clipboard(self, callback=None, object_type=None, scale=Scale(0.05, 0.05, 0.05), position=Position(0, 0, -CLIP_RADIUS/SCL_HUD), color=Color(255, 255, 255), url=None): if object_type: self.clipboard = Object( # show item to be created object_id=f"{self.camname}_clipboard", object_type=object_type, position=position, parent=self.hud.object_id, scale=Scale(scale.x/SCL_HUD, scale.y/SCL_HUD, scale.z/SCL_HUD), material=Material(color=color, transparent=True, opacity=0.4), url=url, clickable=True, evt_handler=callback) self.scene.add_object(self.clipboard) self.cliptarget = Circle( # add helper target object to find true origin object_id=f"{self.camname}_cliptarget", position=position, parent=self.hud.object_id, scale=Scale(0.005/SCL_HUD, 0.005/SCL_HUD, 0.005/SCL_HUD), material=Material(color=Color(255, 255, 255), transparent=True, opacity=0.4), clickable=True, evt_handler=callback) self.scene.add_object(self.cliptarget)
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 create_obj(camname, clipboard, position): randstr = str(random.randrange(0, 1000000)) # make a copy of static object in place new_obj = Object( persist=True, object_id=f"{clipboard.data.object_type}_{randstr}", object_type=clipboard.data.object_type, position=position, # undo clipboard rotation for visibility rotation=Rotation(0, 0, 0, 1), scale=clipboard.data.scale, material=Material(color=clipboard.data.material.color, transparent=False), url=clipboard.data.url, clickable=True) scene.add_object(new_obj) USERS[camname].target_id = new_obj.object_id print("Created " + new_obj.object_id)
def __init__(self, scene: Scene, camname, mode, x=0, y=0, label="", parent=None, drop=None, color=CLR_BUTTON, enable=True, callback=None, btype=ButtonType.ACTION): self.scene = scene if label == "": label = mode.value if parent is None: parent = camname scale = Scale(0.1, 0.1, 0.01) else: scale = Scale(1, 1, 1) self.type = btype self.enabled = enable if enable: self.colorbut = color else: self.colorbut = CLR_BUTTON_DISABLED self.colortxt = CLR_BUTTON_TEXT if len(label) > 8: # easier to read self.label = f"{label[:6]}..." else: self.label = label self.mode = mode self.dropdown = drop self.active = False if drop is None: obj_name = f"{camname}_button_{mode.value}" else: obj_name = f"{camname}_button_{mode.value}_{drop}" shape = Box.object_type if btype == ButtonType.TOGGLE: shape = Cylinder.object_type scale = Scale(scale.x / 2, scale.y, scale.z / 2) self.button = Object( # box is main button object_id=obj_name, object_type=shape, parent=parent, material=Material( color=self.colorbut, transparent=True, opacity=OPC_BUTTON, shader="flat"), position=Position(x * 1.1, PANEL_RADIUS, y * -1.1), scale=scale, clickable=True, evt_handler=callback, ) scene.add_object(self.button) scale = Scale(1, 1, 1) if btype == ButtonType.TOGGLE: scale = Scale(scale.x * 2, scale.y * 2, scale.z) self.text = Text( # text child of button object_id=f"{self.button.object_id}_text", parent=self.button.object_id, text=self.label, # position inside to prevent ray events position=Position(0, -0.1, 0), rotation=Rotation(-0.7, 0, 0, 0.7), scale=scale, color=self.colortxt, ) scene.add_object(self.text)
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)