verifique este addon para blender 3d, se precisa corrigir ou e oque falta: blinfo = {…
- User
verifique este addon para blender 3d, se precisa corrigir ou e oque falta: bl_info = { "name": "Rolling Ball Simulation Addon", "blender": (2, 80, 0), "category": "Physics", }
import bpy import math from bpy.props import EnumProperty, FloatProperty, BoolProperty, IntProperty, StringProperty import mathutils
Predefined rail tracks
RAIL_TRACKS = [ ("SPIRAL", "Spiral", "A spiral track"), ("LOOP", "Loop", "A loop track"), ("DROP", "Drop", "A drop track"), ("CORKSCREW", "Corkscrew", "A corkscrew track"), ("BANKED_TURN", "Banked Turn", "A banked turn track"), ("HILL", "Hill", "A hill track"), ("TWIST", "Twist", "A twist track"), ("HELIX", "Helix", "A helix track"), ("SWITCHBACK", "Switchback", "A switchback track"), ("MULTI_LOOP", "Multi-Loop", "A multi-loop track"), ("CUBIC_SPIRAL", "Cubic Spiral", "A cubic spiral track"), ("SINE_WAVE", "Sine Wave", "A sine wave track"), ("PARABOLA", "Parabola", "A parabolic track"), ("ARC", "Arc", "An arc track"), ("HELICAL_TWIST", "Helical Twist", "A helical twist track"), ("SLOPE", "Slope", "A slope track"), ("HELICAL_DROP", "Helical Drop", "A helical drop track"), ("TOWER_OF_TERROR", "Tower of Terror", "A tower of terror track"), ("VERTICAL_LOOP", "Vertical Loop", "A vertical loop track"), ("CIRCLE", "Circle", "A circular track"), ]
def create_spiral(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="SpiralCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SpiralRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_loop(radius=1, height=2): curve_data = bpy.data.curves.new(name="LoopCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("LoopRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_drop(radius=1, height=5): curve_data = bpy.data.curves.new(name="DropCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * math.cos(2 * math.pi * t) y = radius * math.sin(2 * math.pi * t) z = height * (1 - t) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("DropRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_corkscrew(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="CorkscrewCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("CorkscrewRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_banked_turn(radius=1, height=2, angle=45): curve_data = bpy.data.curves.new(name="BankedTurnCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' # Apply banking transformation mat = mathutils.Matrix.Rotation(math.radians(angle), 4, 'Z') for point in points: point.co = mat @ mathutils.Vector(point.co) point.handle_left = mat @ mathutils.Vector(point.handle_left) point.handle_right = mat @ mathutils.Vector(point.handle_right) obj = bpy.data.objects.new("BankedTurnRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_hill(radius=1, height=5): curve_data = bpy.data.curves.new(name="HillCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * (1 - (t - 0.5) ** 2) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("HillRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_twist(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="TwistCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' # Apply twist transformation mat = mathutils.Matrix.Rotation(math.radians(360 * t), 4, 'Z') for point in points: point.co = mat @ mathutils.Vector(point.co) point.handle_left = mat @ mathutils.Vector(point.handle_left) point.handle_right = mat @ mathutils.Vector(point.handle_right) obj = bpy.data.objects.new("TwistRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_helix(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="HelixCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("HelixRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_switchback(radius=1, height=5): curve_data = bpy.data.curves.new(name="SwitchbackCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) if t < 0.5: angle = 2 * math.pi * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) else: angle = 2 * math.pi * (1 - t) z = height * (1 - t) x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SwitchbackRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_multi_loop(radius=1, height=5, loops=3): curve_data = bpy.data.curves.new(name="MultiLoopCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 100 * loops points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("MultiLoopRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_cubic_spiral(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="CubicSpiralCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t ** 3 x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("CubicSpiralRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_sine_wave(radius=1, height=5, waves=2): curve_data = bpy.data.curves.new(name="SineWaveCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * math.sin(2 * math.pi * waves * t) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SineWaveRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_parabola(radius=1, height=5): curve_data = bpy.data.curves.new(name="ParabolaCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * (t - 0.5) ** 2 points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("ParabolaRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_arc(radius=1, height=5): curve_data = bpy.data.curves.new(name="ArcCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * t points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("ArcRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_helical_twist(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="HelicalTwistCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' # Apply twist transformation mat = mathutils.Matrix.Rotation(math.radians(360 * t), 4, 'Z') for point in points: point.co = mat @ mathutils.Vector(point.co) point.handle_left = mat @ mathutils.Vector(point.handle_left) point.handle_right = mat @ mathutils.Vector(point.handle_right) obj = bpy.data.objects.new("HelicalTwistRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_slope(radius=1, height=5): curve_data = bpy.data.curves.new(name="SlopeCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * t points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SlopeRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_helical_drop(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="HelicalDropCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * (1 - t) x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("HelicalDropRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_tower_of_terror(radius=1, height=5): curve_data = bpy.data.curves.new(name="TowerOfTerrorCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t z = height * (1 - t) x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("TowerOfTerrorRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_vertical_loop(radius=1, height=5): curve_data = bpy.data.curves.new(name="VerticalLoopCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("VerticalLoopRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_circle(radius=1): curve_data = bpy.data.curves.new(name="CircleCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = 0 points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("CircleRail", curve_data) bpy.context.collection.objects.link(obj) return objdef add_rail(track_type): if track_type == 'SPIRAL': rail = create_spiral() elif track_type == 'LOOP': rail = create_loop() elif track_type == 'DROP': rail = create_drop() elif track_type == 'CORKSCREW': rail = create_corkscrew() elif track_type == 'BANKED_TURN': rail = create_banked_turn() elif track_type == 'HILL': rail = create_hill() elif track_type == 'TWIST': rail = create_twist() elif track_type == 'HELIX': rail = create_helix() elif track_type == 'SWITCHBACK': rail = create_switchback() elif track_type == 'MULTI_LOOP': rail = create_multi_loop() elif track_type == 'CUBIC_SPIRAL': rail = create_cubic_spiral() elif track_type == 'SINE_WAVE': rail = create_sine_wave() elif track_type == 'PARABOLA': rail = create_parabola() elif track_type == 'ARC': rail = create_arc() elif track_type == 'HELICAL_TWIST': rail = create_helical_twist() elif track_type == 'SLOPE': rail = create_slope() elif track_type == 'HELICAL_DROP': rail = create_helical_drop() elif track_type == 'TOWER_OF_TERROR': rail = create_tower_of_terror() elif track_type == 'VERTICAL_LOOP': rail = create_vertical_loop() elif track_type == 'CIRCLE': rail = create_circle() else: return None
if rail: rail.name = f"Rail_{track_type}_{len([obj for obj in bpy.data.objects if obj.name.startswith(f"Rail_{track_type}_")])}" add_rigid_body_to_object(rail, type='PASSIVE') return raildef add_ball(location): bpy.ops.mesh.primitive_uv_sphere_add(radius=bpy.context.scene.ball_radius, location=location) ball = bpy.context.object ball.name = f"RollingBall_{len([obj for obj in bpy.data.objects if obj.name.startswith("RollingBall_")])}" add_rigid_body_to_object(ball, type='ACTIVE') return ball
def add_rigid_body_to_object(obj, type='PASSIVE'): # Ensure we are in Object Mode if bpy.context.mode != 'OBJECT': bpy.ops.object.mode_set(mode='OBJECT')
# Deselect all objects bpy.ops.object.select_all(action='DESELECT') # Select and make the object active obj.select_set(True) bpy.context.view_layer.objects.active = obj # Add rigid body physics bpy.ops.rigidbody.object_add(type=type) if type == 'PASSIVE': obj.rigid_body.collision_shape = 'MESH' elif type == 'ACTIVE': obj.rigid_body.collision_shape = 'SPHERE' obj.rigid_body.friction = bpy.context.scene.ball_friction obj.rigid_body.restitution = bpy.context.scene.ball_restitution obj.rigid_body.linear_damping = bpy.context.scene.ball_linear_damping obj.rigid_body.angular_damping = bpy.context.scene.ball_angular_damping obj.rigid_body.mass = bpy.context.scene.ball_massdef set_simulation_gravity(gravity): scene = bpy.context.scene if scene.rigidbody_world: scene.rigidbody_world.point_cache.frame_start = 1 scene.rigidbody_world.point_cache.frame_end = 250 scene.rigidbody_world.time_scale = bpy.context.scene.simulation_speed scene.rigidbody_world.settings.effector_weights.all = gravity / -9.81
def start_simulation(): scene = bpy.context.scene set_simulation_gravity(scene.simulation_gravity) bpy.ops.screen.animation_play()
def pause_simulation(): bpy.ops.screen.animation_cancel()
def reset_simulation(): scene = bpy.context.scene pause_simulation() bpy.ops.screen.frame_jump(end=False) for obj in bpy.data.objects: if obj.rigid_body: obj.rigid_body.kinematic = True obj.location = obj.rigid_body.world_center_of_mass obj.rotation_euler = (0, 0, 0) obj.keyframe_insert(data_path="location", frame=1) obj.keyframe_insert(data_path="rotation_euler", frame=1) obj.rigid_body.kinematic = False
class PHYSICS_PT_rolling_ball(bpy.types.Panel): bl_label = "Rolling Ball Simulation" bl_idname = "PHYSICS_PT_rolling_ball" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = 'Physics'
def draw(self, context): layout = self.layout scene = context.scene layout.prop(scene, "selected_track") layout.operator("physics.add_rail", text="Add Rail", icon='MOD_CURVE') layout.operator("physics.add_ball", text="Add Ball", icon='SPHERE') layout.separator() layout.operator("physics.start_simulation", text="Start Simulation", icon='PLAY') layout.operator("physics.pause_simulation", text="Pause Simulation", icon='PAUSE') layout.operator("physics.reset_simulation", text="Reset Simulation", icon='REW') layout.separator() box = layout.box() box.label(text="Simulation Controls", icon='PHYSICS') box.prop(scene, "simulation_gravity", text="Gravity", icon='FORCE_GRAVITY') box.prop(scene, "simulation_speed", text="Speed", icon='TIME') layout.separator() box = layout.box() box.label(text="Ball Parameters", icon='SPHERE') box.prop(scene, "ball_radius", text="Radius", icon='MESH_UVSPHERE') box.prop(scene, "ball_mass", text="Mass", icon='MOD_PHYSICS') box.prop(scene, "ball_friction", text="Friction", icon='MOD_SMOOTH') box.prop(scene, "ball_restitution", text="Restitution", icon='SNAP_INCREMENT') box.prop(scene, "ball_linear_damping", text="Linear Damping", icon='MOD_PHYSICS') box.prop(scene, "ball_angular_damping", text="Angular Damping", icon='MOD_PHYSICS')class PHYSICS_OT_add_rail(bpy.types.Operator): bl_idname = "physics.add_rail" bl_label = "Add Rail" bl_description = "Add a predefined rail track" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): scene = context.scene rail = add_rail(scene.selected_track) if rail: rail.name = f"Rail_{scene.selected_track}_{len([obj for obj in bpy.data.objects if obj.name.startswith(f"Rail_{scene.selected_track}_")])}" add_rigid_body_to_object(rail, type='PASSIVE') return {'FINISHED'}class PHYSICS_OT_add_ball(bpy.types.Operator): bl_idname = "physics.add_ball" bl_label = "Add Ball" bl_description = "Add a ball at the start of the selected rail" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): scene = context.scene rail = bpy.data.objects.get(f"Rail_{scene.selected_track}_1") if rail and rail.data.splines: start_point = rail.matrix_world @ rail.data.splines[0].bezier_points[0].co ball_offset = mathutils.Vector((0, 0, bpy.context.scene.ball_radius * 1.1)) ball_location = start_point + ball_offset ball = add_ball(ball_location) return {'FINISHED'}class PHYSICS_OT_start_simulation(bpy.types.Operator): bl_idname = "physics.start_simulation" bl_label = "Start Simulation" bl_description = "Start the physics simulation" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): start_simulation() return {'FINISHED'}class PHYSICS_OT_pause_simulation(bpy.types.Operator): bl_idname = "physics.pause_simulation" bl_label = "Pause Simulation" bl_description = "Pause the physics simulation" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): pause_simulation() return {'FINISHED'}class PHYSICS_OT_reset_simulation(bpy.types.Operator): bl_idname = "physics.reset_simulation" bl_label = "Reset Simulation" bl_description = "Reset the physics simulation" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): reset_simulation() return {'FINISHED'}def register(): bpy.utils.register_class(PHYSICS_PT_rolling_ball) bpy.utils.register_class(PHYSICS_OT_add_rail) bpy.utils.register_class(PHYSICS_OT_add_ball) bpy.utils.register_class(PHYSICS_OT_start_simulation) bpy.utils.register_class(PHYSICS_OT_pause_simulation) bpy.utils.register_class(PHYSICS_OT_reset_simulation)
bpy.types.Scene.selected_track = EnumProperty( name="Selected Track", description="Choose a rail track", items=RAIL_TRACKS, default='SPIRAL', ) bpy.types.Scene.ball_radius = FloatProperty( name="Ball Radius", description="Radius of the ball", default=0.5, min=0.1, max=1.0, ) bpy.types.Scene.ball_mass = FloatProperty( name="Ball Mass", description="Mass of the ball", default=1.0, min=0.1, max=10.0, ) bpy.types.Scene.ball_friction = FloatProperty( name="Ball Friction", description="Friction of the ball", default=0.5, min=0.0, max=1.0, ) bpy.types.Scene.ball_restitution = FloatProperty( name="Ball Restitution", description="Restitution of the ball", default=0.0, min=0.0, max=1.0, ) bpy.types.Scene.ball_linear_damping = FloatProperty( name="Linear Damping", description="Linear damping of the ball", default=0.1, min=0.0, max=1.0, ) bpy.types.Scene.ball_angular_damping = FloatProperty( name="Angular Damping", description="Angular damping of the ball", default=0.1, min=0.0, max=1.0, ) bpy.types.Scene.simulation_gravity = FloatProperty( name="Simulation Gravity", description="Simulation gravity", default=-9.81, min=-10.0, max=10.0, ) bpy.types.Scene.simulation_speed = FloatProperty( name="Simulation Speed", description="Simulation speed multiplier", default=1.0, min=0.1, max=10.0, )def unregister(): bpy.utils.unregister_class(PHYSICS_PT_rolling_ball) bpy.utils.unregister_class(PHYSICS_OT_add_rail) bpy.utils.unregister_class(PHYSICS_OT_add_ball) bpy.utils.unregister_class(PHYSICS_OT_start_simulation) bpy.utils.unregister_class(PHYSICS_OT_pause_simulation) bpy.utils.unregister_class(PHYSICS_OT_reset_simulation)
del bpy.types.Scene.selected_track del bpy.types.Scene.ball_radius del bpy.types.Scene.ball_mass del bpy.types.Scene.ball_friction del bpy.types.Scene.ball_restitution del bpy.types.Scene.ball_linear_damping del bpy.types.Scene.ball_angular_damping del bpy.types.Scene.simulation_gravity del bpy.types.Scene.simulation_speedif name == "main": register()
- Assistant
Seu addon para Blender 3D está bem estruturado e contém muitas funcionalidades interessantes para simulação de uma bola rolando em trilhos pré-definidos. No entanto, encontrei alguns problemas e pontos que precisam ser revisados ou aprimorados para garantir o funcionamento correto e a estabilidade do addon:
1. Reatribuição de nomes duplicados na função
add_rail()- Você já atribui o nome do objeto rail dentro da função
add_rail(), e também dentro do operadorPHYSICS_OT_add_rail. Isso causa repetição desnecessária e confusão. - Solução: Remova a duplicação e atribua o nome apenas uma vez dentro do operador (ou dentro da função, escolha um lugar).
2. Uso incorreto de aspas em
add_ball()No método
add_ball(location):ball.name = f"RollingBall_{len([obj for obj in bpy.data.objects if obj.name.startswith("RollingBall_")])}"Aqui, você usou aspas duplas dentro de outra string delimitada por aspas duplas, o que causará erro de sintaxe.
- Correção:
Mude para aspas simples dentro do
startswith:ball.name = f"RollingBall_{len([obj for obj in bpy.data.objects if obj.name.startswith('RollingBall_')])}"3. Uso incorreto da variável
tno loop final dos twistsNas funções
create_twistecreate_helical_twist, tem essa parte:mat = mathutils.Matrix.Rotation(math.radians(360 * t), 4, 'Z') for point in points: point.co = mat @ mathutils.Vector(point.co) point.handle_left = mat @ mathutils.Vector(point.handle_left) point.handle_right = mat @ mathutils.Vector(point.handle_right)Aqui você usa
tque foi definido no último loop, ou seja, ele terá o valor mais próximo de 1, o que significa que a mesma rotação é aplicada a todos os pontos - isso não gera um efeito de twist progressivo, o que imagino ser o objetivo.- Solução: Dentro do loop, aplique o cálculo baseado no índice do ponto, por exemplo:
for i, point in enumerate(points): t = i / (len(points) - 1) mat = mathutils.Matrix.Rotation(math.radians(360 * t), 4, 'Z') point.co = mat @ mathutils.Vector(point.co) point.handle_left = mat @ mathutils.Vector(point.handle_left) point.handle_right = mat @ mathutils.Vector(point.handle_right)Mesma correção vale para
create_helical_twist.4. Atualização do atributo
use_cyclic_uAlgumas curvas que são loopings, como "Multi-Loop" ou "Vertical Loop", corretamente tem
use_cyclic_u = True. Para outras curvas éFalse. Isso está ok, só fique atento para que isso esteja de acordo com o comportamento esperado (exemplo: hill, slope não devem fechar o loop).5. Reset da simulação pode travar objetos
No
reset_simulation()você tenta redefinir a posição dos objetos de corpo rígido com base em:obj.location = obj.rigid_body.world_center_of_massIsso pode gerar problemas, além de setar para
rigid_body.kinematic = Truee logo depois paraFalse. Outra coisa importante é que a física nativa do Blender pode não redefinir corretamente os corpos de física assim.-
Sugestão:
- Use
bpy.ops.ptcache.free_bake_all()para limpar os caches da simulação (precisaimport bpy.ops.ptcache). - Reposicione manualmente os objetos na posição inicial (salve essa posição em uma propriedade customizada ao criar, ou guarde a posição inicial do objeto).
- Considere usar
scene.frame_set(1)em vez debpy.ops.screen.frame_jump(end=False), que geralmente funciona melhor.
- Use
Exemplo simplificado de reset:
def reset_simulation(): pause_simulation() bpy.context.scene.frame_set(1) bpy.ops.ptcache.free_bake_all() # Limpa os caches for obj in bpy.data.objects: if obj.rigid_body: # Opcional: reiniciar transformações manualmente ou salvar posições iniciais para referência obj.rigid_body.kinematic = True # Reinicia posição - se tiver uma posição inicial armazenada, use-a aqui # Exemplo: obj.location = obj["initial_location"] obj.rotation_euler = (0, 0, 0) obj.keyframe_insert(data_path="location", frame=1) obj.keyframe_insert(data_path="rotation_euler", frame=1) obj.rigid_body.kinematic = False
6. Na função
set_simulation_gravityuso incorretoEsse trecho:
scene.rigidbody_world.settings.effector_weights.all = gravity / -9.81effector_weights.allé usado para efeito de força de vento, magia, etc., e não para gravidade. A gravidade real da simulação do Blender está em:scene.rigidbody_world.gravity = Vector((0, 0, gravity))- Recomendo melhorar para:
from mathutils import Vector def set_simulation_gravity(gravity): scene = bpy.context.scene if scene.rigidbody_world: scene.rigidbody_world.point_cache.frame_start = 1 scene.rigidbody_world.point_cache.frame_end = 250 scene.rigidbody_world.time_scale = scene.simulation_speed scene.rigidbody_world.gravity = Vector((0, 0, gravity))
7. Adicionar opção para definir parâmetros da pista antes de criar
Atualmente as funções
create_Xusam parâmetros fixos (ex: radius=1, height=5). Para um addon mais funcional, você pode querer permitir que o usuário personalize ao criar a pista.Você pode adicionar propriedades para o painel e/ou operador e passar esses parâmetros para as funções.
8. Modo de seleção e contexto
Você está usando
bpy.opspara adicionar corpos rígidos e objetos, o que depende do contexto correto. Se o usuário estiver em outro modo que não Object Mode, você tenta voltar, o que é bom.Porém, pode ser melhor usar APIs diretas para melhor controle (como
obj.rigid_body), apesar de ser mais verboso. De qualquer forma, seu método funciona, só fique atento ao contexto.
9. Painel UI - Melhorar aparência
Só uma sugestão menor para organizar melhor o painel, como:
- Desativar operadores se parâmetros forem inválidos.
- Feedback ao usuário na criação (popups ou status na barra).
10. Boas práticas - Encapsular criação e não linkar objetos diretamente
Você pode desejar ter uma coleção específica para o addon, ao invés de adicionar tudo diretamente à coleção ativa.
Resumo - Principais correções para aplicar:
- ball.name = f"RollingBall_{len([obj for obj in bpy.data.objects if obj.name.startswith("RollingBall_")])}" + ball.name = f"RollingBall_{len([obj for obj in bpy.data.objects if obj.name.startswith('RollingBall_')])}"- for point in points: - point.co = mat @ mathutils.Vector(point.co) - point.handle_left = mat @ mathutils.Vector(point.handle_left) - point.handle_right = mat @ mathutils.Vector(point.handle_right) + for i, point in enumerate(points): + t = i / (len(points) - 1) + mat = mathutils.Matrix.Rotation(math.radians(360 * t), 4, 'Z') + point.co = mat @ mathutils.Vector(point.co) + point.handle_left = mat @ mathutils.Vector(point.handle_left) + point.handle_right = mat @ mathutils.Vector(point.handle_right)- scene.rigidbody_world.settings.effector_weights.all = gravity / -9.81 + from mathutils import Vector + scene.rigidbody_world.gravity = Vector((0, 0, gravity))
Teste seu addon após fazer as correções acima. Se tiver erros adicionais ou desejar aprimorar a interface, posso ajudar também.
Se quiser, posso ajudar a ajustar as funções para permitir parâmetros dinâmicos definidos no UI, ou adicionar melhorias para melhor controle da simulação!
Fique à vontade para perguntar!
- Você já atribui o nome do objeto rail dentro da função
- User
faça um prompt em ingles para a ai fazer estas correções ou e modificações
- Assistant
Sure! Here's a concise prompt in English you can use to ask an AI to review and fix the issues in your Blender addon code:
Prompt:
I have a Blender addon script that creates various predefined roller coaster rail tracks and simulates a rolling ball with rigid body physics. Please review the entire Python code and make the following corrections and improvements:
- Fix the syntax error caused by incorrect nested quotes when naming the ball object.
- Correct the progressive twist implementation in the
create_twistandcreate_helical_twistfunctions so that the twist is applied gradually along the curve, not as a single rotation. - Replace the incorrect usage of
rigidbody_world.settings.effector_weights.allto set gravity with the proper assignment ofrigidbody_world.gravity. - Improve the resetting of the physics simulation by:
- Clearing rigid body caches properly.
- Resetting object positions and rotations safely, using frame setting and keyframes as needed.
- Remove redundant renaming of rail objects when adding rails.
- Ensure that rigid body properties are added correctly and contexts/modes are handled safely.
- Optionally provide improvement suggestions for better addon structure, like adding UI properties to adjust track parameters before creation.
Make sure the corrected addon runs correctly in Blender 2.80 and above, with no syntax errors or logic bugs, and ensure the physics simulation behaves as expected.
If you want, you can also add the full code and ask the AI to fix directly, e.g.:
"Please fix the following Blender addon code based on the issues listed above: [insert code]"
Let me know if you want me to create a fully fixed version based on those instructions!
- User
como fazer isto no geometric nodes
- Assistant
Você perguntou "como fazer isto no Geometry Nodes" — imagino que você queira criar trilhos (rails) e mover uma bola rolando neles usando Geometry Nodes no Blender, similar ao que seu addon Python faz, porém usando Geometry Nodes, que é o sistema procedural visual do Blender.
Vou explicar de forma geral como criar uma simulação ou efeito semelhante de uma bola rolando em uma pista/trilhado usando Geometry Nodes, porque simular física completa via Geometry Nodes não é possível (ainda não há simulação rígida física nativa em GN). Mas podemos criar animações paramétricas e até simular movimento do objeto ao longo de uma curva.
Passos para recriar o efeito "Rolling Ball on a Rail" via Geometry Nodes - Guia geral
1. Criar a pista (rail) via Geometry Nodes
- Você pode gerar curvas com Geometry Nodes, mas ainda assim muitos tipos de curvas complexas (espiral, loop, etc) são mais facilmente criados manualmente no editor de curvas e usados como base.
- Caso queira fazer curvas complexas via Geometry Nodes, terá que usar nodes como "Curve Primitive Circle", "Curve Line", "Curve Spiral" (custom) ou modifique com "Set Curve Radius", "Set Curve Tilt", etc.
2. Displacement da pista e perfil
- A pista pode ser uma curva com perfil (usando "Curve to Mesh" com um perfil em seção transversal da pista).
- Exemplo: Gere um círculo pequeno para o perfil do rail, e use o curve da trajetória para gerar o mesh da pista.
3. Criar a esfera (bola) no Geometry Nodes
- Pode gerar uma esfera (primitive UV Sphere) dentro do Geometry Nodes, ou usar um objeto esfera fora do GN e mover sua posição via controlador.
4. Simular movimento da bola sobre o rail (posição sobre a curva)
- No Geometry Nodes você pode usar o node "Sample Nearest" ou "Sample Curve" para pegar pontos e direções sobre a curva da pista.
- Use uma entrada de parâmetro "Factor" (de 0 a 1) para definir a posição da bola sobre a curva.
5. Animar a posição da bola
- Na instância ou transform do ponto da bola, use um valor animado (ex: driver, keyframe ou input do Geometry Nodes) para avançar o valor de
Factorao longo do tempo, simulando movimento.
6. Rotação da bola
- Para simular o giro da bola de forma realista, pode-se calcular o deslocamento ao longo da curva e converter a distância percorrida em uma rotação da esfera.
- Isso demanda calcular o vetor tangente da curva para ajustar a orientação da bola e rotacionar o objeto, simulando o efeito de rolamento.
Exemplo prático simplificado (Blender 3.0+):
-
Crie uma curva (Bezier, ou NURBS) manualmente — sua pista.
-
Crie um Geometry Nodes modifier para o objeto bola (ou adicione a bola via GN):
-
Adicione um parâmetro de entrada para controlar o "Position on Curve" (de 0 a 1).
-
Use o node "Sample Nearest" ou "Sample Curve Parameter" para pegar a posição no ponto da curva.
-
Insira um "Set Position" para definir a localização da bola.
-
-
Animar o parâmetro de posição
- Você pode animar manualmente esse valor, criar um driver, ou usar outra entrada para controlar o movimento da bola.
-
Ajustar a rotação da bola
-
Use
Sample Curve Tangentpara pegar a direção da curva naquele ponto. -
Calcule o ângulo de rotação correta (matematicamente converta o avanço em rotação de uma esfera).
-
Aplique essa rotação para simular o giro da bola.
-
Limitações:
- Geometry Nodes não é uma ferramenta de simulação física real. Portanto não terá colisão rigid body nativa ou interação física automática.
- Para simular física real, você ainda precisará usar o sistema physics do Blender (Rigid Body), mas pode controlar transformações e animações via GN.
- Também não é trivial fazer pistas com loops e interações complexas como o addon Python — GN é mais para computação procedural de geometria e manipulação.
Recursos para aprender Geometry Nodes aplicados a este caso:
- Blender manual - Geometry Nodes Curve
- Tutoriais no YouTube sobre: "Geometry Nodes Ball rolling along curve" e "Geometry Nodes Curve motion animation"
- Exemplos de uso dos nodes:
- Sample Curve Position
- Sample Curve Tangent
- Set Position
- Set Rotation
- Input Value (para controlar animação)
- Curve to Mesh (para criar o rail)
Se quiser, posso te ajudar a montar um exemplo simples de Geometry Nodes configurado para isso — basta pedir. Você pode copiar e colar o node tree que eu montar para animação da bola sobre uma curva.
Resumo
- Use uma curva como rail.
- Use Geometry Nodes para posicionar um objeto (bola) segundo um parâmetro percentual ao longo dessa curva.
- Anime esse parâmetro para fazer a bola "rolar" do começo ao fim.
- Calcule rotação baseada no deslocamento para simular giro da bola.
- Use modifiers fora do Geometry Nodes para pistas e física real, se necessário.
Se desejar, posso montar um tutorial passo-a-passo com imagens ou explicação mais detalhada do node tree. Quer?
- User
verifique se o addon foi corrigido: bl_info = { "name": "Rolling Ball Simulation Addon", "blender": (2, 80, 0), "category": "Physics", }
import bpy import math from bpy.props import EnumProperty, FloatProperty, BoolProperty, IntProperty, StringProperty import mathutils
Predefined rail tracks
RAIL_TRACKS = [ ("SPIRAL", "Spiral", "A spiral track"), ("LOOP", "Loop", "A loop track"), ("DROP", "Drop", "A drop track"), ("CORKSCREW", "Corkscrew", "A corkscrew track"), ("BANKED_TURN", "Banked Turn", "A banked turn track"), ("HILL", "Hill", "A hill track"), ("TWIST", "Twist", "A twist track"), ("HELIX", "Helix", "A helix track"), ("SWITCHBACK", "Switchback", "A switchback track"), ("MULTI_LOOP", "Multi-Loop", "A multi-loop track"), ("CUBIC_SPIRAL", "Cubic Spiral", "A cubic spiral track"), ("SINE_WAVE", "Sine Wave", "A sine wave track"), ("PARABOLA", "Parabola", "A parabolic track"), ("ARC", "Arc", "An arc track"), ("HELICAL_TWIST", "Helical Twist", "A helical twist track"), ("SLOPE", "Slope", "A slope track"), ("HELICAL_DROP", "Helical Drop", "A helical drop track"), ("TOWER_OF_TERROR", "Tower of Terror", "A tower of terror track"), ("VERTICAL_LOOP", "Vertical Loop", "A vertical loop track"), ("CIRCLE", "Circle", "A circular track"), ]
def create_spiral(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="SpiralCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SpiralRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_loop(radius=1, height=2): curve_data = bpy.data.curves.new(name="LoopCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("LoopRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_drop(radius=1, height=5): curve_data = bpy.data.curves.new(name="DropCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * math.cos(2 * math.pi * t) y = radius * math.sin(2 * math.pi * t) z = height * (1 - t) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("DropRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_corkscrew(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="CorkscrewCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("CorkscrewRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_banked_turn(radius=1, height=2, angle=45): curve_data = bpy.data.curves.new(name="BankedTurnCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' # Apply banking transformation mat = mathutils.Matrix.Rotation(math.radians(angle), 4, 'Z') for point in points: point.co = mat @ mathutils.Vector(point.co) point.handle_left = mat @ mathutils.Vector(point.handle_left) point.handle_right = mat @ mathutils.Vector(point.handle_right) obj = bpy.data.objects.new("BankedTurnRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_hill(radius=1, height=5): curve_data = bpy.data.curves.new(name="HillCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * (1 - (t - 0.5) ** 2) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("HillRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_twist(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="TwistCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' # Apply twist transformation for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t mat = mathutils.Matrix.Rotation(math.radians(angle), 4, 'Z') points[i].co = mat @ mathutils.Vector(points[i].co) points[i].handle_left = mat @ mathutils.Vector(points[i].handle_left) points[i].handle_right = mat @ mathutils.Vector(points[i].handle_right) obj = bpy.data.objects.new("TwistRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_helix(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="HelixCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("HelixRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_switchback(radius=1, height=5): curve_data = bpy.data.curves.new(name="SwitchbackCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) if t < 0.5: angle = 2 * math.pi * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) else: angle = 2 * math.pi * (1 - t) z = height * (1 - t) x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SwitchbackRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_multi_loop(radius=1, height=5, loops=3): curve_data = bpy.data.curves.new(name="MultiLoopCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 100 * loops points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("MultiLoopRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_cubic_spiral(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="CubicSpiralCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t ** 3 x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("CubicSpiralRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_sine_wave(radius=1, height=5, waves=2): curve_data = bpy.data.curves.new(name="SineWaveCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * math.sin(2 * math.pi * waves * t) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SineWaveRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_parabola(radius=1, height=5): curve_data = bpy.data.curves.new(name="ParabolaCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * (t - 0.5) ** 2 points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("ParabolaRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_arc(radius=1, height=5): curve_data = bpy.data.curves.new(name="ArcCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * t points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("ArcRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_helical_twist(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="HelicalTwistCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' # Apply twist transformation for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t mat = mathutils.Matrix.Rotation(math.radians(angle), 4, 'Z') points[i].co = mat @ mathutils.Vector(points[i].co) points[i].handle_left = mat @ mathutils.Vector(points[i].handle_left) points[i].handle_right = mat @ mathutils.Vector(points[i].handle_right) obj = bpy.data.objects.new("HelicalTwistRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_slope(radius=1, height=5): curve_data = bpy.data.curves.new(name="SlopeCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * t points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SlopeRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_helical_drop(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="HelicalDropCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * (1 - t) x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("HelicalDropRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_tower_of_terror(radius=1, height=5): curve_data = bpy.data.curves.new(name="TowerOfTerrorCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t z = height * (1 - t) x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("TowerOfTerrorRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_vertical_loop(radius=1, height=5): curve_data = bpy.data.curves.new(name="VerticalLoopCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("VerticalLoopRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_circle(radius=1): curve_data = bpy.data.curves.new(name="CircleCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = 0 points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("CircleRail", curve_data) bpy.context.collection.objects.link(obj) return objdef add_rail(track_type): if track_type == 'SPIRAL': rail = create_spiral() elif track_type == 'LOOP': rail = create_loop() elif track_type == 'DROP': rail = create_drop() elif track_type == 'CORKSCREW': rail = create_corkscrew() elif track_type == 'BANKED_TURN': rail = create_banked_turn() elif track_type == 'HILL': rail = create_hill() elif track_type == 'TWIST': rail = create_twist() elif track_type == 'HELIX': rail = create_helix() elif track_type == 'SWITCHBACK': rail = create_switchback() elif track_type == 'MULTI_LOOP': rail = create_multi_loop() elif track_type == 'CUBIC_SPIRAL': rail = create_cubic_spiral() elif track_type == 'SINE_WAVE': rail = create_sine_wave() elif track_type == 'PARABOLA': rail = create_parabola() elif track_type == 'ARC': rail = create_arc() elif track_type == 'HELICAL_TWIST': rail = create_helical_twist() elif track_type == 'SLOPE': rail = create_slope() elif track_type == 'HELICAL_DROP': rail = create_helical_drop() elif track_type == 'TOWER_OF_TERROR': rail = create_tower_of_terror() elif track_type == 'VERTICAL_LOOP': rail = create_vertical_loop() elif track_type == 'CIRCLE': rail = create_circle() else: return None
if rail: add_rigid_body_to_object(rail, type='PASSIVE') return raildef add_ball(location): bpy.ops.mesh.primitive_uv_sphere_add(radius=bpy.context.scene.ball_radius, location=location) ball = bpy.context.object ball.name = f"RollingBall_{len([obj for obj in bpy.data.objects if obj.name.startswith('RollingBall_')])}" add_rigid_body_to_object(ball, type='ACTIVE') return ball
def add_rigid_body_to_object(obj, type='PASSIVE'): # Ensure we are in Object Mode if bpy.context.mode != 'OBJECT': bpy.ops.object.mode_set(mode='OBJECT')
# Deselect all objects bpy.ops.object.select_all(action='DESELECT') # Select and make the object active obj.select_set(True) bpy.context.view_layer.objects.active = obj # Add rigid body physics bpy.ops.rigidbody.object_add(type=type) if type == 'PASSIVE': obj.rigid_body.collision_shape = 'MESH' elif type == 'ACTIVE': obj.rigid_body.collision_shape = 'SPHERE' obj.rigid_body.friction = bpy.context.scene.ball_friction obj.rigid_body.restitution = bpy.context.scene.ball_restitution obj.rigid_body.linear_damping = bpy.context.scene.ball_linear_damping obj.rigid_body.angular_damping = bpy.context.scene.ball_angular_damping obj.rigid_body.mass = bpy.context.scene.ball_massdef set_simulation_gravity(gravity): scene = bpy.context.scene if scene.rigidbody_world: scene.rigidbody_world.point_cache.frame_start = 1 scene.rigidbody_world.point_cache.frame_end = 250 scene.rigidbody_world.time_scale = bpy.context.scene.simulation_speed scene.rigidbody_world.gravity = (0, 0, gravity)
def start_simulation(): scene = bpy.context.scene set_simulation_gravity(scene.simulation_gravity) bpy.ops.screen.animation_play()
def pause_simulation(): bpy.ops.screen.animation_cancel()
def reset_simulation(): scene = bpy.context.scene pause_simulation() bpy.ops.screen.frame_jump(end=False) for obj in bpy.data.objects: if obj.rigid_body: obj.rigid_body.kinematic = True obj.location = obj.rigid_body.world_center_of_mass obj.rotation_euler = (0, 0, 0) obj.keyframe_insert(data_path="location", frame=1) obj.keyframe_insert(data_path="rotation_euler", frame=1) obj.rigid_body.kinematic = False
class PHYSICS_PT_rolling_ball(bpy.types.Panel): bl_label = "Rolling Ball Simulation" bl_idname = "PHYSICS_PT_rolling_ball" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = 'Physics'
def draw(self, context): layout = self.layout scene = context.scene layout.prop(scene, "selected_track") layout.operator("physics.add_rail", text="Add Rail", icon='MOD_CURVE') layout.operator("physics.add_ball", text="Add Ball", icon='SPHERE') layout.separator() layout.operator("physics.start_simulation", text="Start Simulation", icon='PLAY') layout.operator("physics.pause_simulation", text="Pause Simulation", icon='PAUSE') layout.operator("physics.reset_simulation", text="Reset Simulation", icon='REW') layout.separator() box = layout.box() box.label(text="Simulation Controls", icon='PHYSICS') box.prop(scene, "simulation_gravity", text="Gravity", icon='FORCE_GRAVITY') box.prop(scene, "simulation_speed", text="Speed", icon='TIME') layout.separator() box = layout.box() box.label(text="Ball Parameters", icon='SPHERE') box.prop(scene, "ball_radius", text="Radius", icon='MESH_UVSPHERE') box.prop(scene, "ball_mass", text="Mass", icon='MOD_PHYSICS') box.prop(scene, "ball_friction", text="Friction", icon='MOD_SMOOTH') box.prop(scene, "ball_restitution", text="Restitution", icon='SNAP_INCREMENT') box.prop(scene, "ball_linear_damping", text="Linear Damping", icon='MOD_PHYSICS') box.prop(scene, "ball_angular_damping", text="Angular Damping", icon='MOD_PHYSICS')class PHYSICS_OT_add_rail(bpy.types.Operator): bl_idname = "physics.add_rail" bl_label = "Add Rail" bl_description = "Add a predefined rail track" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): scene = context.scene rail = add_rail(scene.selected_track) return {'FINISHED'}class PHYSICS_OT_add_ball(bpy.types.Operator): bl_idname = "physics.add_ball" bl_label = "Add Ball" bl_description = "Add a ball at the start of the selected rail" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): scene = context.scene rail = bpy.data.objects.get(f"Rail_{scene.selected_track}_1") if rail and rail.data.splines: start_point = rail.matrix_world @ rail.data.splines[0].bezier_points[0].co ball_offset = mathutils.Vector((0, 0, bpy.context.scene.ball_radius * 1.1)) ball_location = start_point + ball_offset ball = add_ball(ball_location) return {'FINISHED'}class PHYSICS_OT_start_simulation(bpy.types.Operator): bl_idname = "physics.start_simulation" bl_label = "Start Simulation" bl_description = "Start the physics simulation" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): start_simulation() return {'FINISHED'}class PHYSICS_OT_pause_simulation(bpy.types.Operator): bl_idname = "physics.pause_simulation" bl_label = "Pause Simulation" bl_description = "Pause the physics simulation" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): pause_simulation() return {'FINISHED'}class PHYSICS_OT_reset_simulation(bpy.types.Operator): bl_idname = "physics.reset_simulation" bl_label = "Reset Simulation" bl_description = "Reset the physics simulation" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): reset_simulation() return {'FINISHED'}def register(): bpy.utils.register_class(PHYSICS_PT_rolling_ball) bpy.utils.register_class(PHYSICS_OT_add_rail) bpy.utils.register_class(PHYSICS_OT_add_ball) bpy.utils.register_class(PHYSICS_OT_start_simulation) bpy.utils.register_class(PHYSICS_OT_pause_simulation) bpy.utils.register_class(PHYSICS_OT_reset_simulation)
bpy.types.Scene.selected_track = EnumProperty( name="Selected Track", description="Choose a rail track", items=RAIL_TRACKS, default='SPIRAL', ) bpy.types.Scene.ball_radius = FloatProperty( name="Ball Radius", description="Radius of the ball", default=0.5, min=0.1, max=1.0, ) bpy.types.Scene.ball_mass = FloatProperty( name="Ball Mass", description="Mass of the ball", default=1.0, min=0.1, max=10.0, ) bpy.types.Scene.ball_friction = FloatProperty( name="Ball Friction", description="Friction of the ball", default=0.5, min=0.0, max=1.0, ) bpy.types.Scene.ball_restitution = FloatProperty( name="Ball Restitution", description="Restitution of the ball", default=0.0, min=0.0, max=1.0, ) bpy.types.Scene.ball_linear_damping = FloatProperty( name="Linear Damping", description="Linear damping of the ball", default=0.1, min=0.0, max=1.0, ) bpy.types.Scene.ball_angular_damping = FloatProperty( name="Angular Damping", description="Angular damping of the ball", default=0.1, min=0.0, max=1.0, ) bpy.types.Scene.simulation_gravity = FloatProperty( name="Simulation Gravity", description="Simulation gravity", default=-9.81, min=-10.0, max=10.0, ) bpy.types.Scene.simulation_speed = FloatProperty( name="Simulation Speed", description="Simulation speed multiplier", default=1.0, min=0.1, max=10.0, )def unregister(): bpy.utils.unregister_class(PHYSICS_PT_rolling_ball) bpy.utils.unregister_class(PHYSICS_OT_add_rail) bpy.utils.unregister_class(PHYSICS_OT_add_ball) bpy.utils.unregister_class(PHYSICS_OT_start_simulation) bpy.utils.unregister_class(PHYSICS_OT_pause_simulation) bpy.utils.unregister_class(PHYSICS_OT_reset_simulation)
del bpy.types.Scene.selected_track del bpy.types.Scene.ball_radius del bpy.types.Scene.ball_mass del bpy.types.Scene.ball_friction del bpy.types.Scene.ball_restitution del bpy.types.Scene.ball_linear_damping del bpy.types.Scene.ball_angular_damping del bpy.types.Scene.simulation_gravity del bpy.types.Scene.simulation_speedif name == "main": register()
- Assistant
Seu código parece estar bastante corrigido e estruturado, com os principais pontos que eu destaquei anteriormente ajustados. A seguir, um resumo dos pontos corrigidos e observações finais para garantir que o addon funcione conforme esperado:
Pontos corrigidos no seu código:
- Aspas corrigidas na linha de nomeação do objeto bola:
ball.name = f"RollingBall_{len([obj for obj in bpy.data.objects if obj.name.startswith('RollingBall_')])}" - Twist e Helical Twist: agora o cálculo progressivo da transformação de rotação é feito dentro de loop por ponto (com variável
ipercorrendo os pontos), aplicando uma rotação diferente para cada ponto, corrigindo erro da versão anterior. - Gravidade da simulação ajustada:
scene.rigidbody_world.gravity = (0, 0, gravity) - Removida duplicação de atribuição do nome do rail ao adicionar pista, nome não é mais redefinido duas vezes.
- Função para adicionar corpo rígido está chamando
bpy.opscom manipulação correta do contexto e modos. - Reset da simulação mantém a lógica básica, apesar de poder ser melhorada (como explicado abaixo).
- Operadores configurados com
REGISTEReUNDOe painel UI estruturado.
Pequenas recomendações/alertas para verificar:
-
Reset da Simulação
- O reset simples feito pode não redefinir perfeitamente o estado da simulação.
- Considere usar
bpy.ops.ptcache.free_bake_all()para limpar os caches da simulação. - Salvar a posição inicial dos objetos na criação pode ajudar a reposicionar exatamente no reset.
- Alternativamente: use
bpy.context.scene.frame_set(1)ao invés debpy.ops.screen.frame_jump(end=False).
-
Nomeação dos Objects
- O método para nomear objetos usa o exemplo:
Note que esse valor será o número total de bolas, então o nome pode repetir se um objeto for apagado. Talvez quiser usar IDs únicos ou armazenar contadores em propriedades da cena.len([obj for obj in bpy.data.objects if obj.name.startswith('RollingBall_')])
- O método para nomear objetos usa o exemplo:
-
Contexto para Operadores
- Quando operadores são chamados em diferentes modos, geralmente o código já faz a troca para 'OBJECT' mode, o que é correto para
bpy.ops. - No entanto, mudanças bruscas de modo podem confundir o usuário; considere avisar ou garantir contexto ou usar API direta quando possível.
- Quando operadores são chamados em diferentes modos, geralmente o código já faz a troca para 'OBJECT' mode, o que é correto para
-
Parâmetros Dinâmicos para as Pistas
- Se desejar maior flexibilidade, pode-se expor os parâmetros (radius, height, turns, etc.) no painel UI e repassar nos métodos de criação das curvas, assim o usuário personaliza diretamente.
Testes recomendados
- Teste a criação das pistas, valide visualmente as curvas.
- Adicione bola e confira se ela é posicionada corretamente no começo da pista.
- Inicie a simulação física e veja a interação bola/pista.
- Pause, reinicie, resete e observe se os objetos retornam a posições corretas.
- Faça testes com diferentes configurações do painel (massa, fricção, restituição, etc).
Conclusão
Seu addon parece estar funcional e corrigido nas principais partes. Se você executar e não encontrar erros de sintaxe, o fluxo básico de criação da pista, adição da bola e controle da simulação deverá funcionar.
Se quiser, posso ajudar a criar versões mais avançadas, melhorar o reset, adicionar parâmetros configuráveis para as pistas, ou até migrar a lógica para Geometry Nodes conforme seu interesse.
Se precisar, posso também revisar e ajudar a rodar o addon em versões mais recentes do Blender.
Se quiser, posso revisar ou sugerir melhorias específicas também, é só pedir!
- Aspas corrigidas na linha de nomeação do objeto bola:
- User
Python: Traceback (most recent call last): File "\Text", line 712, in draw TypeError: UILayout.prop(): error with keyword argument "icon" - enum "FORCE_GRAVITY" not found in ('NONE', 'QUESTION', 'ERROR', 'CANCEL', 'TRIA_RIGHT', 'TRIA_DOWN', 'TRIA_LEFT', 'TRIA_UP', 'ARROW_LEFTRIGHT', 'PLUS', 'DISCLOSURE_TRI_RIGHT', 'DISCLOSURE_TRI_DOWN', 'RADIOBUT_OFF', 'RADIOBUT_ON', 'MENU_PANEL', 'BLENDER', 'GRIP', 'DOT', 'COLLAPSEMENU', 'X', 'DUPLICATE', 'TRASH', 'COLLECTION_NEW', 'OPTIONS', 'NODE', 'NODE_SEL', 'WINDOW', 'WORKSPACE', 'RIGHTARROW_THIN', 'BORDERMOVE', 'VIEWZOOM', 'ADD', 'REMOVE', 'PANEL_CLOSE', 'COPY_ID', 'EYEDROPPER', 'CHECKMARK', 'AUTO', 'CHECKBOX_DEHLT', 'CHECKBOX_HLT', 'UNLOCKED', 'LOCKED', 'UNPINNED', 'PINNED', 'SCREEN_BACK', 'RIGHTARROW', 'DOWNARROW_HLT', 'FCURVE_SNAPSHOT', 'OBJECT_HIDDEN', 'TOPBAR', 'STATUSBAR', 'PLUGIN', 'HELP', 'GHOST_ENABLED', 'COLOR', 'UNLINKED', 'LINKED', 'HAND', 'ZOOM_ALL', 'ZOOM_SELECTED', 'ZOOM_PREVIOUS', 'ZOOM_IN', 'ZOOM_OUT', 'DRIVER_DISTANCE', 'DRIVER_ROTATIONAL_DIFFERENCE', 'DRIVER_TRANSFORM', 'FREEZE', 'STYLUS_PRESSURE', 'GHOST_DISABLED', 'FILE_NEW', 'FILE_TICK', 'QUIT', 'URL', 'RECOVER_LAST', 'THREE_DOTS', 'FULLSCREEN_ENTER', 'FULLSCREEN_EXIT', 'BRUSHES_ALL', 'LIGHT', 'MATERIAL', 'TEXTURE', 'ANIM', 'WORLD', 'SCENE', 'OUTPUT', 'SCRIPT', 'PARTICLES', 'PHYSICS', 'SPEAKER', 'TOOL_SETTINGS', 'SHADERFX', 'MODIFIER', 'RECORD_OFF', 'RECORD_ON', 'BLANK1', 'FAKE_USER_OFF', 'FAKE_USER_ON', 'VIEW3D', 'GRAPH', 'OUTLINER', 'PROPERTIES', 'FILEBROWSER', 'IMAGE', 'INFO', 'SEQUENCE', 'TEXT', 'SPREADSHEET', 'SOUND', 'ACTION', 'NLA', 'PREFERENCES', 'TIME', 'NODETREE', 'GEOMETRY_NODES', 'CONSOLE', 'TRACKER', 'ASSET_MANAGER', 'NODE_COMPOSITING', 'NODE_TEXTURE', 'NODE_MATERIAL', 'UV', 'OBJECT_DATAMODE', 'EDITMODE_HLT', 'UV_DATA', 'VPAINT_HLT', 'TPAINT_HLT', 'WPAINT_HLT', 'SCULPTMODE_HLT', 'POSE_HLT', 'PARTICLEMODE', 'TRACKING', 'TRACKING_BACKWARDS', 'TRACKING_FORWARDS', 'TRACKING_BACKWARDS_SINGLE', 'TRACKING_FORWARDS_SINGLE', 'TRACKING_CLEAR_BACKWARDS', 'TRACKING_CLEAR_FORWARDS', 'TRACKING_REFINE_BACKWARDS', 'TRACKING_REFINE_FORWARDS', 'SCENE_DATA', 'RENDERLAYERS', 'WORLD_DATA', 'OBJECT_DATA', 'MESH_DATA', 'CURVE_DATA', 'META_DATA', 'LATTICE_DATA', 'LIGHT_DATA', 'MATERIAL_DATA', 'TEXTURE_DATA', 'ANIM_DATA', 'CAMERA_DATA', 'PARTICLE_DATA', 'LIBRARY_DATA_DIRECT', 'GROUP', 'ARMATURE_DATA', 'COMMUNITY', 'BONE_DATA', 'CONSTRAINT', 'SHAPEKEY_DATA', 'CONSTRAINT_BONE', 'CAMERA_STEREO', 'PACKAGE', 'UGLYPACKAGE', 'EXPERIMENTAL', 'BRUSH_DATA', 'IMAGE_DATA', 'FILE', 'FCURVE', 'FONT_DATA', 'RENDER_RESULT', 'SURFACE_DATA', 'EMPTY_DATA', 'PRESET', 'RENDER_ANIMATION', 'RENDER_STILL', 'LIBRARY_DATA_BROKEN', 'BOIDS', 'STRANDS', 'GREASEPENCIL', 'LINE_DATA', 'LIBRARY_DATA_OVERRIDE', 'GROUP_BONE', 'GROUP_VERTEX', 'GROUP_VCOL', 'GROUP_UVS', 'FACE_MAPS', 'RNA', 'RNA_ADD', 'MOUSE_LMB', 'MOUSE_MMB', 'MOUSE_RMB', 'MOUSE_MOVE', 'MOUSE_LMB_DRAG', 'MOUSE_MMB_DRAG', 'MOUSE_RMB_DRAG', 'MEMORY', 'PRESET_NEW', 'DECORATE', 'DECORATE_KEYFRAME', 'DECORATE_ANIMATE', 'DECORATE_DRIVER', 'DECORATE_LINKED', 'DECORATE_LIBRARY_OVERRIDE', 'DECORATE_UNLOCKED', 'DECORATE_LOCKED', 'DECORATE_OVERRIDE', 'FUND', 'TRACKER_DATA', 'HEART', 'ORPHAN_DATA', 'USER', 'SYSTEM', 'SETTINGS', 'OUTLINER_OB_EMPTY', 'OUTLINER_OB_MESH', 'OUTLINER_OB_CURVE', 'OUTLINER_OB_LATTICE', 'OUTLINER_OB_META', 'OUTLINER_OB_LIGHT', 'OUTLINER_OB_CAMERA', 'OUTLINER_OB_ARMATURE', 'OUTLINER_OB_FONT', 'OUTLINER_OB_SURFACE', 'OUTLINER_OB_SPEAKER', 'OUTLINER_OB_FORCE_FIELD', 'OUTLINER_OB_GROUP_INSTANCE', 'OUTLINER_OB_GREASEPENCIL', 'OUTLINER_OB_LIGHTPROBE', 'OUTLINER_OB_IMAGE', 'OUTLINER_COLLECTION', 'RESTRICT_COLOR_OFF', 'RESTRICT_COLOR_ON', 'HIDE_ON', 'HIDE_OFF', 'RESTRICT_SELECT_ON', 'RESTRICT_SELECT_OFF', 'RESTRICT_RENDER_ON', 'RESTRICT_RENDER_OFF', 'RESTRICT_INSTANCED_OFF', 'OUTLINER_DATA_EMPTY', 'OUTLINER_DATA_MESH', 'OUTLINER_DATA_CURVE', 'OUTLINER_DATA_LATTICE', 'OUTLINER_DATA_META', 'OUTLINER_DATA_LIGHT', 'OUTLINER_DATA_CAMERA', 'OUTLINER_DATA_ARMATURE', 'OUTLINER_DATA_FONT', 'OUTLINER_DATA_SURFACE', 'OUTLINER_DATA_SPEAKER', 'OUTLINER_DATA_LIGHTPROBE', 'OUTLINER_DATA_GP_LAYER', 'OUTLINER_DATA_GREASEPENCIL', 'GP_SELECT_POINTS', 'GP_SELECT_STROKES', 'GP_MULTIFRAME_EDITING', 'GP_ONLY_SELECTED', 'GP_SELECT_BETWEEN_STROKES', 'MODIFIER_OFF', 'MODIFIER_ON', 'ONIONSKIN_OFF', 'ONIONSKIN_ON', 'RESTRICT_VIEW_ON', 'RESTRICT_VIEW_OFF', 'RESTRICT_INSTANCED_ON', 'MESH_PLANE', 'MESH_CUBE', 'MESH_CIRCLE', 'MESH_UVSPHERE', 'MESH_ICOSPHERE', 'MESH_GRID', 'MESH_MONKEY', 'MESH_CYLINDER', 'MESH_TORUS', 'MESH_CONE', 'MESH_CAPSULE', 'EMPTY_SINGLE_ARROW', 'LIGHT_POINT', 'LIGHT_SUN', 'LIGHT_SPOT', 'LIGHT_HEMI', 'LIGHT_AREA', 'CUBE', 'SPHERE', 'CONE', 'META_PLANE', 'META_CUBE', 'META_BALL', 'META_ELLIPSOID', 'META_CAPSULE', 'SURFACE_NCURVE', 'SURFACE_NCIRCLE', 'SURFACE_NSURFACE', 'SURFACE_NCYLINDER', 'SURFACE_NSPHERE', 'SURFACE_NTORUS', 'EMPTY_AXIS', 'STROKE', 'EMPTY_ARROWS', 'CURVE_BEZCURVE', 'CURVE_BEZCIRCLE', 'CURVE_NCURVE', 'CURVE_NCIRCLE', 'CURVE_PATH', 'LIGHTPROBE_SPHERE', 'LIGHTPROBE_PLANE', 'LIGHTPROBE_VOLUME', 'COLOR_RED', 'COLOR_GREEN', 'COLOR_BLUE', 'TRIA_RIGHT_BAR', 'TRIA_DOWN_BAR', 'TRIA_LEFT_BAR', 'TRIA_UP_BAR', 'FORCE_FORCE', 'FORCE_WIND', 'FORCE_VORTEX', 'FORCE_MAGNETIC', 'FORCE_HARMONIC', 'FORCE_CHARGE', 'FORCE_LENNARDJONES', 'FORCE_TEXTURE', 'FORCE_CURVE', 'FORCE_BOID', 'FORCE_TURBULENCE', 'FORCE_DRAG', 'FORCE_FLUIDFLOW', 'RIGID_BODY', 'RIGID_BODY_CONSTRAINT', 'AREA_JOIN', 'AREA_SWAP', 'SPLIT_HORIZONTAL', 'SPLIT_VERTICAL', 'IMAGE_PLANE', 'IMAGE_BACKGROUND', 'IMAGE_REFERENCE', 'NODE_INSERT_ON', 'NODE_INSERT_OFF', 'NODE_TOP', 'NODE_SIDE', 'NODE_CORNER', 'ANCHOR_TOP', 'ANCHOR_BOTTOM', 'ANCHOR_LEFT', 'ANCHOR_RIGHT', 'ANCHOR_CENTER', 'SELECT_SET', 'SELECT_EXTEND', 'SELECT_SUBTRACT', 'SELECT_INTERSECT', 'SELECT_DIFFERENCE', 'ALIGN_LEFT', 'ALIGN_CENTER', 'ALIGN_RIGHT', 'ALIGN_JUSTIFY', 'ALIGN_FLUSH', 'ALIGN_TOP', 'ALIGN_MIDDLE', 'ALIGN_BOTTOM', 'BOLD', 'ITALIC', 'UNDERLINE', 'SMALL_CAPS', 'CON_ACTION', 'MOD_ENVELOPE', 'MOD_OUTLINE', 'MOD_LENGTH', 'MOD_DASH', 'MOD_LINEART', 'HOLDOUT_OFF', 'HOLDOUT_ON', 'INDIRECT_ONLY_OFF', 'INDIRECT_ONLY_ON', 'CON_CAMERASOLVER', 'CON_FOLLOWTRACK', 'CON_OBJECTSOLVER', 'CON_LOCLIKE', 'CON_ROTLIKE', 'CON_SIZELIKE', 'CON_TRANSLIKE', 'CON_DISTLIMIT', 'CON_LOCLIMIT', 'CON_ROTLIMIT', 'CON_SIZELIMIT', 'CON_SAMEVOL', 'CON_TRANSFORM', 'CON_TRANSFORM_CACHE', 'CON_CLAMPTO', 'CON_KINEMATIC', 'CON_LOCKTRACK', 'CON_SPLINEIK', 'CON_STRETCHTO', 'CON_TRACKTO', 'CON_ARMATURE', 'CON_CHILDOF', 'CON_FLOOR', 'CON_FOLLOWPATH', 'CON_PIVOT', 'CON_SHRINKWRAP', 'MODIFIER_DATA', 'MOD_WAVE', 'MOD_BUILD', 'MOD_DECIM', 'MOD_MIRROR', 'MOD_SOFT', 'MOD_SUBSURF', 'HOOK', 'MOD_PHYSICS', 'MOD_PARTICLES', 'MOD_BOOLEAN', 'MOD_EDGESPLIT', 'MOD_ARRAY', 'MOD_UVPROJECT', 'MOD_DISPLACE', 'MOD_CURVE', 'MOD_LATTICE', 'MOD_TINT', 'MOD_ARMATURE', 'MOD_SHRINKWRAP', 'MOD_CAST', 'MOD_MESHDEFORM', 'MOD_BEVEL', 'MOD_SMOOTH', 'MOD_SIMPLEDEFORM', 'MOD_MASK', 'MOD_CLOTH', 'MOD_EXPLODE', 'MOD_FLUIDSIM', 'MOD_MULTIRES', 'MOD_FLUID', 'MOD_SOLIDIFY', 'MOD_SCREW', 'MOD_VERTEX_WEIGHT', 'MOD_DYNAMICPAINT', 'MOD_REMESH', 'MOD_OCEAN', 'MOD_WARP', 'MOD_SKIN', 'MOD_TRIANGULATE', 'MOD_WIREFRAME', 'MOD_DATA_TRANSFER', 'MOD_NORMALEDIT', 'MOD_PARTICLE_INSTANCE', 'MOD_HUE_SATURATION', 'MOD_NOISE', 'MOD_OFFSET', 'MOD_SIMPLIFY', 'MOD_THICKNESS', 'MOD_INSTANCE', 'MOD_TIME', 'MOD_OPACITY', 'REC', 'PLAY', 'FF', 'REW', 'PAUSE', 'PREV_KEYFRAME', 'NEXT_KEYFRAME', 'PLAY_SOUND', 'PLAY_REVERSE', 'PREVIEW_RANGE', 'ACTION_TWEAK', 'PMARKER_ACT', 'PMARKER_SEL', 'PMARKER', 'MARKER_HLT', 'MARKER', 'KEYFRAME_HLT', 'KEYFRAME', 'KEYINGSET', 'KEY_DEHLT', 'KEY_HLT', 'MUTE_IPO_OFF', 'MUTE_IPO_ON', 'DRIVER', 'SOLO_OFF', 'SOLO_ON', 'FRAME_PREV', 'FRAME_NEXT', 'NLA_PUSHDOWN', 'IPO_CONSTANT', 'IPO_LINEAR', 'IPO_BEZIER', 'IPO_SINE', 'IPO_QUAD', 'IPO_CUBIC', 'IPO_QUART', 'IPO_QUINT', 'IPO_EXPO', 'IPO_CIRC', 'IPO_BOUNCE', 'IPO_ELASTIC', 'IPO_BACK', 'IPO_EASE_IN', 'IPO_EASE_OUT', 'IPO_EASE_IN_OUT', 'NORMALIZE_FCURVES', 'ORIENTATION_PARENT', 'FACE_CORNER', 'VERTEXSEL', 'EDGESEL', 'FACESEL', 'CURSOR', 'PIVOT_BOUNDBOX', 'PIVOT_CURSOR', 'PIVOT_INDIVIDUAL', 'PIVOT_MEDIAN', 'PIVOT_ACTIVE', 'CENTER_ONLY', 'ROOTCURVE', 'SMOOTHCURVE', 'SPHERECURVE', 'INVERSESQUARECURVE', 'SHARPCURVE', 'LINCURVE', 'NOCURVE', 'RNDCURVE', 'PROP_OFF', 'PROP_ON', 'PROP_CON', 'PROP_PROJECTED', 'PARTICLE_POINT', 'PARTICLE_TIP', 'PARTICLE_PATH', 'SNAP_FACE_NEAREST', 'SNAP_FACE_CENTER', 'SNAP_PERPENDICULAR', 'SNAP_MIDPOINT', 'SNAP_OFF', 'SNAP_ON', 'SNAP_NORMAL', 'SNAP_GRID', 'SNAP_VERTEX', 'SNAP_EDGE', 'SNAP_FACE', 'SNAP_VOLUME', 'SNAP_INCREMENT', 'STICKY_UVS_LOC', 'STICKY_UVS_DISABLE', 'STICKY_UVS_VERT', 'CLIPUV_DEHLT', 'CLIPUV_HLT', 'SNAP_PEEL_OBJECT', 'GRID', 'OBJECT_ORIGIN', 'ORIENTATION_GLOBAL', 'ORIENTATION_GIMBAL', 'ORIENTATION_LOCAL', 'ORIENTATION_NORMAL', 'ORIENTATION_VIEW', 'COPYDOWN', 'PASTEDOWN', 'PASTEFLIPUP', 'PASTEFLIPDOWN', 'VIS_SEL_11', 'VIS_SEL_10', 'VIS_SEL_01', 'VIS_SEL_00', 'AUTOMERGE_OFF', 'AUTOMERGE_ON', 'UV_VERTEXSEL', 'UV_EDGESEL', 'UV_FACESEL', 'UV_ISLANDSEL', 'UV_SYNC_SELECT', 'GP_CAPS_FLAT', 'GP_CAPS_ROUND', 'FIXED_SIZE', 'TRANSFORM_ORIGINS', 'GIZMO', 'ORIENTATION_CURSOR', 'NORMALS_VERTEX', 'NORMALS_FACE', 'NORMALS_VERTEX_FACE', 'SHADING_BBOX', 'SHADING_WIRE', 'SHADING_SOLID', 'SHADING_RENDERED', 'SHADING_TEXTURE', 'OVERLAY', 'XRAY', 'LOCKVIEW_OFF', 'LOCKVIEW_ON', 'AXIS_SIDE', 'AXIS_FRONT', 'AXIS_TOP', 'LAYER_USED', 'LAYER_ACTIVE', 'OUTLINER_OB_CURVES', 'OUTLINER_DATA_CURVES', 'CURVES_DATA', 'OUTLINER_OB_POINTCLOUD', 'OUTLINER_DATA_POINTCLOUD', 'POINTCLOUD_DATA', 'OUTLINER_OB_VOLUME', 'OUTLINER_DATA_VOLUME', 'VOLUME_DATA', 'POINTCLOUD_POINT', 'CURRENT_FILE', 'HOME', 'DOCUMENTS', 'TEMP', 'SORTALPHA', 'SORTBYEXT', 'SORTTIME', 'SORTSIZE', 'SHORTDISPLAY', 'LONGDISPLAY', 'IMGDISPLAY', 'BOOKMARKS', 'FONTPREVIEW', 'FILTER', 'NEWFOLDER', 'FOLDER_REDIRECT', 'FILE_PARENT', 'FILE_REFRESH', 'FILE_FOLDER', 'FILE_BLANK', 'FILE_BLEND', 'FILE_IMAGE', 'FILE_MOVIE', 'FILE_SCRIPT', 'FILE_SOUND', 'FILE_FONT', 'FILE_TEXT', 'SORT_DESC', 'SORT_ASC', 'LINK_BLEND', 'APPEND_BLEND', 'IMPORT', 'EXPORT', 'LOOP_BACK', 'LOOP_FORWARDS', 'BACK', 'FORWARD', 'FILE_ARCHIVE', 'FILE_CACHE', 'FILE_VOLUME', 'FILE_3D', 'FILE_HIDDEN', 'FILE_BACKUP', 'DISK_DRIVE', 'MATPLANE', 'MATSPHERE', 'MATCUBE', 'MONKEY', 'CURVES', 'ALIASED', 'ANTIALIASED', 'MAT_SPHERE_SKY', 'MATSHADERBALL', 'MATCLOTH', 'MATFLUID', 'WORDWRAP_OFF', 'WORDWRAP_ON', 'SYNTAX_OFF', 'SYNTAX_ON', 'LINENUMBERS_OFF', 'LINENUMBERS_ON', 'SCRIPTPLUGINS', 'DISC', 'DESKTOP', 'EXTERNAL_DRIVE', 'NETWORK_DRIVE', 'SEQ_SEQUENCER', 'SEQ_PREVIEW', 'SEQ_LUMA_WAVEFORM', 'SEQ_CHROMA_SCOPE', 'SEQ_HISTOGRAM', 'SEQ_SPLITVIEW', 'SEQ_STRIP_META', 'SEQ_STRIP_DUPLICATE', 'IMAGE_RGB', 'IMAGE_RGB_ALPHA', 'IMAGE_ALPHA', 'IMAGE_ZDEPTH', 'HANDLE_AUTOCLAMPED', 'HANDLE_AUTO', 'HANDLE_ALIGNED', 'HANDLE_VECTOR', 'HANDLE_FREE', 'VIEW_CAMERA_UNSELECTED', 'VIEW_UNLOCKED', 'VIEW_LOCKED', 'VIEW_PERSPECTIVE', 'VIEW_ORTHO', 'VIEW_CAMERA', 'VIEW_PAN', 'VIEW_ZOOM', 'BRUSH_BLOB', 'BRUSH_BLUR', 'BRUSH_CLAY', 'BRUSH_CLAY_STRIPS', 'BRUSH_CLONE', 'BRUSH_CREASE', 'BRUSH_FILL', 'BRUSH_FLATTEN', 'BRUSH_GRAB', 'BRUSH_INFLATE', 'BRUSH_LAYER', 'BRUSH_MASK', 'BRUSH_MIX', 'BRUSH_NUDGE', 'BRUSH_PAINT_SELECT', 'BRUSH_PINCH', 'BRUSH_SCRAPE', 'BRUSH_SCULPT_DRAW', 'BRUSH_SMEAR', 'BRUSH_SMOOTH', 'BRUSH_SNAKE_HOOK', 'BRUSH_SOFTEN', 'BRUSH_TEXDRAW', 'BRUSH_TEXFILL', 'BRUSH_TEXMASK', 'BRUSH_THUMB', 'BRUSH_ROTATE', 'GPBRUSH_SMOOTH', 'GPBRUSH_THICKNESS', 'GPBRUSH_STRENGTH', 'GPBRUSH_GRAB', 'GPBRUSH_PUSH', 'GPBRUSH_TWIST', 'GPBRUSH_PINCH', 'GPBRUSH_RANDOMIZE', 'GPBRUSH_CLONE', 'GPBRUSH_WEIGHT', 'GPBRUSH_PENCIL', 'GPBRUSH_PEN', 'GPBRUSH_INK', 'GPBRUSH_INKNOISE', 'GPBRUSH_BLOCK', 'GPBRUSH_MARKER', 'GPBRUSH_FILL', 'GPBRUSH_AIRBRUSH', 'GPBRUSH_CHISEL', 'GPBRUSH_ERASE_SOFT', 'GPBRUSH_ERASE_HARD', 'GPBRUSH_ERASE_STROKE', 'BRUSH_CURVES_ADD', 'BRUSH_CURVES_COMB', 'BRUSH_CURVES_CUT', 'BRUSH_CURVES_DELETE', 'BRUSH_CURVES_DENSITY', 'BRUSH_CURVES_GROW_SHRINK', 'BRUSH_CURVES_PINCH', 'BRUSH_CURVES_PUFF', 'BRUSH_CURVES_SLIDE', 'BRUSH_CURVES_SMOOTH', 'BRUSH_CURVES_SNAKE_HOOK', 'KEYTYPE_KEYFRAME_VEC', 'KEYTYPE_BREAKDOWN_VEC', 'KEYTYPE_EXTREME_VEC', 'KEYTYPE_JITTER_VEC', 'KEYTYPE_MOVING_HOLD_VEC', 'HANDLETYPE_FREE_VEC', 'HANDLETYPE_ALIGNED_VEC', 'HANDLETYPE_VECTOR_VEC', 'HANDLETYPE_AUTO_VEC', 'HANDLETYPE_AUTO_CLAMP_VEC', 'COLORSET_01_VEC', 'COLORSET_02_VEC', 'COLORSET_03_VEC', 'COLORSET_04_VEC', 'COLORSET_05_VEC', 'COLORSET_06_VEC', 'COLORSET_07_VEC', 'COLORSET_08_VEC', 'COLORSET_09_VEC', 'COLORSET_10_VEC', 'COLORSET_11_VEC', 'COLORSET_12_VEC', 'COLORSET_13_VEC', 'COLORSET_14_VEC', 'COLORSET_15_VEC', 'COLORSET_16_VEC', 'COLORSET_17_VEC', 'COLORSET_18_VEC', 'COLORSET_19_VEC', 'COLORSET_20_VEC', 'COLLECTION_COLOR_01', 'COLLECTION_COLOR_02', 'COLLECTION_COLOR_03', 'COLLECTION_COLOR_04', 'COLLECTION_COLOR_05', 'COLLECTION_COLOR_06', 'COLLECTION_COLOR_07', 'COLLECTION_COLOR_08', 'SEQUENCE_COLOR_01', 'SEQUENCE_COLOR_02', 'SEQUENCE_COLOR_03', 'SEQUENCE_COLOR_04', 'SEQUENCE_COLOR_05', 'SEQUENCE_COLOR_06', 'SEQUENCE_COLOR_07', 'SEQUENCE_COLOR_08', 'SEQUENCE_COLOR_09', 'LIBRARY_DATA_INDIRECT', 'LIBRARY_DATA_OVERRIDE_NONEDITABLE', 'EVENT_A', 'EVENT_B', 'EVENT_C', 'EVENT_D', 'EVENT_E', 'EVENT_F', 'EVENT_G', 'EVENT_H', 'EVENT_I', 'EVENT_J', 'EVENT_K', 'EVENT_L', 'EVENT_M', 'EVENT_N', 'EVENT_O', 'EVENT_P', 'EVENT_Q', 'EVENT_R', 'EVENT_S', 'EVENT_T', 'EVENT_U', 'EVENT_V', 'EVENT_W', 'EVENT_X', 'EVENT_Y', 'EVENT_Z', 'EVENT_SHIFT', 'EVENT_CTRL', 'EVENT_ALT', 'EVENT_OS', 'EVENT_F1', 'EVENT_F2', 'EVENT_F3', 'EVENT_F4', 'EVENT_F5', 'EVENT_F6', 'EVENT_F7', 'EVENT_F8', 'EVENT_F9', 'EVENT_F10', 'EVENT_F11', 'EVENT_F12', 'EVENT_ESC', 'EVENT_TAB', 'EVENT_PAGEUP', 'EVENT_PAGEDOWN', 'EVENT_RETURN', 'EVENT_SPACEKEY')
- Assistant
O erro que você está recebendo:
TypeError: UILayout.prop(): error with keyword argument "icon" - enum "FORCE_GRAVITY" not found in ('NONE', 'QUESTION', 'ERROR', ...indica que o ícone
"FORCE_GRAVITY"não existe na lista de ícones do Blender.
Como corrigir:
- Use um ícone válido e disponível no Blender. Por exemplo, para representar gravidade, um ícone comum usado é
'FORCE_FORCE'ou'FORCE'. - Outra opção é usar ícones relacionados a força ou física que estão na lista oficial.
No seu código, vá para esta parte:
box.prop(scene, "simulation_gravity", text="Gravity", icon='FORCE_GRAVITY')e substitua o
'FORCE_GRAVITY'por um dos ícones válidos. Por exemplo:box.prop(scene, "simulation_gravity", text="Gravity", icon='FORCE_FORCE')ou
box.prop(scene, "simulation_gravity", text="Gravity", icon='FORCE')
Sugestões comuns de ícones para física/simulação que funcionam:
'PHYSICS''FORCE_FORCE''FORCE_WIND''FORCE_TURBULENCE''FORCE_MAGNETIC'
Exemplo corrigido do trecho do seu painel:
box = layout.box() box.label(text="Simulation Controls", icon='PHYSICS') box.prop(scene, "simulation_gravity", text="Gravity", icon='FORCE_FORCE') box.prop(scene, "simulation_speed", text="Speed", icon='TIME')
Extras (se precisar verificar outros ícones disponíveis)
- Você pode ver a lista completa de ícones válidos dentro do Blender pelo Python Console rodando:
for icon in dir(bpy.types.UILayout.bl_rna.functions['prop'].parameters['icon'].enum_items): print(icon)Ou melhor, utilize addons disponíveis que listam ícones, ou navegue na documentação/upstream do Blender.
Resumo rápido:
- Remova o ícone "FORCE_GRAVITY" porque não existe.
- Substitua por algo como
'FORCE_FORCE'ou'PHYSICS'. - Teste o addon novamente.
Se quiser eu posso ajudar a ajustar no código onde quer que tenha o problema. Quer?
- Use um ícone válido e disponível no Blender. Por exemplo, para representar gravidade, um ícone comum usado é
- User
faça um prompt em ingles para a ai fazer estas correções
- Assistant
Sure! Here's a clear and concise prompt in English you can use to ask an AI to fix the icon error in your Blender addon code:
Prompt:
I have a Blender addon script with a UI panel that uses the
UILayout.prop()function to display properties with icons. However, I get the following error:TypeError: UILayout.prop(): error with keyword argument "icon" - enum "FORCE_GRAVITY" not found ...It seems that the icon
"FORCE_GRAVITY"is not a valid icon in Blender.Please help me:
- Identify where the invalid icon
"FORCE_GRAVITY"is used in the code. - Replace it with a valid Blender icon for representing gravity or physics.
- Suggest alternative icons that fit a physics or force context.
- Ensure the code runs without icon-related errors in Blender 2.8+.
Here is the relevant snippet from the panel code:
box.prop(scene, "simulation_gravity", text="Gravity", icon='FORCE_GRAVITY')Please fix this part and provide a corrected example.
If you want, you can also ask for a general check of the addon UI icons to make sure all are valid.
Let me know if you want me to help fix the entire panel code!
- Identify where the invalid icon
- User
peça para a ai adicionar todas as correções ao addon
- Assistant
Certainly! Here's a comprehensive prompt you can use to ask an AI to apply all necessary corrections and improvements to your Blender addon code, including fixing the icon error, proper handling of twists, gravity setting, simulation reset improvements, naming, and more:
Prompt:
I have a Blender addon script for simulating a rolling ball on predefined rail tracks using rigid body physics. I want you to review my entire addon code and apply all necessary corrections and improvements to ensure:
- No syntax errors or issues with string/quote usage.
- Correct progressive application of twist transformations in rail creation functions (
create_twist,create_helical_twist), so the twist smoothly varies along the curve. - Proper setting of simulation gravity using
scene.rigidbody_world.gravity = (0, 0, gravity)instead of incorrecteffector_weights. - Improved simulation reset that clears rigid body caches properly and resets object positions safely.
- Avoid duplicate or redundant renaming of rails or balls; provide unique naming even if objects are deleted.
- Fix UI panel icon errors: replace invalid icons like
'FORCE_GRAVITY'with valid Blender icons such as'FORCE_FORCE'or'PHYSICS'. - Ensure rigid body setup adds correct collision shapes and respects context and modes appropriately.
- Keep the code compatible with Blender 2.8 and newer.
- Make the code clean, well-structured, and fully functional, preserving all original features.
Please take the entire addon code as input, fix all the above points, and return the full corrected and improved addon Python script, ready to be used without errors.
If helpful, also add suggestions to improve user experience or flexibility, like exposing rail parameters to the UI, but keep it optional.
Thank you!
- User
verifique este , se foi corrigido: bl_info = { "name": "Rolling Ball Simulation Addon", "blender": (2, 80, 0), "category": "Physics", }
import bpy import math from bpy.props import EnumProperty, FloatProperty, BoolProperty, IntProperty, StringProperty import mathutils
Predefined rail tracks
RAIL_TRACKS = [ ("SPIRAL", "Spiral", "A spiral track"), ("LOOP", "Loop", "A loop track"), ("DROP", "Drop", "A drop track"), ("CORKSCREW", "Corkscrew", "A corkscrew track"), ("BANKED_TURN", "Banked Turn", "A banked turn track"), ("HILL", "Hill", "A hill track"), ("TWIST", "Twist", "A twist track"), ("HELIX", "Helix", "A helix track"), ("SWITCHBACK", "Switchback", "A switchback track"), ("MULTI_LOOP", "Multi-Loop", "A multi-loop track"), ("CUBIC_SPIRAL", "Cubic Spiral", "A cubic spiral track"), ("SINE_WAVE", "Sine Wave", "A sine wave track"), ("PARABOLA", "Parabola", "A parabolic track"), ("ARC", "Arc", "An arc track"), ("HELICAL_TWIST", "Helical Twist", "A helical twist track"), ("SLOPE", "Slope", "A slope track"), ("HELICAL_DROP", "Helical Drop", "A helical drop track"), ("TOWER_OF_TERROR", "Tower of Terror", "A tower of terror track"), ("VERTICAL_LOOP", "Vertical Loop", "A vertical loop track"), ("CIRCLE", "Circle", "A circular track"), ]
def create_spiral(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="SpiralCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SpiralRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_loop(radius=1, height=2): curve_data = bpy.data.curves.new(name="LoopCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("LoopRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_drop(radius=1, height=5): curve_data = bpy.data.curves.new(name="DropCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * math.cos(2 * math.pi * t) y = radius * math.sin(2 * math.pi * t) z = height * (1 - t) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("DropRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_corkscrew(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="CorkscrewCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("CorkscrewRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_banked_turn(radius=1, height=2, angle=45): curve_data = bpy.data.curves.new(name="BankedTurnCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' # Apply banking transformation mat = mathutils.Matrix.Rotation(math.radians(angle), 4, 'Z') for point in points: point.co = mat @ mathutils.Vector(point.co) point.handle_left = mat @ mathutils.Vector(point.handle_left) point.handle_right = mat @ mathutils.Vector(point.handle_right) obj = bpy.data.objects.new("BankedTurnRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_hill(radius=1, height=5): curve_data = bpy.data.curves.new(name="HillCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * (1 - (t - 0.5) ** 2) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("HillRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_twist(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="TwistCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' # Apply twist transformation for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t mat = mathutils.Matrix.Rotation(math.radians(angle), 4, 'Z') points[i].co = mat @ mathutils.Vector(points[i].co) points[i].handle_left = mat @ mathutils.Vector(points[i].handle_left) points[i].handle_right = mat @ mathutils.Vector(points[i].handle_right) obj = bpy.data.objects.new("TwistRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_helix(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="HelixCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("HelixRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_switchback(radius=1, height=5): curve_data = bpy.data.curves.new(name="SwitchbackCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) if t < 0.5: angle = 2 * math.pi * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) else: angle = 2 * math.pi * (1 - t) z = height * (1 - t) x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SwitchbackRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_multi_loop(radius=1, height=5, loops=3): curve_data = bpy.data.curves.new(name="MultiLoopCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 100 * loops points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("MultiLoopRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_cubic_spiral(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="CubicSpiralCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t ** 3 x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("CubicSpiralRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_sine_wave(radius=1, height=5, waves=2): curve_data = bpy.data.curves.new(name="SineWaveCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * math.sin(2 * math.pi * waves * t) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SineWaveRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_parabola(radius=1, height=5): curve_data = bpy.data.curves.new(name="ParabolaCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * (t - 0.5) ** 2 points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("ParabolaRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_arc(radius=1, height=5): curve_data = bpy.data.curves.new(name="ArcCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * t points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("ArcRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_helical_twist(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="HelicalTwistCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' # Apply twist transformation for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t mat = mathutils.Matrix.Rotation(math.radians(angle), 4, 'Z') points[i].co = mat @ mathutils.Vector(points[i].co) points[i].handle_left = mat @ mathutils.Vector(points[i].handle_left) points[i].handle_right = mat @ mathutils.Vector(points[i].handle_right) obj = bpy.data.objects.new("HelicalTwistRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_slope(radius=1, height=5): curve_data = bpy.data.curves.new(name="SlopeCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * t points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SlopeRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_helical_drop(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="HelicalDropCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * (1 - t) x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("HelicalDropRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_tower_of_terror(radius=1, height=5): curve_data = bpy.data.curves.new(name="TowerOfTerrorCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t z = height * (1 - t) x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("TowerOfTerrorRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_vertical_loop(radius=1, height=5): curve_data = bpy.data.curves.new(name="VerticalLoopCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("VerticalLoopRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_circle(radius=1): curve_data = bpy.data.curves.new(name="CircleCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = 0 points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("CircleRail", curve_data) bpy.context.collection.objects.link(obj) return objdef add_rail(track_type): if track_type == 'SPIRAL': rail = create_spiral() elif track_type == 'LOOP': rail = create_loop() elif track_type == 'DROP': rail = create_drop() elif track_type == 'CORKSCREW': rail = create_corkscrew() elif track_type == 'BANKED_TURN': rail = create_banked_turn() elif track_type == 'HILL': rail = create_hill() elif track_type == 'TWIST': rail = create_twist() elif track_type == 'HELIX': rail = create_helix() elif track_type == 'SWITCHBACK': rail = create_switchback() elif track_type == 'MULTI_LOOP': rail = create_multi_loop() elif track_type == 'CUBIC_SPIRAL': rail = create_cubic_spiral() elif track_type == 'SINE_WAVE': rail = create_sine_wave() elif track_type == 'PARABOLA': rail = create_parabola() elif track_type == 'ARC': rail = create_arc() elif track_type == 'HELICAL_TWIST': rail = create_helical_twist() elif track_type == 'SLOPE': rail = create_slope() elif track_type == 'HELICAL_DROP': rail = create_helical_drop() elif track_type == 'TOWER_OF_TERROR': rail = create_tower_of_terror() elif track_type == 'VERTICAL_LOOP': rail = create_vertical_loop() elif track_type == 'CIRCLE': rail = create_circle() else: return None
if rail: unique_name = f"Rail_{track_type}_{len([obj for obj in bpy.data.objects if obj.name.startswith(f"Rail_{track_type}_")]) + 1}" rail.name = unique_name add_rigid_body_to_object(rail, type='PASSIVE') return raildef add_ball(location): bpy.ops.mesh.primitive_uv_sphere_add(radius=bpy.context.scene.ball_radius, location=location) ball = bpy.context.object unique_name = f"RollingBall_{len([obj for obj in bpy.data.objects if obj.name.startswith('RollingBall_')]) + 1}" ball.name = unique_name add_rigid_body_to_object(ball, type='ACTIVE') return ball
def add_rigid_body_to_object(obj, type='PASSIVE'): # Ensure we are in Object Mode if bpy.context.mode != 'OBJECT': bpy.ops.object.mode_set(mode='OBJECT')
# Deselect all objects bpy.ops.object.select_all(action='DESELECT') # Select and make the object active obj.select_set(True) bpy.context.view_layer.objects.active = obj # Add rigid body physics bpy.ops.rigidbody.object_add(type=type) if type == 'PASSIVE': obj.rigid_body.collision_shape = 'MESH' elif type == 'ACTIVE': obj.rigid_body.collision_shape = 'SPHERE' obj.rigid_body.friction = bpy.context.scene.ball_friction obj.rigid_body.restitution = bpy.context.scene.ball_restitution obj.rigid_body.linear_damping = bpy.context.scene.ball_linear_damping obj.rigid_body.angular_damping = bpy.context.scene.ball_angular_damping obj.rigid_body.mass = bpy.context.scene.ball_massdef set_simulation_gravity(gravity): scene = bpy.context.scene if scene.rigidbody_world: scene.rigidbody_world.point_cache.frame_start = 1 scene.rigidbody_world.point_cache.frame_end = 250 scene.rigidbody_world.time_scale = bpy.context.scene.simulation_speed scene.rigidbody_world.gravity = (0, 0, gravity)
def start_simulation(): scene = bpy.context.scene set_simulation_gravity(scene.simulation_gravity) bpy.ops.screen.animation_play()
def pause_simulation(): bpy.ops.screen.animation_cancel()
def reset_simulation(): scene = bpy.context.scene pause_simulation() bpy.ops.screen.frame_jump(end=False) for obj in bpy.data.objects: if obj.rigid_body: obj.rigid_body.kinematic = True obj.location = obj.rigid_body.world_center_of_mass obj.rotation_euler = (0, 0, 0) obj.keyframe_insert(data_path="location", frame=1) obj.keyframe_insert(data_path="rotation_euler", frame=1) obj.rigid_body.kinematic = False # Clear rigid body caches if scene.rigidbody_world: scene.rigidbody_world.point_cache.clear_cache()
class PHYSICS_PT_rolling_ball(bpy.types.Panel): bl_label = "Rolling Ball Simulation" bl_idname = "PHYSICS_PT_rolling_ball" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = 'Physics'
def draw(self, context): layout = self.layout scene = context.scene layout.prop(scene, "selected_track") layout.operator("physics.add_rail", text="Add Rail", icon='MOD_CURVE') layout.operator("physics.add_ball", text="Add Ball", icon='SPHERE') layout.separator() layout.operator("physics.start_simulation", text="Start Simulation", icon='PLAY') layout.operator("physics.pause_simulation", text="Pause Simulation", icon='PAUSE') layout.operator("physics.reset_simulation", text="Reset Simulation", icon='REW') layout.separator() box = layout.box() box.label(text="Simulation Controls", icon='PHYSICS') box.prop(scene, "simulation_gravity", text="Gravity", icon='FORCE_FORCE') box.prop(scene, "simulation_speed", text="Speed", icon='TIME') layout.separator() box = layout.box() box.label(text="Ball Parameters", icon='SPHERE') box.prop(scene, "ball_radius", text="Radius", icon='MESH_UVSPHERE') box.prop(scene, "ball_mass", text="Mass", icon='MOD_PHYSICS') box.prop(scene, "ball_friction", text="Friction", icon='MOD_SMOOTH') box.prop(scene, "ball_restitution", text="Restitution", icon='SNAP_INCREMENT') box.prop(scene, "ball_linear_damping", text="Linear Damping", icon='MOD_PHYSICS') box.prop(scene, "ball_angular_damping", text="Angular Damping", icon='MOD_PHYSICS')class PHYSICS_OT_add_rail(bpy.types.Operator): bl_idname = "physics.add_rail" bl_label = "Add Rail" bl_description = "Add a predefined rail track" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): scene = context.scene rail = add_rail(scene.selected_track) return {'FINISHED'}class PHYSICS_OT_add_ball(bpy.types.Operator): bl_idname = "physics.add_ball" bl_label = "Add Ball" bl_description = "Add a ball at the start of the selected rail" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): scene = context.scene rail = bpy.data.objects.get(f"Rail_{scene.selected_track}_1") if rail and rail.data.splines: start_point = rail.matrix_world @ rail.data.splines[0].bezier_points[0].co ball_offset = mathutils.Vector((0, 0, bpy.context.scene.ball_radius * 1.1)) ball_location = start_point + ball_offset ball = add_ball(ball_location) return {'FINISHED'}class PHYSICS_OT_start_simulation(bpy.types.Operator): bl_idname = "physics.start_simulation" bl_label = "Start Simulation" bl_description = "Start the physics simulation" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): start_simulation() return {'FINISHED'}class PHYSICS_OT_pause_simulation(bpy.types.Operator): bl_idname = "physics.pause_simulation" bl_label = "Pause Simulation" bl_description = "Pause the physics simulation" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): pause_simulation() return {'FINISHED'}class PHYSICS_OT_reset_simulation(bpy.types.Operator): bl_idname = "physics.reset_simulation" bl_label = "Reset Simulation" bl_description = "Reset the physics simulation" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): reset_simulation() return {'FINISHED'}def register(): bpy.utils.register_class(PHYSICS_PT_rolling_ball) bpy.utils.register_class(PHYSICS_OT_add_rail) bpy.utils.register_class(PHYSICS_OT_add_ball) bpy.utils.register_class(PHYSICS_OT_start_simulation) bpy.utils.register_class(PHYSICS_OT_pause_simulation) bpy.utils.register_class(PHYSICS_OT_reset_simulation)
bpy.types.Scene.selected_track = EnumProperty( name="Selected Track", description="Choose a rail track", items=RAIL_TRACKS, default='SPIRAL', ) bpy.types.Scene.ball_radius = FloatProperty( name="Ball Radius", description="Radius of the ball", default=0.5, min=0.1, max=1.0, ) bpy.types.Scene.ball_mass = FloatProperty( name="Ball Mass", description="Mass of the ball", default=1.0, min=0.1, max=10.0, ) bpy.types.Scene.ball_friction = FloatProperty( name="Ball Friction", description="Friction of the ball", default=0.5, min=0.0, max=1.0, ) bpy.types.Scene.ball_restitution = FloatProperty( name="Ball Restitution", description="Restitution of the ball", default=0.0, min=0.0, max=1.0, ) bpy.types.Scene.ball_linear_damping = FloatProperty( name="Linear Damping", description="Linear damping of the ball", default=0.1, min=0.0, max=1.0, ) bpy.types.Scene.ball_angular_damping = FloatProperty( name="Angular Damping", description="Angular damping of the ball", default=0.1, min=0.0, max=1.0, ) bpy.types.Scene.simulation_gravity = FloatProperty( name="Simulation Gravity", description="Simulation gravity", default=-9.81, min=-10.0, max=10.0, ) bpy.types.Scene.simulation_speed = FloatProperty( name="Simulation Speed", description="Simulation speed multiplier", default=1.0, min=0.1, max=10.0, )def unregister(): bpy.utils.unregister_class(PHYSICS_PT_rolling_ball) bpy.utils.unregister_class(PHYSICS_OT_add_rail) bpy.utils.unregister_class(PHYSICS_OT_add_ball) bpy.utils.unregister_class(PHYSICS_OT_start_simulation) bpy.utils.unregister_class(PHYSICS_OT_pause_simulation) bpy.utils.unregister_class(PHYSICS_OT_reset_simulation)
del bpy.types.Scene.selected_track del bpy.types.Scene.ball_radius del bpy.types.Scene.ball_mass del bpy.types.Scene.ball_friction del bpy.types.Scene.ball_restitution del bpy.types.Scene.ball_linear_damping del bpy.types.Scene.ball_angular_damping del bpy.types.Scene.simulation_gravity del bpy.types.Scene.simulation_speedif name == "main": register()
- Assistant
Seu código está muito bem corrigido e organizado; as principais melhorias que sugeri antes foram aplicadas. Vou destacar os pontos importantes e algumas observações finais para garantir que funcione corretamente:
Pontos revisados e corrigidos:
-
Nomenclatura única para trilhos e bolas, usando contagem mais correta para evitar nomes duplicados, por exemplo:
unique_name = f"Rail_{track_type}_{len([...]) + 1}" -
Twist gradual aplicado corretamente no
create_twistecreate_helical_twist, aplicando transformação dentro do loop de pontos. -
Gravidade configurada usando:
scene.rigidbody_world.gravity = (0, 0, gravity) -
Ícones no painel corrigidos para usar ícones válidos como
'FORCE_FORCE'em vez de'FORCE_GRAVITY'. -
Função de reset aprimorada:
- Pausa a simulação,
- Reseta o frame,
- Define objetos como cinemáticos temporariamente,
- Reposiciona objetos,
- Limpa cache via
scene.rigidbody_world.point_cache.clear_cache().
-
Contexto
OBJECTgarantido antes de adicionar corpos rígidos. -
Operadores e painel bem configurados com opções de registro e undo.
Recomendações adicionais (opcional):
-
Resetar posições:
A linhaobj.location = obj.rigid_body.world_center_of_masspode não ser 100% confiável para resetar posição inicial da simulação (depende do estado do corpo rígido). Se possível, armazene posição inicial ao criar objetos (por exemplo, em uma propriedade custom) e retorne a ela no reset. -
Limpar cache com bpy.ops.ptcache.free_bake_all() pode garantir melhor limpeza da simulação, mas o uso direto de APIs também é correto.
-
Configurações do painel:
Se desejar, exponha parâmetros para criação das curvas (radius, height, turns, etc.) em propriedades da cena para personalização. -
Gerenciamento de coleções:
Para controle mais avançado, pode organizar trilhos e bolas em coleções separadas.
Teste sugerido:
- Crie trilho, verifique se o objeto é nomeado corretamente e aparece na viewport.
- Adicione a bola, verifique se posiciona na posição inicial correta (considerando offset z pelo raio).
- Inicie e pause a simulação, verifique movimentação correta da bola.
- Resete e veja se a bola e trilho voltam à posição inicial.
- Ajuste parâmetros no painel e veja o efeito.
Conclusão
O seu addon parece pronto para uso, corrigido e estruturado para Blender 2.80+. Se não houver erros de runtime no Blender, deve funcionar conforme esperado.
Se precisar, posso ajudar a criar uma versão com personalização dos parâmetros das pistas ou melhorar o reset para maior confiabilidade.
Se quiser posso revisar versões específicas, adicionar sugestões visuais, exemplos ou tutoriais também.
Bons projetos!
-
- User
Python: File "\Text", line 627 unique_name = f"Rail_{track_type}{len([obj for obj in bpy.data.objects if obj.name.startswith(f"Rail{track_type}_")]) + 1}" ^^^^^ SyntaxError: f-string: unmatched '('
- Assistant
O erro ocorre porque você está usando f-string aninhada sem escapar corretamente as aspas internas, causando conflito de parênteses e aspas. Exemplo da linha problemática:
unique_name = f"Rail_{track_type}_{len([obj for obj in bpy.data.objects if obj.name.startswith(f"Rail_{track_type}_")]) + 1}"Aqui o
f"Rail_{track_type}_"está dentro de outra f-string delimitada por aspas duplas, causando confusão.
Como corrigir
Opção 1: Use aspas simples dentro da inner f-string para evitar conflito
unique_name = f"Rail_{track_type}_{len([obj for obj in bpy.data.objects if obj.name.startswith(f'Rail_{track_type}_')]) + 1}"Opção 2: Use variável temporária para a string interna para maior clareza:
prefix = f"Rail_{track_type}_" count = len([obj for obj in bpy.data.objects if obj.name.startswith(prefix)]) + 1 unique_name = f"{prefix}{count}"
Recomendação
Use a Opção 2 para melhor legibilidade e evitar erros de sintaxe:
def add_rail(track_type): if track_type == 'SPIRAL': rail = create_spiral() # ... outros casos ... else: return None if rail: prefix = f"Rail_{track_type}_" count = len([obj for obj in bpy.data.objects if obj.name.startswith(prefix)]) + 1 unique_name = f"{prefix}{count}" rail.name = unique_name add_rigid_body_to_object(rail, type='PASSIVE') return rail
Mesma correção aplique para nomeação da bola (se usar f-string aninhada).
Se preferir, posso corrigir o trecho para você — basta pedir!
- User
faça um prompt em ingles para a ai fazer estas correções
- Assistant
Sure! Here's a clear and detailed prompt in English you can use to ask an AI to fix the f-string syntax error and improve the naming logic in your Blender addon code:
Prompt:
I have a Blender addon script where I use nested f-strings to generate unique object names based on existing objects in the scene, like this:
unique_name = f"Rail_{track_type}_{len([obj for obj in bpy.data.objects if obj.name.startswith(f"Rail_{track_type}_")]) + 1}"But this causes a Python syntax error:
SyntaxError: f-string: unmatched '('Please help me fix this error by:
- Correctly handling the nested f-strings to avoid syntax issues with quotes and parentheses.
- Improving readability and maintainability by suggesting the use of intermediate variables instead of nested f-strings.
- Applying this fix both for naming rails and naming balls in the addon.
- Making sure the unique naming logic works correctly without duplications.
Please provide the corrected and improved code snippets for these parts and explain the changes.
Thank you!
- User
peça para adicionar todas as correçoes no addon
- Assistant
Certainly! Here's a comprehensive prompt you can use to ask an AI to apply all necessary corrections (including the f-string fix, icon corrections, twist fixes, gravity setting, reset improvements, unique naming, and more) to your Blender addon code:
Prompt:
I have a Blender addon script for simulating a rolling ball on predefined rail tracks. The addon has several issues including:
- Syntax errors caused by nested f-strings with conflicting quotes in unique naming logic.
- Invalid icon names in the UI, e.g.,
'FORCE_GRAVITY'used where no such icon exists. - Improper setting of simulation gravity using
effector_weightsinstead of the correctscene.rigidbody_world.gravity. - Twist transformations in rail creation functions (
create_twist,create_helical_twist) are not applied progressively along the curve points. - The simulation reset does not properly clear rigid body caches or reliably reset object positions.
- Possible duplicate or inconsistent naming of objects.
- General improvements with context handling for rigid bodies and object modes.
Please take the entire addon code as base, apply all these corrections and improvements thoroughly, including:
- Fixing f-string syntax errors by avoiding nested f-strings or using intermediate variables.
- Replacing invalid icons with valid ones (e.g.,
'FORCE_FORCE'or'PHYSICS'). - Setting gravity correctly via
scene.rigidbody_world.gravity. - Applying twist transformations smoothly along the curve points with rotation varying per point.
- Improving simulation reset to clear caches and reset object transforms safely.
- Ensuring unique naming of rails and balls without duplication issues.
- Maintaining Blender 2.8+ compatibility.
- General code cleanup and better user experience in the UI panel.
Return the full corrected and improved addon script ready to use without errors.
Thank you!
- User
bl_info = { "name": "Rolling Ball Simulation Addon", "blender": (2, 80, 0), "category": "Physics", }
import bpy import math from bpy.props import EnumProperty, FloatProperty, BoolProperty, IntProperty, StringProperty import mathutils
Predefined rail tracks
RAIL_TRACKS = [ ("SPIRAL", "Spiral", "A spiral track"), ("LOOP", "Loop", "A loop track"), ("DROP", "Drop", "A drop track"), ("CORKSCREW", "Corkscrew", "A corkscrew track"), ("BANKED_TURN", "Banked Turn", "A banked turn track"), ("HILL", "Hill", "A hill track"), ("TWIST", "Twist", "A twist track"), ("HELIX", "Helix", "A helix track"), ("SWITCHBACK", "Switchback", "A switchback track"), ("MULTI_LOOP", "Multi-Loop", "A multi-loop track"), ("CUBIC_SPIRAL", "Cubic Spiral", "A cubic spiral track"), ("SINE_WAVE", "Sine Wave", "A sine wave track"), ("PARABOLA", "Parabola", "A parabolic track"), ("ARC", "Arc", "An arc track"), ("HELICAL_TWIST", "Helical Twist", "A helical twist track"), ("SLOPE", "Slope", "A slope track"), ("HELICAL_DROP", "Helical Drop", "A helical drop track"), ("TOWER_OF_TERROR", "Tower of Terror", "A tower of terror track"), ("VERTICAL_LOOP", "Vertical Loop", "A vertical loop track"), ("CIRCLE", "Circle", "A circular track"), ]
def create_spiral(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="SpiralCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SpiralRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_loop(radius=1, height=2): curve_data = bpy.data.curves.new(name="LoopCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("LoopRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_drop(radius=1, height=5): curve_data = bpy.data.curves.new(name="DropCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * math.cos(2 * math.pi * t) y = radius * math.sin(2 * math.pi * t) z = height * (1 - t) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("DropRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_corkscrew(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="CorkscrewCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("CorkscrewRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_banked_turn(radius=1, height=2, angle=45): curve_data = bpy.data.curves.new(name="BankedTurnCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' # Apply banking transformation mat = mathutils.Matrix.Rotation(math.radians(angle), 4, 'Z') for point in points: point.co = mat @ mathutils.Vector(point.co) point.handle_left = mat @ mathutils.Vector(point.handle_left) point.handle_right = mat @ mathutils.Vector(point.handle_right) obj = bpy.data.objects.new("BankedTurnRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_hill(radius=1, height=5): curve_data = bpy.data.curves.new(name="HillCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * (1 - (t - 0.5) ** 2) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("HillRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_twist(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="TwistCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' # Apply twist transformation for i in range(num_points): t = i / (num_points - 1) twist_angle = 360 * turns * t mat = mathutils.Matrix.Rotation(math.radians(twist_angle), 4, 'Z') points[i].co = mat @ mathutils.Vector(points[i].co) points[i].handle_left = mat @ mathutils.Vector(points[i].handle_left) points[i].handle_right = mat @ mathutils.Vector(points[i].handle_right) obj = bpy.data.objects.new("TwistRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_helix(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="HelixCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("HelixRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_switchback(radius=1, height=5): curve_data = bpy.data.curves.new(name="SwitchbackCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) if t < 0.5: angle = 2 * math.pi * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) else: angle = 2 * math.pi * (1 - t) z = height * (1 - t) x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SwitchbackRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_multi_loop(radius=1, height=5, loops=3): curve_data = bpy.data.curves.new(name="MultiLoopCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 100 * loops points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("MultiLoopRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_cubic_spiral(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="CubicSpiralCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t ** 3 x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("CubicSpiralRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_sine_wave(radius=1, height=5, waves=2): curve_data = bpy.data.curves.new(name="SineWaveCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * math.sin(2 * math.pi * waves * t) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SineWaveRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_parabola(radius=1, height=5): curve_data = bpy.data.curves.new(name="ParabolaCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * (t - 0.5) ** 2 points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("ParabolaRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_arc(radius=1, height=5): curve_data = bpy.data.curves.new(name="ArcCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * t points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("ArcRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_helical_twist(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="HelicalTwistCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * t x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' # Apply twist transformation for i in range(num_points): t = i / (num_points - 1) twist_angle = 360 * turns * t mat = mathutils.Matrix.Rotation(math.radians(twist_angle), 4, 'Z') points[i].co = mat @ mathutils.Vector(points[i].co) points[i].handle_left = mat @ mathutils.Vector(points[i].handle_left) points[i].handle_right = mat @ mathutils.Vector(points[i].handle_right) obj = bpy.data.objects.new("HelicalTwistRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_slope(radius=1, height=5): curve_data = bpy.data.curves.new(name="SlopeCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) x = radius * t y = 0 z = height * t points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("SlopeRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_helical_drop(radius=1, height=5, turns=2): curve_data = bpy.data.curves.new(name="HelicalDropCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * turns * t z = height * (1 - t) x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("HelicalDropRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_tower_of_terror(radius=1, height=5): curve_data = bpy.data.curves.new(name="TowerOfTerrorCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = False num_points = 100 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t z = height * (1 - t) x = radius * math.cos(angle) y = radius * math.sin(angle) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("TowerOfTerrorRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_vertical_loop(radius=1, height=5): curve_data = bpy.data.curves.new(name="VerticalLoopCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = height * (0.5 + 0.5 * math.cos(2 * math.pi * t)) points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("VerticalLoopRail", curve_data) bpy.context.collection.objects.link(obj) return objdef create_circle(radius=1): curve_data = bpy.data.curves.new(name="CircleCurve", type='CURVE') curve_data.dimensions = '3D' curve_data.bevel_depth = 0.1 curve_data.bevel_resolution = 4
spline = curve_data.splines.new('BEZIER') spline.use_cyclic_u = True num_points = 50 points = spline.bezier_points points.add(num_points - 1) for i in range(num_points): t = i / (num_points - 1) angle = 2 * math.pi * t x = radius * math.cos(angle) y = radius * math.sin(angle) z = 0 points[i].co = (x, y, z) points[i].handle_left_type = 'AUTO' points[i].handle_right_type = 'AUTO' obj = bpy.data.objects.new("CircleRail", curve_data) bpy.context.collection.objects.link(obj) return objdef add_rail(track_type): base_name = f"Rail_{track_type}_" existing_objects = [obj for obj in bpy.data.objects if obj.name.startswith(base_name)] unique_index = len(existing_objects) + 1 unique_name = f"{base_name}{unique_index}"
if track_type == 'SPIRAL': rail = create_spiral() elif track_type == 'LOOP': rail = create_loop() elif track_type == 'DROP': rail = create_drop() elif track_type == 'CORKSCREW': rail = create_corkscrew() elif track_type == 'BANKED_TURN': rail = create_banked_turn() elif track_type == 'HILL': rail = create_hill() elif track_type == 'TWIST': rail = create_twist() elif track_type == 'HELIX': rail = create_helix() elif track_type == 'SWITCHBACK': rail = create_switchback() elif track_type == 'MULTI_LOOP': rail = create_multi_loop() elif track_type == 'CUBIC_SPIRAL': rail = create_cubic_spiral() elif track_type == 'SINE_WAVE': rail = create_sine_wave() elif track_type == 'PARABOLA': rail = create_parabola() elif track_type == 'ARC': rail = create_arc() elif track_type == 'HELICAL_TWIST': rail = create_helical_twist() elif track_type == 'SLOPE': rail = create_slope() elif track_type == 'HELICAL_DROP': rail = create_helical_drop() elif track_type == 'TOWER_OF_TERROR': rail = create_tower_of_terror() elif track_type == 'VERTICAL_LOOP': rail = create_vertical_loop() elif track_type == 'CIRCLE': rail = create_circle() else: return None if rail: rail.name = unique_name add_rigid_body_to_object(rail, type='PASSIVE') return raildef add_ball(location): base_name = "RollingBall_" existing_objects = [obj for obj in bpy.data.objects if obj.name.startswith(base_name)] unique_index = len(existing_objects) + 1 unique_name = f"{base_name}{unique_index}"
bpy.ops.mesh.primitive_uv_sphere_add(radius=bpy.context.scene.ball_radius, location=location) ball = bpy.context.object ball.name = unique_name add_rigid_body_to_object(ball, type='ACTIVE') return balldef add_rigid_body_to_object(obj, type='PASSIVE'): # Ensure we are in Object Mode if bpy.context.mode != 'OBJECT': bpy.ops.object.mode_set(mode='OBJECT')
# Deselect all objects bpy.ops.object.select_all(action='DESELECT') # Select and make the object active obj.select_set(True) bpy.context.view_layer.objects.active = obj # Add rigid body physics bpy.ops.rigidbody.object_add(type=type) if type == 'PASSIVE': obj.rigid_body.collision_shape = 'MESH' elif type == 'ACTIVE': obj.rigid_body.collision_shape = 'SPHERE' obj.rigid_body.friction = bpy.context.scene.ball_friction obj.rigid_body.restitution = bpy.context.scene.ball_restitution obj.rigid_body.linear_damping = bpy.context.scene.ball_linear_damping obj.rigid_body.angular_damping = bpy.context.scene.ball_angular_damping obj.rigid_body.mass = bpy.context.scene.ball_massdef set_simulation_gravity(gravity): scene = bpy.context.scene if scene.rigidbody_world: scene.rigidbody_world.point_cache.frame_start = 1 scene.rigidbody_world.point_cache.frame_end = 250 scene.rigidbody_world.time_scale = bpy.context.scene.simulation_speed scene.rigidbody_world.gravity = (0, 0, gravity)
def start_simulation(): scene = bpy.context.scene set_simulation_gravity(scene.simulation_gravity) bpy.ops.screen.animation_play()
def pause_simulation(): bpy.ops.screen.animation_cancel()
def reset_simulation(): scene = bpy.context.scene pause_simulation() bpy.ops.screen.frame_jump(end=False) for obj in bpy.data.objects: if obj.rigid_body: obj.rigid_body.kinematic = True obj.location = obj.rigid_body.world_center_of_mass obj.rotation_euler = (0, 0, 0) obj.keyframe_insert(data_path="location", frame=1) obj.keyframe_insert(data_path="rotation_euler", frame=1) obj.rigid_body.kinematic = False if scene.rigidbody_world: scene.rigidbody_world.point_cache.clear_cache()
class PHYSICS_PT_rolling_ball(bpy.types.Panel): bl_label = "Rolling Ball Simulation" bl_idname = "PHYSICS_PT_rolling_ball" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = 'Physics'
def draw(self, context): layout = self.layout scene = context.scene layout.prop(scene, "selected_track") layout.operator("physics.add_rail", text="Add Rail", icon='MOD_CURVE') layout.operator("physics.add_ball", text="Add Ball", icon='SPHERE') layout.separator() layout.operator("physics.start_simulation", text="Start Simulation", icon='PLAY') layout.operator("physics.pause_simulation", text="Pause Simulation", icon='PAUSE') layout.operator("physics.reset_simulation", text="Reset Simulation", icon='REW') layout.separator() box = layout.box() box.label(text="Simulation Controls", icon='PHYSICS') box.prop(scene, "simulation_gravity", text="Gravity", icon='PHYSICS') box.prop(scene, "simulation_speed", text="Speed", icon='TIME') layout.separator() box = layout.box() box.label(text="Ball Parameters", icon='SPHERE') box.prop(scene, "ball_radius", text="Radius", icon='MESH_UVSPHERE') box.prop(scene, "ball_mass", text="Mass", icon='MOD_PHYSICS') box.prop(scene, "ball_friction", text="Friction", icon='MOD_SMOOTH') box.prop(scene, "ball_restitution", text="Restitution", icon='SNAP_INCREMENT') box.prop(scene, "ball_linear_damping", text="Linear Damping", icon='MOD_PHYSICS') box.prop(scene, "ball_angular_damping", text="Angular Damping", icon='MOD_PHYSICS')class PHYSICS_OT_add_rail(bpy.types.Operator): bl_idname = "physics.add_rail" bl_label = "Add Rail" bl_description = "Add a predefined rail track" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): scene = context.scene rail = add_rail(scene.selected_track) return {'FINISHED'}class PHYSICS_OT_add_ball(bpy.types.Operator): bl_idname = "physics.add_ball" bl_label = "Add Ball" bl_description = "Add a ball at the start of the selected rail" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): scene = context.scene rail = bpy.data.objects.get(f"Rail_{scene.selected_track}_1") if rail and rail.data.splines: start_point = rail.matrix_world @ rail.data.splines[0].bezier_points[0].co ball_offset = mathutils.Vector((0, 0, bpy.context.scene.ball_radius * 1.1)) ball_location = start_point + ball_offset ball = add_ball(ball_location) return {'FINISHED'}class PHYSICS_OT_start_simulation(bpy.types.Operator): bl_idname = "physics.start_simulation" bl_label = "Start Simulation" bl_description = "Start the physics simulation" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): start_simulation() return {'FINISHED'}class PHYSICS_OT_pause_simulation(bpy.types.Operator): bl_idname = "physics.pause_simulation" bl_label = "Pause Simulation" bl_description = "Pause the physics simulation" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): pause_simulation() return {'FINISHED'}class PHYSICS_OT_reset_simulation(bpy.types.Operator): bl_idname = "physics.reset_simulation" bl_label = "Reset Simulation" bl_description = "Reset the physics simulation" bl_options = {'REGISTER', 'UNDO'}
def execute(self, context): reset_simulation() return {'FINISHED'}def register(): bpy.utils.register_class(PHYSICS_PT_rolling_ball) bpy.utils.register_class(PHYSICS_OT_add_rail) bpy.utils.register_class(PHYSICS_OT_add_ball) bpy.utils.register_class(PHYSICS_OT_start_simulation) bpy.utils.register_class(PHYSICS_OT_pause_simulation) bpy.utils.register_class(PHYSICS_OT_reset_simulation)
bpy.types.Scene.selected_track = EnumProperty( name="Selected Track", description="Choose a rail track", items=RAIL_TRACKS, default='SPIRAL', ) bpy.types.Scene.ball_radius = FloatProperty( name="Ball Radius", description="Radius of the ball", default=0.5, min=0.1, max=1.0, ) bpy.types.Scene.ball_mass = FloatProperty( name="Ball Mass", description="Mass of the ball", default=1.0, min=0.1, max=10.0, ) bpy.types.Scene.ball_friction = FloatProperty( name="Ball Friction", description="Friction of the ball", default=0.5, min=0.0, max=1.0, ) bpy.types.Scene.ball_restitution = FloatProperty( name="Ball Restitution", description="Restitution of the ball", default=0.0, min=0.0, max=1.0, ) bpy.types.Scene.ball_linear_damping = FloatProperty( name="Linear Damping", description="Linear damping of the ball", default=0.1, min=0.0, max=1.0, ) bpy.types.Scene.ball_angular_damping = FloatProperty( name="Angular Damping", description="Angular damping of the ball", default=0.1, min=0.0, max=1.0, ) bpy.types.Scene.simulation_gravity = FloatProperty( name="Simulation Gravity", description="Simulation gravity", default=-9.81, min=-10.0, max=10.0, ) bpy.types.Scene.simulation_speed = FloatProperty( name="Simulation Speed", description="Simulation speed multiplier", default=1.0, min=0.1, max=10.0, )def unregister(): bpy.utils.unregister_class(PHYSICS_PT_rolling_ball) bpy.utils.unregister_class(PHYSICS_OT_add_rail) bpy.utils.unregister_class(PHYSICS_OT_add_ball) bpy.utils.unregister_class(PHYSICS_OT_start_simulation) bpy.utils.unregister_class(PHYSICS_OT_pause_simulation) bpy.utils.unregister_class(PHYSICS_OT_reset_simulation)
del bpy.types.Scene.selected_track del bpy.types.Scene.ball_radius del bpy.types.Scene.ball_mass del bpy.types.Scene.ball_friction del bpy.types.Scene.ball_restitution del bpy.types.Scene.ball_linear_damping del bpy.types.Scene.ball_angular_damping del bpy.types.Scene.simulation_gravity del bpy.types.Scene.simif name == "main": register()
- Assistant
Your addon code looks well structured and the main corrections discussed earlier appear properly addressed, including:
- Proper progressive twist applied in
create_twistandcreate_helical_twist. - Unique naming of rails and balls without nested f-string issues.
- Correct use of icons in UI panel (
icon='PHYSICS'or'FORCE_FORCE'instead of invalid ones). - Setting gravity correctly via
scene.rigidbody_world.gravity = (0, 0, gravity). - Resetting simulation with cache cleared and objects reset.
- Proper context handling for rigid body setup.
One minor issue to fix:
At the end of your
unregister()function, the last line appears truncated:del bpy.types.Scene.simThis should be:
del bpy.types.Scene.simulation_speed
Recommendation
Replace the last lines of
unregister()with:def unregister(): bpy.utils.unregister_class(PHYSICS_PT_rolling_ball) bpy.utils.unregister_class(PHYSICS_OT_add_rail) bpy.utils.unregister_class(PHYSICS_OT_add_ball) bpy.utils.unregister_class(PHYSICS_OT_start_simulation) bpy.utils.unregister_class(PHYSICS_OT_pause_simulation) bpy.utils.unregister_class(PHYSICS_OT_reset_simulation) del bpy.types.Scene.selected_track del bpy.types.Scene.ball_radius del bpy.types.Scene.ball_mass del bpy.types.Scene.ball_friction del bpy.types.Scene.ball_restitution del bpy.types.Scene.ball_linear_damping del bpy.types.Scene.ball_angular_damping del bpy.types.Scene.simulation_gravity del bpy.types.Scene.simulation_speed
Final thoughts
- This correction aside, your code should work as expected on Blender 2.80+.
- Test it by installing as an addon in Blender and verify the rail creation, ball addition, simulation start/pause/reset, and UI controls.
- If you want to enhance user experience, you might consider adding tooltips, parameter controls for rails, or cache/bake control for physics.
If you want me to check or improve anything else in the addon, just ask!
- Proper progressive twist applied in
- User
oque
- Assistant
No seu código, a linha final do método
unregister()está incompleta e isso causa erro.
O que está escrito é:del bpy.types.Scene.simO correto é apagar a propriedade completa, que no caso é:
del bpy.types.Scene.simulation_speed
Por que isso importa?
- Se essa linha estiver incompleta, o Python gera erro de sintaxe ou runtime na hora de desregistrar o addon (ou quando você tentar desativá-lo).
- Isso pode impedir que o Blender remova as propriedades associadas à cena corretamente.
O que você deve fazer?
Substituir toda a parte
unregister()final por:def unregister(): bpy.utils.unregister_class(PHYSICS_PT_rolling_ball) bpy.utils.unregister_class(PHYSICS_OT_add_rail) bpy.utils.unregister_class(PHYSICS_OT_add_ball) bpy.utils.unregister_class(PHYSICS_OT_start_simulation) bpy.utils.unregister_class(PHYSICS_OT_pause_simulation) bpy.utils.unregister_class(PHYSICS_OT_reset_simulation) del bpy.types.Scene.selected_track del bpy.types.Scene.ball_radius del bpy.types.Scene.ball_mass del bpy.types.Scene.ball_friction del bpy.types.Scene.ball_restitution del bpy.types.Scene.ball_linear_damping del bpy.types.Scene.ball_angular_damping del bpy.types.Scene.simulation_gravity del bpy.types.Scene.simulation_speedAssim seu addon vai desregistrar todas as propriedades corretamente.
Em resumo
- A palavra
simsozinha parece ter sido cortada por acidente e tem que ser substituída pela palavra/variável completasimulation_speed. - Corrija isso e seu código deve rodar sem problemas.
Se precisar, posso ajudar a revisar todo o código ou responder outras dúvidas!