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_transforms_gen(self, actor, target, fallback_routing_surface=None, fgl_kwargs=None, **kwargs): reserved_space_a = get_default_reserve_space(actor.species, actor.age) reserved_space_b = get_default_reserve_space(target.species, target.age) fgl_kwargs = fgl_kwargs if fgl_kwargs is not None else {} ignored_objects = {actor.id, target.id} ignored_ids = fgl_kwargs.get('ignored_object_ids') if ignored_ids is not None: ignored_objects.update(ignored_ids) fgl_kwargs['ignored_object_ids'] = ignored_objects for (transform, jig_params) in self._get_available_transforms_gen(actor, target): actor_angle = yaw_quaternion_to_angle(transform.orientation) (translation_a, orientation_a, translation_b, orientation_b, routing_surface) = generate_jig_polygon( actor.location, transform.translation, actor_angle, target.location, Vector2.ZERO(), 0, reserved_space_a.left, reserved_space_a.right, reserved_space_a.front, reserved_space_a.back, reserved_space_b.left, reserved_space_b.right, reserved_space_b.front, reserved_space_b.back, fallback_routing_surface=fallback_routing_surface, reverse_nonreletive_sim_orientation=self. reverse_actor_sim_orientation, **fgl_kwargs) if translation_a is None: continue yield (Transform(translation_a, orientation_a), Transform(translation_b, orientation_b), routing_surface, jig_params)
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