def vector_from_seq(list_or_tuple): if not list_or_tuple: return length = len(list_or_tuple) if length >= 3: return Vector3(list_or_tuple[0], list_or_tuple[1], list_or_tuple[2]) elif length == 2: return Vector2(list_or_tuple[0], list_or_tuple[1])
def __call__(self): goals = [] step = TWO_PI / self.COUNT for angle in range(self.COUNT): angle *= step x = math.cos(angle) * self.radius y = math.sin(angle) * self.radius v = Vector2(x, y) v += self.center goals.append(v) return tuple(goals)
def _on_quadtree_changed(self): quadtree = services.sim_quadtree() if quadtree is None: return bounds = QtCircle(Vector2(0, 0), 10000) with Context(self.layer) as layer: filter_visualizers = ((placement.ItemType.SIM_POSITION, Color.GREEN), (placement.ItemType.SIM_INTENDED_POSITION, Color.YELLOW), (placement.ItemType.ROUTE_GOAL_SUPPRESSOR, Color.RED), (placement.ItemType.ROUTABLE_OBJECT_SURFACE, Color.CYAN)) for (quadtree_filter, color) in filter_visualizers: layer.set_color(color) for o in quadtree.query(bounds=bounds, surface_id=routing.SurfaceIdentifier(0, 0, 0), filter=quadtree_filter, flags=ObjectQuadTreeQueryFlag.IGNORE_SURFACE): if isinstance(o[2], Polygon): layer.add_polygon(o[2], altitude=0.1, routing_surface=o[3]) else: height = terrain.get_lot_level_height(o[2].center.x, o[2].center.y, o[3].secondary_id, services.current_zone_id()) + 0.1 layer.add_circle(sims4.math.Vector3(o[2].center.x, height, o[2].center.y), o[2].radius, altitude=KEEP_ALTITUDE)
def add_location_to_quadtree(self, placement_type, position=DEFAULT, orientation=DEFAULT, routing_surface=DEFAULT, index=0): position = self._agent.position if position is DEFAULT else position orientation = self._agent.orientation if orientation is DEFAULT else orientation routing_surface = self._agent.routing_surface if routing_surface is DEFAULT else routing_surface if placement_type in (placement.ItemType.SIM_POSITION, placement.ItemType.SIM_INTENDED_POSITION): quadtree_geometry = self.get_quadtree_polygon( position=position, orientation=orientation) else: quadtree_geometry = QtCircle(Vector2(position.x, position.z), self.agent_goal_radius) services.sim_quadtree().insert(self._agent, self._agent.id, placement_type, quadtree_geometry, routing_surface, False, index)
def get_quadtree_polygon(self, position, orientation): return QtCircle(Vector2(position.x, position.z), self.radius)
def get_bounds_2D(points): min_x = min(point.x for point in points) max_x = max(point.x for point in points) min_z = min(point.z for point in points) max_z = max(point.z for point in points) return (Vector2(min_x, min_z), Vector2(max_x, max_z))
def __init__(self, center, radius): self.center = Vector2(center.x, center.z) self.radius = radius