ААА тыт
- User
ААА тыт
- Assistant
Привет! Как я могу помочь тебе сегодня?
- User
Вот оригинальный код аддона для блендер 3.3.0:
bl_info = { "name": "F1 Track Transfer Shape Layout", "author": "AlonsoBeast", "version": (1, 0), "blender": (3, 3, 0), "category": "Object", "location": "3D View > Sidebar > F1 Track Builder Toolkit", "description": "Transfer shape from source to target curves", }
import bpy
def get_curve_names(self, context): """Get names of all curves in the scene""" return [(obj.name, obj.name, '') for obj in bpy.data.objects if obj.type == 'CURVE']
class TransferShapeOperator(bpy.types.Operator): """Transfer shape from source to target curve""" bl_idname = "object.transfer_shape_operator" bl_label = "F1 Track Transfer Shape"
source_curve: bpy.props.StringProperty() target_curve: bpy.props.StringProperty() def execute(self, context): source_curve = bpy.data.objects.get(self.source_curve) target_curve = bpy.data.objects.get(self.target_curve) if not source_curve or not target_curve: self.report({'ERROR'}, "Invalid curve selection.") print("Error: Invalid curve selection.") return {'CANCELLED'} if source_curve == target_curve: self.report({'ERROR'}, "Source and target curves are the same.") print("Error: You have selected the same source and target curves.") return {'CANCELLED'} source_spline = source_curve.data.splines.active target_spline = target_curve.data.splines.active if not source_spline or not target_spline: self.report({'ERROR'}, "No active spline found in either source or target curve.") print("Error: No active spline in source or target curve.") return {'CANCELLED'} num_source_points = len(source_spline.bezier_points) def interpolate_bezier_points(spline, t): num_points = len(spline.bezier_points) if num_points < 2: return None total_length = sum((p.co - spline.bezier_points[i - 1].co).length for i, p in enumerate(spline.bezier_points) if i > 0) target_distance = t * total_length cumulative_length = 0 new_position = None for i in range(1, num_points): p1 = spline.bezier_points[i - 1].co p2 = spline.bezier_points[i].co segment_length = (p1 - p2).length if cumulative_length + segment_length >= target_distance: segment_ratio = (target_distance - cumulative_length) / segment_length new_position = p1.lerp(p2, segment_ratio) break cumulative_length += segment_length return new_position for i, point in enumerate(source_spline.bezier_points): target_position_ratio = i / (num_source_points - 1) new_position = interpolate_bezier_points(target_spline, target_position_ratio) if new_position: point.co = new_position bpy.context.view_layer.update() print("Transfer successful.") self.report({'INFO'}, "Transfer successful.") return {'FINISHED'}class TransferShapePanel(bpy.types.Panel): bl_label = "F1 Track Transfer Shape Layout" bl_idname = "VIEW3D_PT_transfer_shape_layout" bl_space_type = "VIEW_3D" bl_region_type = "UI" bl_category = "F1 Track"
def draw(self, context): layout = self.layout col = layout.column() col.label(text="Source Shape") col.prop(context.scene, "source_track_curve", text="Track Line") col.prop(context.scene, "source_trial_curve", text="Trial Line") col.prop(context.scene, "source_pit_curve", text="Pit Line") col.separator() col.label(text="Target Shape") col.prop(context.scene, "target_track_curve", text="Track Line") col.prop(context.scene, "target_trial_curve", text="Trial Line") col.prop(context.scene, "target_pit_curve", text="Pit Line") transfer_operator = col.operator("object.transfer_shape_operator", text="Transfer Track") transfer_operator.source_curve = context.scene.source_track_curve transfer_operator.target_curve = context.scene.target_track_curve transfer_operator = col.operator("object.transfer_shape_operator", text="Transfer Trial") transfer_operator.source_curve = context.scene.source_trial_curve transfer_operator.target_curve = context.scene.target_trial_curve transfer_operator = col.operator("object.transfer_shape_operator", text="Transfer Pit") transfer_operator.source_curve = context.scene.source_pit_curve transfer_operator.target_curve = context.scene.target_pit_curvedef register(): bpy.utils.register_class(TransferShapeOperator) bpy.utils.register_class(TransferShapePanel)
bpy.types.Scene.source_track_curve = bpy.props.EnumProperty(items=get_curve_names, name="Source Track") bpy.types.Scene.source_trial_curve = bpy.props.EnumProperty(items=get_curve_names, name="Source Trial") bpy.types.Scene.source_pit_curve = bpy.props.EnumProperty(items=get_curve_names, name="Source Pit") bpy.types.Scene.target_track_curve = bpy.props.EnumProperty(items=get_curve_names, name="Target Track") bpy.types.Scene.target_trial_curve = bpy.props.EnumProperty(items=get_curve_names, name="Target Trial") bpy.types.Scene.target_pit_curve = bpy.props.EnumProperty(items=get_curve_names, name="Target Pit")def unregister(): bpy.utils.unregister_class(TransferShapeOperator) bpy.utils.unregister_class(TransferShapePanel)
del bpy.types.Scene.source_track_curve del bpy.types.Scene.source_trial_curve del bpy.types.Scene.source_pit_curve del bpy.types.Scene.target_track_curve del bpy.types.Scene.target_trial_curve del bpy.types.Scene.target_pit_curveif name == "main": register()
- Assistant
Этот код представляет собой аддон для Blender, который позволяет переносить форму из одной кривой в другую. Если вам нужны конкретные изменения или хотите добавить функциональность, дайте знать! А пока вот краткий обзор его работы:
Основные функции аддона:
-
Описание: Аддон имеет пользовательский интерфейс в боковой панели 3D-вида, где можно выбрать исходные и целевые кривые (Track, Trial, Pit).
-
Перенос формы: Периодически выбираются точки из исходной кривой и вычисляются их положения на целевой кривой с использованием интерполяции.
-
Регистрация: Аддон регистрирует свои классы и свойства в Blender, чтобы пользователь мог взаимодействовать с интерфейсом.
Как использовать:
- Убедитесь, что у вас есть кривая, из которой вы хотите перенести форму, и кривая, в которую вы хотите её перенести.
- Выберите нужные кривые в интерфейсе аддона.
- Нажмите соответствующий оператор для переноски формы.
Как установить:
- Скопируйте данный код в текстовый файл.
- Сохраните файл с расширением
.py, напримерf1_track_transfer.py. - В Blender перейдите в
Edit > Preferences > Add-ons > Install...и выберите ваш файл. - Активируйте аддон в списке.
Если у вас есть другие вопросы или вам нужно внести изменения в код, дайте знать!
-