def _draw_spawn_points(self):
     zone = services.current_zone()
     with Context(self.layer) as layer:
         for spawn_point in zone.spawn_points_gen():
             point_color = SpawnPointVisualizer.SPAWN_POINT_COLORS.get(
                 spawn_point.obj_def_guid, Color.WHITE)
             footprint_polygon = spawn_point.get_footprint_polygon()
             if footprint_polygon is not None:
                 layer.add_polygon(footprint_polygon,
                                   color=point_color,
                                   altitude=0.1)
             (valid_positions, invalid_positions
              ) = spawn_point.get_valid_and_invalid_positions()
             layer.set_color(point_color)
             for slot_position in valid_positions:
                 layer.add_point(slot_position, altitude=0.1)
             layer.set_color(Color.RED)
             for slot_position in invalid_positions:
                 layer.add_point(slot_position, altitude=0.1)
             layer.set_color(Color.WHITE)
             layer.add_text_world(spawn_point.get_approximate_center(),
                                  spawn_point.get_name())
         layer.set_color(Color.CYAN)
         for corner in services.current_zone().lot.corners:
             layer.add_point(corner, size=1.0)
    def redraw(self, sim):
        routing_context = sim.get_routing_context()
        routing_polygon = routing_context.get_quadtree_polygon()

        def _draw_polygon(position, *, color):
            if isinstance(routing_polygon, QtCircle):
                layer.add_circle(position, routing_polygon.radius, color=color)
            else:
                layer.add_polygon(list(routing_polygon), color=color)

        with Context(self.layer,
                     altitude=0.1,
                     routing_surface=sim.routing_surface) as layer:
            position_color = pseudo_random_color(sim.id)
            position = sim.position
            orientation = sim.orientation
            _draw_polygon(position, color=position_color)
            if orientation != sims4.math.Quaternion.ZERO():
                angle = sims4.math.yaw_quaternion_to_angle(orientation)
                layer.add_arrow(position, angle, color=position_color)
            if sim.parent is not None:
                return
            intended_transform = sim.intended_transform
            intended_position = intended_transform.translation
            intended_position_color = pseudo_random_color(sim.id + 1)
            _draw_polygon(intended_position, color=intended_position_color)
            intended_orientation = intended_transform.orientation
            if intended_orientation != sims4.math.Quaternion.ZERO():
                angle = sims4.math.yaw_quaternion_to_angle(
                    intended_orientation)
                layer.add_arrow(intended_position,
                                angle,
                                color=intended_position_color)
Esempio n. 3
0
 def _on_update(self):
     broadcaster_service = services.current_zone().broadcaster_service
     with Context(self.layer) as layer:
         for broadcaster in broadcaster_service.get_broadcasters_gen(
                 inspect_only=True):
             constraint = broadcaster.get_constraint()
             if constraint is not None:
                 color = pseudo_random_color(broadcaster.guid)
                 _draw_constraint(layer, constraint, color)
             broadcasting_object = broadcaster.broadcasting_object
             if broadcasting_object is not None:
                 broadcaster_center = broadcasting_object.position
                 layer.add_circle(broadcaster_center,
                                  radius=0.3,
                                  color=color)
             for linked_broadcaster in broadcaster.get_linked_broadcasters_gen(
             ):
                 linked_broadcasting_object = linked_broadcaster.broadcasting_object
                 while linked_broadcasting_object is not None:
                     layer.add_point(linked_broadcasting_object.position,
                                     size=0.25,
                                     color=color)
                     layer.add_segment(broadcaster_center,
                                       linked_broadcasting_object.position,
                                       color=color)
         for broadcaster in broadcaster_service.get_pending_broadcasters_gen(
         ):
             color = pseudo_random_color(broadcaster.guid)
             (r, g, b, a) = sims4.color.to_rgba(color)
             color = sims4.color.from_rgba(r, g, b, a * 0.5)
             broadcasting_object = broadcaster.broadcasting_object
             while broadcasting_object is not None:
                 layer.add_circle(broadcasting_object.position, color=color)
 def _on_transition_destinations_changed(self,
                                         sim,
                                         transition_destinations,
                                         transition_sources,
                                         max_cost,
                                         preserve=False):
     POSSIBLE_SOURCE = from_rgba(50, 50, 50, 0.5)
     with Context(self.layer, preserve=preserve) as layer:
         for (path_id, constraint, weight) in transition_destinations:
             alpha = 1.0
             if max_cost > 0:
                 alpha = alpha - weight / max_cost
                 if alpha < 0.01:
                     alpha = 0.01
             color = pseudo_random_color(path_id, a=alpha)
             if constraint.was_selected:
                 _draw_constraint(layer,
                                  constraint,
                                  color,
                                  altitude_modifier=0.5)
             else:
                 _draw_constraint(layer, constraint, color)
         for constraint in transition_sources:
             if constraint.was_selected:
                 _draw_constraint(layer,
                                  constraint,
                                  POSSIBLE_SOURCE,
                                  altitude_modifier=0.5)
             else:
                 _draw_constraint(layer, constraint, POSSIBLE_SOURCE)
def debugvis_simposition_stop(opt_sim: OptionalTargetParam = None,
                              _connection=None):
    if opt_sim is None:
        sim_info_manager = services.sim_info_manager()
        if sim_info_manager is not None:
            while True:
                for info in sim_info_manager.get_all():
                    while info.account_id is not None and info.is_instanced():
                        sim = info.get_sim_instance()
                        if sim is not None and sim.id in _sim_layer_visualizers:
                            visualizer = _sim_layer_visualizers[sim.id]
                            visualizer.stop()
                            del _sim_layer_visualizers[sim.id]
                            with Context(visualizer.layer):
                                pass
                            sims4.commands.output(
                                'Removed visualization: {0}'.format(
                                    visualizer.layer), _connection)
                            sims4.commands.client_cheat(
                                'debugvis.layer.disable {0}'.format(
                                    visualizer.layer), _connection)
    elif not _stop_sim_visualizer(opt_sim, _connection, 'sim_pos',
                                  _sim_layer_visualizers):
        return 0
    return 1
 def stop(self):
     routing_component = self.sim.routing_component
     if self._on_position_changed in routing_component.on_follow_path:
         routing_component.on_follow_path.remove(self._on_position_changed)
     if self.sim._on_location_changed_callbacks is not None and self._on_position_changed in self.sim._on_location_changed_callbacks:
         self.sim.unregister_on_location_changed(self._on_position_changed)
     with Context(self.layer):
         pass
Esempio n. 7
0
 def _redraw(self, _=None):
     los_constraint = self._sim.los_constraint
     with Context(self.layer,
                  routing_surface=los_constraint.routing_surface) as layer:
         _draw_constraint(layer, los_constraint, self._color)
         _draw_constraint(layer,
                          self._sim.get_social_group_constraint(None),
                          self._color_semitrans)
 def _on_mood_changed(self):
     offset = sims4.math.Vector3.Y_AXIS() * 0.4
     BONE_INDEX = 5
     mood_name = strip_prefix(self.sim.get_mood().__name__, 'Mood_')
     with Context(self.layer) as context:
         context.add_text_object(self.sim,
                                 offset,
                                 mood_name,
                                 bone_index=BONE_INDEX)
 def _on_quadtree_changed(self):
     quadtree = services.sim_quadtree()
     if quadtree is None:
         return
     zone = services.current_zone()
     pos = sims4.math.Vector2(0, 0)
     bounds = sims4.geometry.QtCircle(pos, 10000)
     all_sims_positions = quadtree.query(
         bounds=bounds,
         level=self.ALL_LEVELS,
         filter=placement.ItemType.SIM_POSITION,
         flags=sims4.geometry.ObjectQuadTreeQueryFlag.IGNORE_LEVEL)
     all_intended = quadtree.query(
         bounds=bounds,
         level=self.ALL_LEVELS,
         filter=placement.ItemType.SIM_INTENDED_POSITION,
         flags=sims4.geometry.ObjectQuadTreeQueryFlag.IGNORE_LEVEL)
     all_suppressors = quadtree.query(
         bounds=bounds,
         level=self.ALL_LEVELS,
         filter=placement.ItemType.ROUTE_GOAL_SUPPRESSOR,
         flags=sims4.geometry.ObjectQuadTreeQueryFlag.IGNORE_LEVEL)
     with Context(self.layer) as layer:
         layer.set_color(Color.GREEN)
         for o in all_sims_positions:
             height = terrain.get_lot_level_height(
                 o[2].center.x, o[2].center.y, o[3], zone.id) + 0.1
             pos = sims4.math.Vector3(o[2].center.x, height, o[2].center.y)
             layer.add_circle(pos, o[2].radius, altitude=KEEP_ALTITUDE)
         layer.set_color(Color.YELLOW)
         for o in all_intended:
             if isinstance(o[2], Polygon):
                 routing_surface = routing.SurfaceIdentifier(
                     zone.id, o[3], routing.SURFACETYPE_WORLD)
                 layer.add_polygon(o[2],
                                   altitude=0.1,
                                   routing_surface=routing_surface)
             else:
                 height = terrain.get_lot_level_height(
                     o[2].center.x, o[2].center.y, o[3], zone.id) + 0.1
                 pos = sims4.math.Vector3(o[2].center.x, height,
                                          o[2].center.y)
                 layer.add_circle(pos, o[2].radius, altitude=KEEP_ALTITUDE)
         layer.set_color(Color.RED)
         for o in all_suppressors:
             if isinstance(o[2], Polygon):
                 routing_surface = routing.SurfaceIdentifier(
                     zone.id, o[3], routing.SURFACETYPE_WORLD)
                 layer.add_polygon(o[2],
                                   altitude=0.1,
                                   routing_surface=routing_surface)
             else:
                 height = terrain.get_lot_level_height(
                     o[2].center.x, o[2].center.y, o[3], zone.id) + 0.1
                 pos = sims4.math.Vector3(o[2].center.x, height,
                                          o[2].center.y)
                 layer.add_circle(pos, o[2].radius, altitude=KEEP_ALTITUDE)
Esempio n. 10
0
 def _on_quadtree_changed(self):
     fire_service = services.get_fire_service()
     fire_quadtree = fire_service.fire_quadtree
     flammable_quadtree = fire_service.flammable_objects_quadtree
     zone = services.current_zone()
     pos = sims4.math.Vector2(0, 0)
     bounds = sims4.geometry.QtCircle(pos, 10000)
     if fire_quadtree is not None:
         fire_objects = fire_quadtree.query(bounds)
     else:
         fire_objects = []
     if flammable_quadtree is not None:
         flammable_objects = flammable_quadtree.query(bounds)
     else:
         flammable_objects = []
     with Context(self.layer) as layer:
         layer.set_color(Color.RED)
         for obj in fire_objects:
             level = obj.location.level
             height = terrain.get_lot_level_height(
                 obj.position.x, obj.position.z, level, zone.id) + 0.1
             radius = FireService.FIRE_QUADTREE_RADIUS
             pos = sims4.math.Vector3(obj.position.x, height,
                                      obj.position.z)
             layer.add_circle(pos, radius, altitude=KEEP_ALTITUDE)
         layer.set_color(Color.YELLOW)
         for obj in flammable_objects:
             if obj.location.world_routing_surface is None:
                 pass
             level = obj.location.level
             height = terrain.get_lot_level_height(
                 obj.position.x, obj.position.z, level, zone.id) + 0.1
             radius = obj.object_radius
             if obj.fire_retardant:
                 radius += FireService.FIRE_RETARDANT_EXTRA_OBJECT_RADIUS
             location = sims4.math.Vector2(obj.position.x, obj.position.z)
             object_bounds = obj.object_bounds_for_flammable_object(
                 location=location,
                 fire_retardant_bonus=FireService.
                 FIRE_RETARDANT_EXTRA_OBJECT_RADIUS)
             if isinstance(object_bounds, QtCircle):
                 pos = sims4.math.Vector3(obj.position.x, height,
                                          obj.position.z)
                 layer.add_circle(pos, radius, altitude=KEEP_ALTITUDE)
             else:
                 while isinstance(object_bounds, QtRect):
                     v0 = sims4.math.Vector3(object_bounds.a.x, height,
                                             object_bounds.a.y)
                     v2 = sims4.math.Vector3(object_bounds.b.x, height,
                                             object_bounds.b.y)
                     delta = v2 - v0
                     v1 = v0 + sims4.math.Vector3(delta.x, 0, 0)
                     v3 = v0 + sims4.math.Vector3(0, 0, delta.z)
                     vertices = [v0, v1, v2, v3]
                     layer.add_polygon(vertices, altitude=KEEP_ALTITUDE)
Esempio n. 11
0
 def _draw_all_portals(self, *_, **__):
     object_manager = services.object_manager()
     with Context(self.layer, preserve=True) as context:
         context.layer.clear()
     if self.portal_obj_id:
         portal_obj = object_manager.get(self.portal_obj_id)
         if portal_obj is not None:
             self._draw_portal_obj(portal_obj, portal_id=self.portal_id)
         return
     for obj in object_manager.portal_cache_gen():
         self._draw_portal_obj(obj, portal_id=0)
Esempio n. 12
0
 def _on_update(self):
     with Context(self.layer) as layer:
         for ensemble in services.ensemble_service().get_all_ensembles():
             color = pseudo_random_color(ensemble.guid)
             if ensemble.last_center_of_mass is None:
                 continue
             layer.add_circle(ensemble.last_center_of_mass,
                              radius=math.sqrt(
                                  ensemble.max_ensemble_radius),
                              color=color)
             for sim in ensemble:
                 layer.add_circle(sim.position, radius=0.3, color=color)
def _stop_visualizer(_connection, vis_name, container, handle):
    if handle in container:
        visualizer = container[handle]
        visualizer.stop()
        del container[handle]
        with Context(visualizer.layer):
            pass
        sims4.commands.output(
            'Removed visualization: {0}'.format(visualizer.layer), _connection)
        sims4.commands.client_cheat(
            'debugvis.layer.disable {0}'.format(visualizer.layer), _connection)
    return True
 def _visualize_contours(self, layer, contours, color, make_closed=True):
     with Context(layer, routing_surface=self._routing_surface) as context:
         for contour in contours:
             length = len(contour)
             while length != 0:
                 for i in range(length - 1):
                     context.add_segment(contour[i],
                                         contour[i + 1],
                                         color=color)
                 if make_closed:
                     context.add_segment(contour[length - 1],
                                         contour[0],
                                         color=color)
Esempio n. 15
0
def debugvis_draw_circle(x: float = 0.0,
                         y: float = 0.0,
                         z: float = 0.0,
                         rad: float = 0.1,
                         snap_to_terrain: bool = False,
                         _connection=None):
    debugvis_draw_start(_connection)
    pos = sims4.math.Vector3(x, y, z)
    altitude = KEEP_ALTITUDE
    if snap_to_terrain == True:
        altitude = None
    with Context(_draw_viz_layer, preserve=True) as layer:
        layer.add_circle(pos, radius=rad, altitude=altitude)
Esempio n. 16
0
def debugvis_draw_text(x: float = 0.0,
                       y: float = 0.0,
                       z: float = 0.0,
                       text='test',
                       snap_to_terrain: bool = False,
                       _connection=None):
    debugvis_draw_start(_connection)
    pos = sims4.math.Vector3(x, y, z)
    altitude = KEEP_ALTITUDE
    if snap_to_terrain == True:
        altitude = None
    with Context(_draw_viz_layer, preserve=True) as layer:
        layer.add_text_world(pos, text, altitude=altitude)
Esempio n. 17
0
 def _draw_portal_obj(self, portal_obj, *args, portal_id=0, **kwargs):
     with Context(self.layer, preserve=True) as layer:
         for portal_instance in portal_obj.get_portal_instances():
             if portal_id and not portal_id == portal_instance.there and not portal_id == portal_instance.back:
                 continue
             if portal_instance.there is not None:
                 self._draw_portal_pair(portal_instance,
                                        portal_instance.there, layer,
                                        Color.CYAN, Color.MAGENTA, 6.0, 6)
             if portal_instance.back is not None:
                 self._draw_portal_pair(portal_instance,
                                        portal_instance.back, layer,
                                        Color.GREEN, Color.ORANGE, 4.0, 6)
 def redraw(self, sim, constraint):
     routing_surface = None if isinstance(
         constraint, _ConstraintSet) else constraint.routing_surface
     color = pseudo_random_color(sim.id)
     (r, g, b, a) = sims4.color.to_rgba(color)
     (gr, gg, gb, ga) = sims4.color.to_rgba(Color.GREY)
     semitransparent = sims4.color.from_rgba(
         (gr + r) / 2, (gg + g) / 2, (gb + b) / 2, (ga + a) / 2 * 0.4)
     transparent = sims4.color.from_rgba((gr + r) / 2, (gg + g) / 2,
                                         (gb + b) / 2, (ga + a) / 2 * 0.15)
     if isinstance(constraint, _ConstraintSet):
         for sub_constraint in constraint:
             if sub_constraint.routing_surface is not None:
                 routing_surface = sub_constraint.routing_surface
                 break
     else:
         routing_surface = constraint.routing_surface
     with Context(self.layer, routing_surface=routing_surface) as layer:
         direction_constraint = None
         direction_constraints = []
         for sub_constraint in constraint:
             if sub_constraint._geometry is not None:
                 if sub_constraint._geometry.polygon is None:
                     if sub_constraint._geometry.restrictions is not None:
                         direction_constraints.append(sub_constraint)
         if direction_constraints:
             direction_constraint = create_constraint_set(
                 direction_constraints)
         for si in sim.si_state:
             participant_type = si.get_participant_type(sim)
             for si_constraint in si.constraint_intersection(
                     participant_type=participant_type):
                 if direction_constraint is not None:
                     si_constraint = direction_constraint.intersect(
                         si_constraint)
                 si_color = transparent
                 si_altitude = 0.01
                 if si.is_guaranteed():
                     si_color = semitransparent
                     si_altitude = 0.02
                 _draw_constraint(layer,
                                  si_constraint,
                                  si_color,
                                  altitude_modifier=si_altitude)
         _draw_constraint(layer,
                          constraint,
                          color,
                          altitude_modifier=0.03,
                          anywhere_position=sim.position,
                          draw_contours=True)
def debugvis_draw_arrow(x: float = 0.0,
                        y: float = 0.0,
                        z: float = 0.0,
                        angle: float = 0.0,
                        length: float = 0.5,
                        snap_to_terrain: bool = False,
                        _connection=None):
    debugvis_draw_start(_connection)
    pos = sims4.math.Vector3(x, y, z)
    altitude = KEEP_ALTITUDE
    if snap_to_terrain == True:
        altitude = None
    with Context(_draw_viz_layer, preserve=True) as layer:
        layer.add_arrow(pos, angle, length, altitude=altitude)
 def _process(self, _):
     sim = self.sim
     if sim is None:
         self.stop()
         return
     offset = sims4.math.Vector3.Y_AXIS()*0.4
     BONE_INDEX = 5
     if sim.to_skip_autonomy():
         autonomy_timer_text = 'Skipping'
     elif sim.get_autonomy_state_setting() < autonomy.settings.AutonomyState.FULL:
         autonomy_timer_text = 'Disabled'
     else:
         autonomy_timer_text = str(sim.get_time_until_next_update())
     with Context(self._layer) as context:
         context.add_text_object(self.sim, offset, autonomy_timer_text, bone_index=BONE_INDEX)
 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)
Esempio n. 22
0
 def _draw_path(self):
     with Context(self.layer) as context:
         context.layer.clear()
         if self.route is None:
             return
         verticies_left = []
         verticies_right = []
         for index in range(len(self.route) - 1, 0, -1):
             cur_node = self.route[index]
             prev_node = self.route[index - 1]
             cur_pos = sims4.math.Vector3(cur_node.position[0], cur_node.position[1], cur_node.position[2])
             prev_pos = sims4.math.Vector3(prev_node.position[0], prev_node.position[1], prev_node.position[2])
             context.add_segment(prev_pos, cur_pos, color=Color.CYAN)
             portal = services.object_manager().get(cur_node.portal_object_id)
             if portal is not None:
                 for portal_instance in portal.get_portal_instances():
                     if portal_instance.there is not None:
                         self._draw_portal_pair(portal_instance, portal_instance.there, context, Color.CYAN, Color.MAGENTA, self.PORTAL_THERE_HEIGHT, self.PORTAL_ARCH_DETAIL)
                     if portal_instance.back is not None:
                         self._draw_portal_pair(portal_instance, portal_instance.back, context, Color.GREEN, Color.ORANGE, self.PORTAL_BACK_HEIGHT, self.PORTAL_ARCH_DETAIL)
             vector = cur_pos - prev_pos
             vector = sims4.math.vector_cross(sims4.math.Vector3.Y_AXIS(), vector)
             if vector.magnitude() != 0:
                 vector = sims4.math.vector_normalize(vector)
             tunnel_p1 = cur_pos + vector*self.TUNNEL_OFFSET
             tunnel_p2 = prev_pos + vector*self.TUNNEL_OFFSET
             tunnel_p3 = cur_pos + vector*-self.TUNNEL_OFFSET
             tunnel_p4 = prev_pos + vector*-self.TUNNEL_OFFSET
             verticies_left.append(tunnel_p1)
             verticies_right.append(tunnel_p3)
             if index == 1:
                 context.add_circle(prev_pos, radius=0.15, color=Color.GREEN)
                 context.add_circle(prev_pos, radius=0.18, color=Color.GREEN)
                 verticies_left.append(tunnel_p2)
                 verticies_left.append(prev_pos)
                 verticies_left.append(tunnel_p4)
             if index == len(self.route) - 1:
                 context.add_circle(cur_pos, radius=self.ENDPOINT_INNER_CIRCLE_RADIUS, color=Color.RED)
                 context.add_circle(cur_pos, radius=self.ENDPOINT_OUTER_CIRCLE_RADIUS, color=Color.RED)
                 verticies_right.append(tunnel_p1)
                 verticies_right.append(cur_pos)
                 verticies_right.append(tunnel_p3)
             else:
                 context.add_circle(cur_pos, radius=self.NODE_RADIUS, color=Color.CYAN)
         verticies_right.reverse()
         verticies_left.extend(verticies_right)
         context.add_polygon(verticies_left, color=Color.GREEN)
 def redraw(self, sim):
     with Context(self.layer, altitude=0.1) as layer:
         for group in sim.get_groups_for_sim_gen():
             if group is not None:
                 if self.sim in group:
                     if group.geometry:
                         for sim in group:
                             layer.routing_surface = sim.routing_surface
                             geometry = group.geometry.get(sim, None)
                             if geometry is not None:
                                 color = pseudo_random_color(sim.id)
                                 layer.add_polygon(geometry.field,
                                                   color=color)
                                 layer.add_point(geometry.focus,
                                                 color=color)
                                 layer.add_arrow_for_transform(
                                     sim.transform,
                                     color=color,
                                     altitude=0.05)
                         layer.routing_surface = group.routing_surface
                         color = pseudo_random_color(id(group))
                         layer.add_polygon(group.geometry.field,
                                           color=color,
                                           altitude=0.125)
                         layer.add_point(group.geometry.focus,
                                         color=color,
                                         size=0.2)
                         if group.radius is not None:
                             layer.add_circle(group.geometry.focus,
                                              group.radius,
                                              color=color)
                     if group._focus is not None:
                         layer.add_point(group._focus.position,
                                         color=sims4.color.Color.CYAN)
                     if isinstance(
                             group,
                             JigGroup) and group.jig_polygon is not None:
                         color = pseudo_random_color(id(group))
                         layer.add_polygon(group.jig_polygon,
                                           color=color,
                                           altitude=0.125)
                     for (index, sim) in enumerate(group):
                         for i in range(index):
                             layer.add_point(sim.position,
                                             altitude=2 + i * 0.15,
                                             size=0.025,
                                             color=Color.RED)
 def redraw(self, sim):
     with Context(self.layer, altitude=0.1, routing_surface=sim.routing_surface) as layer:
         position_color = pseudo_random_color(sim.id)
         position = sim.position
         orientation = sim.orientation
         layer.add_circle(position, routing.get_default_agent_radius(), color=position_color)
         if orientation != sims4.math.Quaternion.ZERO():
             angle = sims4.math.yaw_quaternion_to_angle(orientation)
             layer.add_arrow(position, angle, color=position_color)
         while sim.intended_location is not None:
             intended_position_color = pseudo_random_color(sim.id + 1)
             intended_position = sim.intended_location.position
             intended_orientation = sim.intended_location.orientation
             layer.add_circle(intended_position, routing.get_default_agent_radius(), color=intended_position_color)
             while intended_orientation != sims4.math.Quaternion.ZERO():
                 angle = sims4.math.yaw_quaternion_to_angle(intended_orientation)
                 layer.add_arrow(intended_position, angle, color=intended_position_color)
 def _on_spawn_points_changed(self):
     zone = services.current_zone()
     with Context(self.layer) as layer:
         for spawn_point in zone.spawn_points_gen():
             point_color = SpawnPointVisualizer.SPAWN_POINT_COLORS.get(spawn_point.obj_def_guid, Color.WHITE)
             footprint_polygon = spawn_point.get_footprint_polygon()
             if footprint_polygon is not None:
                 layer.add_polygon(footprint_polygon, color=point_color, altitude=0.1)
             for (slot_index, slot_position) in enumerate(spawn_point.get_slot_positions()):
                 if not spawn_point.valid_slots & 1 << slot_index:
                     layer.set_color(Color.RED)
                 else:
                     layer.set_color(point_color)
                 layer.add_point(slot_position, altitude=0.1)
         layer.set_color(Color.CYAN)
         for corner in services.current_zone().lot.corners:
             layer.add_point(corner, size=1.0)
Esempio n. 26
0
def debugvis_draw_line(x1: float = 0.0,
                       y1: float = 0.0,
                       z1: float = 0.0,
                       x2: float = 0.0,
                       y2: float = 0.0,
                       z2: float = 0.0,
                       snap_to_terrain: bool = False,
                       color: int = None,
                       _connection=None):
    debugvis_draw_start(_connection)
    start = sims4.math.Vector3(x1, y1, z1)
    dest = sims4.math.Vector3(x2, y2, z2)
    altitude = KEEP_ALTITUDE
    if snap_to_terrain == True:
        altitude = None
    with Context(_draw_viz_layer, preserve=True) as layer:
        layer.add_segment(start, dest, altitude=altitude, color=color)
 def _on_transition_destinations_changed(self,
                                         sim,
                                         transition_destinations,
                                         possible_sources,
                                         max_weight,
                                         preserve=False):
     POSSIBLE_SOURCE = from_rgba(50, 50, 50, 0.5)
     with Context(self.layer, preserve=preserve) as layer:
         for (path_id, constraint, weight) in transition_destinations:
             alpha = 1.0
             if max_weight > 0:
                 alpha = weight / max_weight
             color = pseudo_random_color(path_id, a=alpha)
             _draw_constraint(layer, constraint, color)
         for constraint in possible_sources:
             _draw_constraint(layer,
                              constraint,
                              POSSIBLE_SOURCE,
                              altitude_modifier=0.5)
Esempio n. 28
0
def debugvis_social_clustering(detailed_obj_id: int = None, _connection=None):
    with Context('social_clustering') as layer:
        for cluster in services.social_group_cluster_service(
        ).get_clusters_gen(regenerate=True):
            layer.routing_surface = cluster.routing_surface
            for obj in cluster.objects_gen():
                layer.set_color(Color.CYAN)
                layer.add_segment(obj.position, cluster.position)
                if obj.id == detailed_obj_id:
                    layer.set_color(Color.WHITE)
                    layer.add_polygon(cluster.polygon)
                    detailed_obj_id = None
                layer.set_color(Color.YELLOW)
                layer.add_circle(obj.position, 0.65)
            layer.set_color(Color.CYAN)
            layer.add_circle(cluster.position, 0.35)
            _draw_constraint(layer, cluster.constraint, Color.GREEN)
    sims4.commands.client_cheat('debugvis.layer.enable social_clustering',
                                _connection)
    return True
Esempio n. 29
0
 def _draw_spawner_constraints(self):
     with Context(self.layer) as layer:
         for obj in services.object_manager(
         ).get_all_objects_with_component_gen(SPAWNER_COMPONENT):
             position = obj.position
             spawner_component = obj.get_component(SPAWNER_COMPONENT)
             radii = []
             slot_positions = []
             for data in spawner_component._spawner_data:
                 if data.spawner_option.spawn_type == SpawnerTuning.GROUND_SPAWNER and data.spawner_option.radius not in radii:
                     radii.append(data.spawner_option.radius)
                 if data.spawner_option.spawn_type == SpawnerTuning.SLOT_SPAWNER:
                     slot_types = {data.spawner_option.slot_type}
                     for slot in obj.get_runtime_slots_gen(
                             slot_types=slot_types):
                         slot_positions.append(slot.position)
             spawner_color = pseudo_random_color(obj.id)
             for radius in radii:
                 layer.add_circle(position, radius, color=spawner_color)
             for slot in slot_positions:
                 layer.add_point(slot,
                                 color=spawner_color,
                                 altitude=KEEP_ALTITUDE)
Esempio n. 30
0
def debugvis_test(name, _connection=None):
    client = services.client_manager().get(_connection)
    sim = client.active_sim
    time = services.time_service().sim_now
    hour = time.hour() % 12 * sims4.math.TWO_PI / 12
    minute = time.minute() * sims4.math.TWO_PI / 60
    a = sim.position + sims4.math.Vector3(0, 1, 0)
    b = a + sims4.math.Vector3(math.cos(hour), 0, math.sin(hour)) * 3
    c = a + sims4.math.Vector3(math.cos(minute), 0, math.sin(minute)) * 4
    with Context(name, routing_surface=sim.routing_surface) as layer:
        layer.set_color(Color.YELLOW)
        layer.add_segment(a, b, color=Color.CYAN)
        layer.add_segment(a, c, color=Color.RED)
        layer.add_point(a, size=0.2)
        layer.add_point(b, size=0.1, color=Color.BLUE)
        layer.add_point(c, size=0.1, color=Color.MAGENTA)
        layer.add_circle(a, 5, color=Color.GREEN)
        for i in range(12):
            theta = i * sims4.math.TWO_PI / 12
            x = sims4.math.Vector3(4.75 * math.cos(theta), 0,
                                   4.75 * math.sin(theta))
            color = sims4.color.interpolate(Color.YELLOW, Color.BLUE, i / 11)
            layer.add_arrow(a + x,
                            0.5 * sims4.math.PI - theta,
                            end_arrow=False,
                            color=color)
            layer.add_text_world(a + x,
                                 str(i),
                                 color_foreground=pseudo_random_color(i))
        layer.add_text_screen(sims4.math.Vector2(4, 32),
                              'Displaying debug visualization tests.')
        for i in range(200):
            layer.add_text_object(sim,
                                  sims4.math.Vector3.ZERO(),
                                  str(i),
                                  bone_index=i)
    return 1