def draw_transform(transform_str, _connection=None): transform_str = transform_str.replace(VECTOR3_STR, '') float_list = extract_floats(transform_str) color = pseudo_random_color(id(float_list)) num_floats = len(float_list) if num_floats == 7: transform_quaternion = sims4.math.Quaternion(float_list[3], float_list[4], float_list[5], float_list[6]) angle = sims4.math.yaw_quaternion_to_angle(transform_quaternion) debugvis_draw_arrow(float_list[0], float_list[1], float_list[2], angle=angle, snap_to_terrain=True, color=color, _connection=_connection) debugvis_draw_point(float_list[0], float_list[1], float_list[2], snap_to_terrain=True, color=color, _connection=_connection) else: logger.warn( "Transform string doesn't have vector3 and orientation: {}", transform_str)
def draw_vector3(vector3_str, _connection): point_list = extract_floats(vector3_str) color = pseudo_random_color(id(point_list)) num_floats = len(point_list) if num_floats == 3: debugvis_draw_point(point_list[0], point_list[1], point_list[2], True, color, _connection) else: logger.warn("Vector3 string doesn't have 3 points: {}", vector3_str)
def routing_debug_generate_routing_goals_from_geometry( *args, obj: OptionalTargetParam = None, _connection=None): output = sims4.commands.Output(_connection) obj = get_optional_target(obj, _connection=_connection) if obj is None: return False routing_component = obj.get_component(ROUTING_COMPONENT) if routing_component is None: return False total_string = ''.join(args) polygon_strs = find_substring_in_repr(total_string, POLYGON_STR, POLYGON_END_PARAM) if not polygon_strs: output('No valid polygons. must start with {} and end with {}'.format( POLYGON_STR, POLYGON_END_PARAM)) return constraints = [] routing_surface = routing.SurfaceIdentifier( services.current_zone_id(), 0, routing.SurfaceType.SURFACETYPE_OBJECT) for poly_str in polygon_strs: point_list = extract_floats(poly_str) if not point_list or len(point_list) % 2 != 0: output('Point list is not valid length. Too few or one too many.') return vertices = [] for index in range(0, len(point_list), 2): vertices.append( sims4.math.Vector3(point_list[index], 0.0, point_list[index + 1])) polygon = sims4.geometry.Polygon(vertices) geometry = RestrictedPolygon(polygon, []) constraints.append( Constraint(geometry=geometry, routing_surface=routing_surface)) constraint_set = create_constraint_set(constraints) if not postures.posture_graph.enable_debug_goals_visualization: sims4.commands.execute('debugvis.goals.enable', _connection) handles = constraint_set.get_connectivity_handles(obj) handles_str = 'Handles: {}'.format(len(handles)) sims4.commands.output(handles_str, _connection) all_goals = [] for handle in handles: goal_list = handle.get_goals() goals_str = '\tGoals: {}'.format(len(goal_list)) sims4.commands.output(goals_str, _connection) all_goals.extend(goal_list) if postures.posture_graph.enable_debug_goals_visualization: for constraint in constraints: with debugvis.Context( 'goal_scoring', routing_surface=constraint.routing_surface) as layer: for polygon in constraint.geometry.polygon: layer.add_polygon( polygon, routing_surface=constraint.routing_surface) for goal in all_goals: position = goal.location.transform.translation layer.add_point(position, routing_surface=constraint.routing_surface)
def polygon_intersection(*args, _connection=None): output = sims4.commands.Output(_connection) total_string = ''.join(args) polygon_strs = find_substring_in_repr(total_string, POLYGON_STR, POLYGON_END_PARAM) if not polygon_strs: output('No valid polygons. must start with {} and end with {}'.format( POLYGON_STR, POLYGON_END_PARAM)) return constraints = [] for poly_str in polygon_strs: point_list = extract_floats(poly_str) if not point_list or len(point_list) % 2 != 0: output('Point list is not valid length. Too few or one too many.') return vertices = [] for index in range(0, len(point_list), 2): vertices.append( sims4.math.Vector3(point_list[index], 0.0, point_list[index + 1])) polygon = sims4.geometry.Polygon(vertices) geometry = sims4.geometry.RestrictedPolygon(polygon, []) constraint = Constraint(geometry=geometry, routing_surface=routing.SurfaceIdentifier( services.current_zone_id(), 0, routing.SurfaceType.SURFACETYPE_WORLD)) constraints.append(constraint) intersection = ANYWHERE for constraint in constraints: new_intersection = intersection.intersect(constraint) if not new_intersection.valid: output( 'Constraint intersection failed. Drawing incompatible geometry. {}' .format(new_intersection)) if intersection.geometry is not None: draw_geometry_in_string(str(intersection.geometry), _connection=_connection) draw_geometry_in_string(str(constraint.geometry), _connection=_connection) return intersection = new_intersection if intersection.valid: draw_geometry_in_string(str(intersection.geometry), _connection=_connection) output('Intersection valid. Drawing Polygon.')
def draw_polygon_str(polygon_str, _connection): point_list = extract_floats(polygon_str) draw_polygon(point_list, _connection)