def _fill_node_sections(data_list, offset_matrix): """Fills up "Node" sections.""" sections = [] for item in data_list: section = _SectionData("Node") section.props.append(("Index", int(item.scs_props.locator_prefab_con_node_index))) loc = _convert_utils.convert_location_to_scs(item.location, offset_matrix) section.props.append(("Position", ["&&", loc])) direction = _convert_utils.scs_to_blend_matrix().inverted() * (item.matrix_world.to_quaternion() * Vector((0, 1, 0))) section.props.append(("Direction", ["&&", direction])) # print('p_locator_lanes: %s' % item.scs_props.p_locator_lanes) # lane_input_values = [] # lane_output_values = [] # for lane_num in range(item.scs_props.p_locator_lanes): # if lane_num: # lane_input_values.append(lane_num) # lane_output_values.append(lane_num) # else: # lane_input_values.append(-1) # lane_output_values.append(-1) section.props.append(("InputLanes", ["ii", (-1, -1, -1, -1, -1, -1, -1, -1)])) # section.props.append(("InputLanes", lane_input_values)) section.props.append(("OutputLanes", ["ii", (-1, -1, -1, -1, -1, -1, -1, -1)])) # section.props.append(("OutputLanes", lane_output_values)) section.props.append(("TerrainPointCount", 0)) section.props.append(("StreamCount", 0)) section.props.append(("", "")) # section.props.append(("__EMPTY_LINE__", 0)) sections.append(section) return sections
def _get_custom_channels(action): custom_channels = [] frame_start = action.frame_range[0] frame_end = action.frame_range[1] total_time = action.scs_props.action_length anim_export_step = action.scs_props.anim_export_step total_frames = (frame_end - frame_start) / anim_export_step for group in action.groups: if group.name == 'Location': # print(' A -> %s' % str(group)) loc_curves = {} for channel in group.channels: if channel.data_path.endswith("location"): # data_path = channel.data_path array_index = channel.array_index # print(' a -> %s (%i)' % (data_path, array_index)) loc_curves[array_index] = channel # GO THOUGH FRAMES actual_frame = frame_start previous_frame_value = None timings_stream = [] movement_stream = [] while actual_frame <= frame_end: location = Vector() # LOCATION MATRIX if len(loc_curves) > 0: for index in range(3): if index in loc_curves: location[index] = loc_curves[index].evaluate( actual_frame) # COMPUTE SCS FRAME LOCATION frame_loc = _convert_utils.convert_location_to_scs( location) if previous_frame_value is None: previous_frame_value = frame_loc frame_movement = frame_loc - previous_frame_value previous_frame_value = frame_loc lprint('S actual_frame: %s - value: %s', (actual_frame, frame_loc)) timings_stream.append( ("__time__", total_time / total_frames), ) movement_stream.append(frame_movement) actual_frame += anim_export_step anim_timing = ("_TIME", timings_stream) anim_movement = ("_MOVEMENT", movement_stream) bone_anim = (anim_timing, anim_movement) bone_data = ("Prism Movement", bone_anim) custom_channels.append(bone_data) # TODO: Channels can be outside of action groups, but I'm not sure if it practically can occur. # for x in action.fcurves: # if x.data_path == 'location': # print(' B -> %s' % str(x.data_path)) return custom_channels
def _get_custom_channels(action): custom_channels = [] frame_start = action.frame_range[0] frame_end = action.frame_range[1] total_time = action.scs_props.action_length anim_export_step = action.scs_props.anim_export_step total_frames = (frame_end - frame_start) / anim_export_step for group in action.groups: if group.name == 'Location': # print(' A -> %s' % str(group)) loc_curves = {} for channel in group.channels: if channel.data_path.endswith("location"): # data_path = channel.data_path array_index = channel.array_index # print(' a -> %s (%i)' % (data_path, array_index)) loc_curves[array_index] = channel # GO THOUGH FRAMES actual_frame = frame_start previous_frame_value = None timings_stream = [] movement_stream = [] while actual_frame <= frame_end: location = Vector() # LOCATION MATRIX if len(loc_curves) > 0: for index in range(3): if index in loc_curves: location[index] = loc_curves[index].evaluate(actual_frame) # COMPUTE SCS FRAME LOCATION frame_loc = _convert_utils.convert_location_to_scs(location) if previous_frame_value is None: previous_frame_value = frame_loc frame_movement = frame_loc - previous_frame_value previous_frame_value = frame_loc lprint('S actual_frame: %s - value: %s', (actual_frame, frame_loc)) timings_stream.append(("__time__", total_time / total_frames), ) movement_stream.append(frame_movement) actual_frame += anim_export_step anim_timing = ("_TIME", timings_stream) anim_movement = ("_MOVEMENT", movement_stream) bone_anim = (anim_timing, anim_movement) bone_data = ("Prism Movement", bone_anim) custom_channels.append(bone_data) # TODO: Channels can be outside of action groups, but I'm not sure if it practically can occur. # for x in action.fcurves: # if x.data_path == 'location': # print(' B -> %s' % str(x.data_path)) return custom_channels
def _get_custom_channels(scs_animation, action): custom_channels = [] frame_start = scs_animation.anim_start frame_end = scs_animation.anim_end anim_export_step = action.scs_props.anim_export_step total_frames = (frame_end - frame_start) / anim_export_step loc_curves = {} # dictionary for storing "location" curves of action # get curves which are related to moving of armature object for fcurve in action.fcurves: if fcurve.data_path == 'location': loc_curves[fcurve.array_index] = fcurve # write custom channel only if location curves were found if len(loc_curves) > 0: # GO THOUGH FRAMES actual_frame = frame_start previous_frame_value = None timings_stream = [] movement_stream = [] while actual_frame <= frame_end: location = Vector() # LOCATION MATRIX if len(loc_curves) > 0: for index in range(3): if index in loc_curves: location[index] = loc_curves[index].evaluate( actual_frame) # COMPUTE SCS FRAME LOCATION frame_loc = _convert_utils.convert_location_to_scs(location) if previous_frame_value is None: previous_frame_value = frame_loc frame_movement = frame_loc - previous_frame_value previous_frame_value = frame_loc lprint('S actual_frame: %s - value: %s', (actual_frame, frame_loc)) timings_stream.append( ("__time__", scs_animation.length / total_frames), ) movement_stream.append(frame_movement) actual_frame += anim_export_step anim_timing = ("_TIME", timings_stream) anim_movement = ("_MOVEMENT", movement_stream) bone_anim = (anim_timing, anim_movement) bone_data = ("Prism Movement", bone_anim) custom_channels.append(bone_data) return custom_channels
def _get_custom_channels(scs_animation, action): custom_channels = [] frame_start = scs_animation.anim_start frame_end = scs_animation.anim_end anim_export_step = action.scs_props.anim_export_step total_frames = (frame_end - frame_start) / anim_export_step loc_curves = {} # dictionary for storing "location" curves of action # get curves which are related to moving of armature object for fcurve in action.fcurves: if fcurve.data_path == 'location': loc_curves[fcurve.array_index] = fcurve # write custom channel only if location curves were found if len(loc_curves) > 0: # GO THOUGH FRAMES actual_frame = frame_start previous_frame_value = None timings_stream = [] movement_stream = [] while actual_frame <= frame_end: location = Vector() # LOCATION MATRIX if len(loc_curves) > 0: for index in range(3): if index in loc_curves: location[index] = loc_curves[index].evaluate(actual_frame) # COMPUTE SCS FRAME LOCATION frame_loc = _convert_utils.convert_location_to_scs(location) if previous_frame_value is None: previous_frame_value = frame_loc frame_movement = frame_loc - previous_frame_value previous_frame_value = frame_loc lprint('S actual_frame: %s - value: %s', (actual_frame, frame_loc)) timings_stream.append(("__time__", scs_animation.length / total_frames), ) movement_stream.append(frame_movement) actual_frame += anim_export_step anim_timing = ("_TIME", timings_stream) anim_movement = ("_MOVEMENT", movement_stream) bone_anim = (anim_timing, anim_movement) bone_data = ("Prism Movement", bone_anim) custom_channels.append(bone_data) return custom_channels
def _fill_trigger_point_sections(tp_locators, offset_matrix): """Fills up "Trigger Point" sections.""" sections = [] for loc_index, loc_obj in enumerate(tp_locators): section = _SectionData("TriggerPoint") section.props.append(("TriggerID", loc_index)) section.props.append(("TriggerAction", loc_obj.scs_props.locator_prefab_tp_action)) section.props.append(("TriggerRange", loc_obj.scs_props.locator_prefab_tp_range)) section.props.append(("TriggerResetDelay", loc_obj.scs_props.locator_prefab_tp_reset_delay)) section.props.append(("TriggerResetDist", 0.0)) # constant section.props.append(("Flags", 0)) loc = _convert_utils.convert_location_to_scs(loc_obj.location, offset_matrix) section.props.append(("Position", ["&&", loc])) section.props.append(("Neighbours", ["ii", _get_tp_neigbours(tp_locators, loc_obj)])) sections.append(section) return sections
def _fill_map_point_sections(mp_locators, offset_matrix): """Fills up "Map Point" sections.""" sections = [] # print('map_loc_connection_list: %s' % str(map_loc_connection_list)) for loc_obj in mp_locators: section = _SectionData("MapPoint") section.props.append(("MapVisualFlags", _get_mp_visual_flags(loc_obj))) section.props.append(("MapNavFlags", _get_mp_nav_flags(loc_obj))) loc = _convert_utils.convert_location_to_scs(loc_obj.location, offset_matrix) loc.y = 0 # Y location for map points should always be exported as zero section.props.append(("Position", ["&&", loc])) section.props.append(("Neighbours", ["ii", _get_mp_neigbours(mp_locators, loc_obj)])) sections.append(section) return sections
def _fill_map_point_sections(mp_locators, offset_matrix): """Fills up "Map Point" sections.""" sections = [] # print('map_loc_connection_list: %s' % str(map_loc_connection_list)) for loc_obj in mp_locators: section = _SectionData("MapPoint") section.props.append(("MapVisualFlags", _get_mp_visual_flags(loc_obj))) section.props.append(("MapNavFlags", _get_mp_nav_flags(loc_obj))) loc = _convert_utils.convert_location_to_scs(loc_obj.location, offset_matrix) loc.y = 0 # Y location for map points should always be exported as zero section.props.append(("Position", ["&&", loc])) section.props.append( ("Neighbours", ["ii", _get_mp_neigbours(mp_locators, loc_obj)])) sections.append(section) return sections
def _fill_trigger_point_sections(tp_locators, offset_matrix): """Fills up "Trigger Point" sections.""" sections = [] for loc_index, loc_obj in enumerate(tp_locators): section = _SectionData("TriggerPoint") section.props.append(("TriggerID", loc_index)) section.props.append( ("TriggerAction", loc_obj.scs_props.locator_prefab_tp_action)) section.props.append( ("TriggerRange", loc_obj.scs_props.locator_prefab_tp_range)) section.props.append(("TriggerResetDelay", loc_obj.scs_props.locator_prefab_tp_reset_delay)) section.props.append(("TriggerResetDist", 0.0)) # constant section.props.append(("Flags", 0)) loc = _convert_utils.convert_location_to_scs(loc_obj.location, offset_matrix) section.props.append(("Position", ["&&", loc])) section.props.append( ("Neighbours", ["ii", _get_tp_neigbours(tp_locators, loc_obj)])) sections.append(section) return sections
def _fill_node_sections(data_list, offset_matrix): """Fills up "Node" sections.""" sections = [] for item in data_list: section = _SectionData("Node") section.props.append( ("Index", int(item.scs_props.locator_prefab_con_node_index))) loc = _convert_utils.convert_location_to_scs(item.location, offset_matrix) section.props.append(("Position", ["&&", loc])) direction = _convert_utils.scs_to_blend_matrix().inverted() * ( item.matrix_world.to_quaternion() * Vector((0, 1, 0))) section.props.append(("Direction", ["&&", direction])) # print('p_locator_lanes: %s' % item.scs_props.p_locator_lanes) # lane_input_values = [] # lane_output_values = [] # for lane_num in range(item.scs_props.p_locator_lanes): # if lane_num: # lane_input_values.append(lane_num) # lane_output_values.append(lane_num) # else: # lane_input_values.append(-1) # lane_output_values.append(-1) section.props.append( ("InputLanes", ["ii", (-1, -1, -1, -1, -1, -1, -1, -1)])) # section.props.append(("InputLanes", lane_input_values)) section.props.append( ("OutputLanes", ["ii", (-1, -1, -1, -1, -1, -1, -1, -1)])) # section.props.append(("OutputLanes", lane_output_values)) section.props.append(("TerrainPointCount", 0)) section.props.append(("StreamCount", 0)) section.props.append(("", "")) # section.props.append(("__EMPTY_LINE__", 0)) sections.append(section) return sections
def _fill_nav_curve_sections(nav_point_list, offset_matrix): """Fills up (navigation) "Curve" sections.""" _INDEX = "index" _START = "start" _END = "end" _PREV_CURVES = "prev_curves" _NEXT_CURVES = "next_curves" curves_dict = _connections_group_wrapper.get_curves( nav_point_list, _INDEX, _START, _END, _NEXT_CURVES, _PREV_CURVES) # prepare empty sections for curves so it can be later placed directly on right index sections = [_SectionData("Dummy")] * len(curves_dict) for connection_key in curves_dict.keys(): curve = curves_dict[connection_key] start_loc = bpy.data.objects[curve[_START]] end_loc = bpy.data.objects[curve[_END]] section = _SectionData("Curve") section.props.append(("Index", curve[_INDEX])) section.props.append( ("Name", _name_utils.tokenize_name(curve[_START]))) section.props.append(("", "")) section.props.append(("#", "Flags:")) section.props.append(("Flags", _get_np_flags(start_loc, end_loc))) section.props.append(("", "")) section.props.append( ("LeadsToNodes", 0)) # TODO SIMON: make it happen when you know what it means speed_limit = _get_np_speed_limit(start_loc) if speed_limit: section.props.append(("", "")) section.props.append(("SpeedLimit", [ "&", ])) traffic_light = _get_np_traffic_light_id(start_loc) if traffic_light != -1: section.props.append(("", "")) section.props.append(("TrafficLightID", )) section.props.append(("", "")) section.props.append(("NextCurves", [ "ii", _get_np_prev_next_curves(curves_dict, curve[_NEXT_CURVES], _INDEX) ])) section.props.append(("PrevCurves", [ "ii", _get_np_prev_next_curves(curves_dict, curve[_PREV_CURVES], _INDEX) ])) section.props.append(("", "")) section.props.append( ("Length", ["&", (_get_np_length(start_loc, end_loc), )])) section.props.append(("", "")) bezier_section = _SectionData("Bezier") # START NODE start_section = _SectionData("Start") loc = _convert_utils.convert_location_to_scs(start_loc.location, offset_matrix) start_section.props.append(("Position", ["&&", loc])) direction_vector = _convert_utils.scs_to_blend_matrix().inverted() * ( start_loc.matrix_world.to_quaternion() * Vector((0, 1, 0))) start_section.props.append(("Direction", [ "&&", (direction_vector[0], direction_vector[1], direction_vector[2]) ])) # END NODE end_section = _SectionData("End") loc = _convert_utils.convert_location_to_scs(end_loc.location, offset_matrix) end_section.props.append(("Position", ["&&", loc])) direction_vector = _convert_utils.scs_to_blend_matrix().inverted() * ( end_loc.matrix_world.to_quaternion() * Vector((0, 1, 0))) end_section.props.append(("Direction", [ "&&", (direction_vector[0], direction_vector[1], direction_vector[2]) ])) bezier_section.sections.append(start_section) bezier_section.sections.append(end_section) section.sections.append(bezier_section) # make sure that current section is placed on right place sections[curve[_INDEX]] = section return sections
def _fill_nav_curve_sections(nav_point_list, offset_matrix): """Fills up (navigation) "Curve" sections.""" _INDEX = "index" _START = "start" _END = "end" _PREV_CURVES = "prev_curves" _NEXT_CURVES = "next_curves" curves_dict = _connections_group_wrapper.get_curves(nav_point_list, _INDEX, _START, _END, _NEXT_CURVES, _PREV_CURVES) # prepare empty sections for curves so it can be later placed directly on right index sections = [_SectionData("Dummy")] * len(curves_dict) for connection_key in curves_dict.keys(): curve = curves_dict[connection_key] start_loc = bpy.data.objects[curve[_START]] end_loc = bpy.data.objects[curve[_END]] section = _SectionData("Curve") section.props.append(("Index", curve[_INDEX])) section.props.append(("Name", _name_utils.tokenize_name(curve[_START]))) section.props.append(("", "")) section.props.append(("#", "Flags:")) section.props.append(("Flags", _get_np_flags(start_loc, end_loc))) section.props.append(("", "")) section.props.append(("LeadsToNodes", 0)) # TODO SIMON: make it happen when you know what it means speed_limit = _get_np_speed_limit(start_loc) if speed_limit: section.props.append(("", "")) section.props.append(("SpeedLimit", ["&", ])) traffic_light = _get_np_traffic_light_id(start_loc) if traffic_light != -1: section.props.append(("", "")) section.props.append(("TrafficLightID", )) section.props.append(("", "")) section.props.append(("NextCurves", ["ii", _get_np_prev_next_curves(curves_dict, curve[_NEXT_CURVES], _INDEX)])) section.props.append(("PrevCurves", ["ii", _get_np_prev_next_curves(curves_dict, curve[_PREV_CURVES], _INDEX)])) section.props.append(("", "")) section.props.append(("Length", ["&", (_get_np_length(start_loc, end_loc), )])) section.props.append(("", "")) bezier_section = _SectionData("Bezier") # START NODE start_section = _SectionData("Start") loc = _convert_utils.convert_location_to_scs(start_loc.location, offset_matrix) start_section.props.append(("Position", ["&&", loc])) direction_vector = _convert_utils.scs_to_blend_matrix().inverted() * (start_loc.matrix_world.to_quaternion() * Vector((0, 1, 0))) start_section.props.append(("Direction", ["&&", (direction_vector[0], direction_vector[1], direction_vector[2])])) # END NODE end_section = _SectionData("End") loc = _convert_utils.convert_location_to_scs(end_loc.location, offset_matrix) end_section.props.append(("Position", ["&&", loc])) direction_vector = _convert_utils.scs_to_blend_matrix().inverted() * (end_loc.matrix_world.to_quaternion() * Vector((0, 1, 0))) end_section.props.append(("Direction", ["&&", (direction_vector[0], direction_vector[1], direction_vector[2])])) bezier_section.sections.append(start_section) bezier_section.sections.append(end_section) section.sections.append(bezier_section) # make sure that current section is placed on right place sections[curve[_INDEX]] = section return sections