def to_debug_color(self, color): """ Helper function for color conversion """ if color is None: return debug_pb.Color(r=255, g=255, b=255) else: r = getattr(color, "r", getattr(color, "x", 255)) g = getattr(color, "g", getattr(color, "y", 255)) b = getattr(color, "b", getattr(color, "z", 255)) if r + g + b <= 3: r *= 255 g *= 255 b *= 255 return debug_pb.Color(r=int(r), g=int(g), b=int(b))
async def debug_text(self, texts: Union[str, list], positions: Union[list, set], color=(0, 255, 0), size_px=16): """ Deprecated, may be removed soon """ if isinstance(positions, (set, list)): if not positions: return if isinstance(texts, str): texts = [texts] * len(positions) assert len(texts) == len(positions) await self._execute(debug=sc_pb.RequestDebug(debug=[ debug_pb.DebugCommand(draw=debug_pb.DebugDraw(text=[ debug_pb.DebugText( text=t, color=debug_pb.Color( r=color[0], g=color[1], b=color[2]), world_pos=common_pb.Point( x=p.x, y=p.y, z=getattr(p, "z", 10)), size=size_px) for t, p in zip(texts, positions) ])) ])) else: await self.debug_text([texts], [positions], color)
def to_debug_color(self, color): """ Helper function for color conversion """ if color is None: return debug_pb.Color(r=255, g=255, b=255) elif isinstance(color, tuple) and len(color) == 3: return debug_pb.Color(r=color[0], g=color[1], b=color[2]) else: r = getattr(color, "r", getattr(color, "x", 255)) g = getattr(color, "g", getattr(color, "y", 255)) b = getattr(color, "b", getattr(color, "z", 255)) if max(r, g, b) <= 1: r *= 255 g *= 255 b *= 255 return debug_pb.Color(r=int(r), g=int(g), b=int(b))
def to_debug_color(color: Union[tuple, Point3]): """ Helper function for color conversion """ if color is None: return debug_pb.Color(r=255, g=255, b=255) # Need to check if not of type Point3 because Point3 inherits from tuple if isinstance(color, (tuple, list)) and not isinstance( color, Point3) and len(color) == 3: return debug_pb.Color(r=color[0], g=color[1], b=color[2]) # In case color is of type Point3 r = getattr(color, "r", getattr(color, "x", 255)) g = getattr(color, "g", getattr(color, "y", 255)) b = getattr(color, "b", getattr(color, "z", 255)) if max(r, g, b) <= 1: r *= 255 g *= 255 b *= 255 return debug_pb.Color(r=int(r), g=int(g), b=int(b))
async def debug_text(self, texts, positions, color=(0, 255, 0)): if isinstance(positions, list): if not positions: return if isinstance(texts, str): texts = [texts] * len(positions) assert len(texts) == len(positions) await self._execute(debug=sc_pb.RequestDebug( debug=[debug_pb.DebugCommand(draw=debug_pb.DebugDraw( text=[debug_pb.DebugText( text=t, color=debug_pb.Color(r=color[0], g=color[1], b=color[2]), world_pos=common_pb.Point(x=p.x, y=p.y, z=p.z) ) for t, p in zip(texts, positions)] ))] )) else: await self.debug_text([texts], [positions], color)