feat: 切换至滚动阻力运行模型并更新资产、编辑器与验证

- 物理规则:现行模型仅保留滚动阻力耗能与恢复系数碰撞,风力、空气阻力、静摩擦、动摩擦不再参与运行;确认三球质量 60/330/约890 kg 及水密度、流阻参数
- 定向加速改为真实顶面接触触发的一次性 +5 m/s 速度事件,模型新增渐进式 U 形导槽出口
- 更新球体、滑槽、水/冰/墙、球洞模型与 storybook 目录、物理、实体配置
- 工坊摆放、编辑器、运行适配与检查脚本同步;删除过时的 baseline 三组检查
- 新增谜题设计参考文档、关卡草稿与本轮实验产物
This commit is contained in:
Yanchen
2026-12-05 10:37:31 +08:00
parent d1141b04c7
commit bf6c355fa6
132 changed files with 13205 additions and 1838 deletions
+7 -23
View File
@@ -33,7 +33,7 @@
- Y 形在同一侧设置两个相邻、等高的入口,中心相距 1 m,各自连接一个单格直槽;公共出口与其中一路对齐,另一路以连续 S 形曲线并入,不要求对称。单件场景同时展示两个输入直槽和一个输出直槽,验证真实接缝。
- 编辑器按 Y 形四格占用进行选择、替换、旋转及重叠检查;数量配额计为一块。只有上方槽面参与路线连接。
目标洞口现由 Blender 制作并导出为 `goal_hole.glb`:入口与喉部净半径均为 0.32 m,深度 0.55 m,壁厚 0.04 m。碰撞使用同一空心网格,避免只缩小视觉开口。入洞检测记录球心向下跨过洞底平面的交点,再按洞口净空校验水平位置。
目标洞口现由 Blender 制作并导出为 `goal_hole.glb`:入口与喉部净半径均为 0.32 m,深度 0.55 m,壁厚 0.04 m。碰撞使用同一空心网格,避免只缩小视觉开口。这款直筒球洞的喉口位于上沿,球心向下跨入上口并满足孔径净空时即算入洞。
独立半径对比实验已完成选择并清理:删除其 Blender 模型、GLB、Godot 场景、脚本和报告,以及旧镜像下层导轨夹具;当前保留连续轨道、单件试跑、自由搭建和双球汇流四个试玩预设。底孔测试预设及独立底孔场景均已删除。
@@ -42,35 +42,19 @@
铁球为 SphereShape3D 刚体,半径读取生成的资产目录;均匀实心球惯量按质量和半径生成。所有轨道为静态三角网格碰撞体,铁球与轨道、铁球与铁球碰撞均开启。固定物理频率为 120 Hz,启用连续碰撞检测。
当前 `physics.json` 中的名义铁密度假设为 7870 kg/m³,半径 0.3 m 对应约 890.08 kg;质量值保存在物理预设中。木材接触试验系数为:静摩擦 0.42、动摩擦 0.32、滚动阻力 0.025、回弹 0.08;空气密度 1.225 kg/m³,铁球阻力系数为 0.47,正常计算风力和静止空气阻力。质量与接触值沿用首轮验证参数,不是实验测得的材质常数。
当前 `physics.json` 中的名义铁密度假设为 7870 kg/m³,半径 0.3 m 对应约 890.08 kg;质量值保存在物理预设中。木槽滚动阻力为 0.025,恢复系数为 0.08。与工坊共用固体滚动阻力模型,空气阻力已停用。
Godot 原生 PhysicsMaterial 只暴露一个摩擦参数;本轮根据接触点滑速切换静/动摩擦系数,再由原生求解器计算接触冲量。这是用于本轮试验的近似,不等价于完整的逐接触双系数材质求解。滚动阻力另施加受限力矩,空气作用使用相对空气速度计算,不额外修改轨道速度。多材质同时接触和铁球之间的独立材质配对尚未完整标定;目前原生回弹合成会使两个铁球各 0.08 的回弹得到约 0.16 的相对恢复表现。[Godot PhysicsMaterial](https://docs.godotengine.org/en/4.7/classes/class_physicsmaterial.html)
接触数据和力矩在刚体积分回调中读取、施加,轨迹记录只用于显示与测量。[Godot PhysicsDirectBodyState3D](https://docs.godotengine.org/en/4.7/classes/class_physicsdirectbodystate3d.html)
## 验证范围
## 验证与历史记录
本次实心底座修改已通过 42 项基础物理检查;另有两套模型的 151 项碰撞/场景检查和 16 项源文件检查,见 [本次验证索引](../README.md)。以下交互流程与双球汇流的完整历史结果未在本轮重复运行。
早期 `baseline-test` 及其物理、交互流程和双球汇流三组自动检查已删除,不再提供这些过时断言的运行入口,也不再保留 `playtest/baseline/checks/`。早期试玩场景仍可通过 `./scripts/playtest.zsh` 和 `./scripts/run.zsh merge` 手动检查。
运行 `./scripts/run.zsh baseline-test` 会刷新 Godot 导入并运行物理、交互流程和双球汇流三组测试。报告记录实际参数、轨迹和结果;退出码非零表示测试失败。
[基础物理报告](../artifacts/baseline/physics_report.json)、[交互报告](../artifacts/baseline/playtest_report.json) 和 [双球汇流报告](../artifacts/baseline/merge_report.json) 仅作为历史产物保留,不代表当前场景或共享物理脚本已经通过同一组检查。历史默认路线约 2.90 秒入洞;窗口关闭或不同操作路径不会被这些数值覆盖,需要按实际试玩继续验证。
物理测试移除底孔通过用例后共 42 项:
- 真空自由落体与球在半圆槽中的静止接触。
- 30° 理想平面上实心球滚动,加速度与解析值比较。
- 水平滚动时关闭/开启滚动阻力的速度差异。
- 两个铁球副本迎面碰撞,检查速度方向与总动量。
- 六种滑槽、四个朝向的顶部槽面通行;Y 形分别测试两个岔口,共 28 项路径测试。
- Y 形连接两个相邻直槽及一个出口直槽后,分别测试两个入口和四个朝向,共 8 项完整连接测试。连接测试初速度为 1.6 m/s,其余既有路径测试继续使用原有的 1.2 m/s 或坡道静止释放条件。
- 无接触条件下,质量相差十倍时的风响应比较;该解析基准直接读取当前铁球的非零阻力配置,仅改变质量,不再单独覆盖阻力系数。
交互流程测试共 30 项:默认重力路线穿过真实洞口、释放、暂停、重试、六种资产选择与四次旋转复位、相邻放置、运行后编辑锁定、删除、拒绝悬空放置、场景配额及鼠标射线选取可见方块;另覆盖 Y 形的合法四格尺寸、超界标记区分、重叠拒绝、四格选择、中心旋转和替换后释放多余格子。
较长的完整连接测试采用 1.6 m/s 初速度,场景中仍可用滑块调整;试验只设置初始速度,未添加持续推力、速度锁定或关闭摩擦。低初速度是否足够到达后续路线,继续由实际行程和摩擦耗能决定。
测试调用真实 Godot 场景和物理引擎。界面按钮通过信号触发、选格通过引擎输入事件路径验证;原生渲染已截图检查。没有声称通过操作系统鼠标自动化完成所有按钮测试。
当前基础物理结果见 [物理报告](../artifacts/baseline/physics_report.json),历史交互结果见 [交互报告](../artifacts/baseline/playtest_report.json)。历史默认路线约 2.90 秒入洞;当前 30° 平面验证仍与约 3.5036 m/s² 的解析值比较。窗口关闭或不同操作路径不会被这些数值覆盖,需要按实际试玩继续验证。
当前自动检查按改动范围使用 `playtest/checks/` 中的专项,入口见 [脚本说明](../../scripts/README.md)。
## 双铁球汇流场景
@@ -82,7 +66,7 @@ Godot 原生 PhysicsMaterial 只暴露一个摩擦参数;本轮根据接触点
入洞按球的唯一编号计数,每球只记录一次。已入洞球隐藏并退出碰撞;部分入洞不成功,任何一球丢失也不能通过减少剩余球数完成通关。重试会重建两球并清空入洞、轨迹及暂停状态。预设演示场景不开放方块编辑,可切回自由搭建场景调整其他布局。
双球专项验证共 16 项,覆盖同高分支、同时释放、球间碰撞开关、两球暂停、分别通过不同入口及共同出口、两球进入同一洞口、部分入洞、事件去重、退出模拟、重试复现、丢球不判胜及切回单球场景。实际完成时间约 5.4 秒,具体轨迹和逐球入洞事件见 [双球汇流报告](../artifacts/baseline/merge_report.json)。
历史双球专项曾有 16 项,覆盖同高分支、同时释放、球间碰撞开关、两球暂停、分别通过不同入口及共同出口、两球进入同一洞口、部分入洞、事件去重、退出模拟、重试复现、丢球不判胜及切回单球场景。当时实际完成时间约 5.4 秒,具体轨迹和逐球入洞事件见保留的 [双球汇流报告](../artifacts/baseline/merge_report.json);该专项现已删除,不再作为当前运行证明。
## 后续需验证
@@ -1,84 +0,0 @@
extends SceneTree
var results: Array=[]
var failures:=0
func _initialize() -> void:call_deferred("run")
func check(name: String, ok: bool, detail: Dictionary={}) -> void:
results.append({"name":name,"passed":ok,"detail":detail.duplicate(true)})
if not ok:failures+=1
print(("PASS " if ok else "FAIL ")+name+" "+JSON.stringify(detail))
func run() -> void:
var app=load("res://playtest/baseline/scenes/main.tscn").instantiate()
root.add_child(app)
app.build_preset(3)
await physics_frame
check("two_iron_balls_ready",app.merge_balls.size()==2 and app.merge_balls.all(func(b):return b.freeze and is_equal_approx(b.radius,.3) and b.linear_velocity.is_zero_approx()))
check("separate_equal_height_branches",is_equal_approx(app.merge_balls[0].position.y,app.merge_balls[1].position.y) and is_equal_approx(absf(app.merge_balls[0].position.z-app.merge_balls[1].position.z),1.0))
check("ball_collision_enabled",app.merge_balls.all(func(b):return (b.collision_layer&2)!=0 and (b.collision_mask&2)!=0))
app.start_button.pressed.emit()
check("simultaneous_release",app.merge_release_ticks.size()==2 and app.merge_release_ticks[0]==app.merge_release_ticks[1] and app.merge_balls.all(func(b):return not b.freeze and b.linear_velocity.is_zero_approx()))
for i in range(35):await physics_frame
app.toggle_run()
var positions: Array=app.merge_balls.map(func(b):return b.position)
var time: float=app.elapsed
for i in range(20):await physics_frame
check("pause_stops_both_balls",app.paused and app.merge_balls[0].position.is_equal_approx(positions[0]) and app.merge_balls[1].position.is_equal_approx(positions[1]) and is_equal_approx(time,app.elapsed))
app.toggle_run()
var partial_seen:=false
var premature_win:=false
for i in range(2400):
await physics_frame
if app.merge_entered.size()==1:
partial_seen=true
premature_win=premature_win or app.status.begins_with("成功")
if app.merge_entered.size()+app.merge_lost.size()==2:break
check("both_balls_enter_common_hole",app.merge_entered.size()==2 and app.merge_lost.is_empty(),{"status":app.status,"time":app.elapsed,"hole_events":app.merge_hole_events,"ball_collision_frames":app.merge_collision_frames,"a_position":[app.merge_balls[0].position.x,app.merge_balls[0].position.y,app.merge_balls[0].position.z],"b_position":[app.merge_balls[1].position.x,app.merge_balls[1].position.y,app.merge_balls[1].position.z]})
check("one_ball_is_not_a_win",partial_seen and not premature_win)
check("two_unique_hole_events",app.merge_hole_events.size()==2 and app.merge_hole_events[0].ballId!=app.merge_hole_events[1].ballId)
var first_run: Array=app.merge_samples.duplicate(true)
var correct_inlets:=true
var common_outlet:=true
for i in range(2):
var key: String="a" if i==0 else "b"
var inlet_seen:=false
var outlet_seen:=false
for sample in first_run:
var p: Array=sample[key]
if p[0]>-.6 and p[0]<-.1 and absf(p[2]-i)<.2 and p[1]>1.8:inlet_seen=true
if p[0]>1.3 and p[0]<1.7 and absf(p[2]-1)<.2 and p[1]>1.5:outlet_seen=true
correct_inlets=correct_inlets and inlet_seen
common_outlet=common_outlet and outlet_seen
check("both_use_distinct_y_inlets",correct_inlets)
check("both_use_common_y_outlet",common_outlet)
for i in range(60):await physics_frame
check("hole_events_not_repeated",app.merge_hole_events.size()==2)
check("entered_balls_exit_simulation",app.merge_balls.all(func(b):return b.freeze and not b.visible and b.collision_mask==0 and b.collision_layer==0))
app.reset_ball()
await physics_frame
check("retry_restores_two_balls",app.merge_balls.size()==2 and app.merge_balls.all(func(b):return b.freeze and b.visible and b.collision_mask==3) and app.merge_entered.is_empty() and app.merge_hole_events.is_empty() and app.elapsed==0)
app.toggle_run()
for i in range(2400):
await physics_frame
if app.merge_entered.size()+app.merge_lost.size()==2:break
check("repeat_run_completes",app.merge_entered.size()==2 and app.merge_lost.is_empty(),{"time":app.elapsed})
app.reset_ball();app.toggle_run()
app.merge_balls[0].position=Vector3(0,-2,0)
for i in range(1800):
await physics_frame
if app.merge_entered.size()+app.merge_lost.size()==2:break
check("lost_ball_does_not_reduce_target",app.merge_lost.size()==1 and app.merge_entered.size()==1 and not app.status.begins_with("成功"))
app.build_preset(0)
await physics_frame
var dynamic_balls:=0
for child in app.get_children():
if child is RigidBody3D:dynamic_balls+=1
check("switch_back_to_single_ball_scene",app.merge_balls.is_empty() and dynamic_balls==1 and is_instance_valid(app.ball))
var path=ProjectSettings.globalize_path("res://playtest/artifacts/baseline/merge_report.json")
var file=FileAccess.open(path,FileAccess.WRITE)
file.store_string(JSON.stringify({"passed":results.size()-failures,"failed":failures,"results":results,"first_run_trace":first_run}," "))
file.close()
app.queue_free()
await process_frame
quit(1 if failures else 0)
@@ -1 +0,0 @@
uid://mumonx8gdgce
@@ -1,178 +0,0 @@
extends SceneTree
const Library = preload("res://playtest/baseline/scripts/asset_library.gd")
var lib = Library.new()
var arena: Node3D
var results: Array = []
var failures := 0
func _initialize() -> void:
call_deferred("run")
func vec(v: Vector3) -> Array:
return [snappedf(v.x,.000001),snappedf(v.y,.000001),snappedf(v.z,.000001)]
func clear_arena() -> void:
if is_instance_valid(arena):
root.remove_child(arena)
arena.queue_free()
arena=Node3D.new()
root.add_child(arena)
await physics_frame
await physics_frame
func record(name: String, passed: bool, detail: Dictionary) -> void:
results.append({"name":name,"passed":passed,"detail":detail})
if not passed:failures+=1
print(("PASS " if passed else "FAIL ")+name+" "+JSON.stringify(detail))
func run_path(kind: String, rotation_step: int, branch: int, connected := false) -> void:
await clear_arena()
var basis:=Basis(Vector3.UP,-rotation_step*PI/2)
arena.add_child(lib.create_piece(kind,Vector3.ZERO,rotation_step))
var sphere=lib.create_ball()
sphere.freeze=true
var descending: bool=kind in ["gentle","steep"]
var t:=.80 if descending else .05
var direction: Vector3=lib.path_tangent(kind,0,branch)
var start: Vector3
var target: Vector3
var exit_direction: Vector3
start=lib.ball_on_surface(kind,t,branch)
target=lib.ball_on_surface(kind,0 if descending else 1,branch)
exit_direction=-lib.path_tangent(kind,0,branch) if descending else lib.path_tangent(kind,1,branch)
if connected:
for local_center in lib.y_connectors():arena.add_child(lib.create_piece("straight",basis*local_center,rotation_step))
start=lib.path_point(kind,0,branch)+Vector3(-.65,-float(lib.catalog[kind].grooveRadius)+sphere.radius+.018,0)
target=lib.path_point(kind,1,branch)+Vector3(.85,-float(lib.catalog[kind].grooveRadius)+sphere.radius,0)
direction=Vector3.RIGHT
arena.add_child(sphere)
sphere.position=basis*start
await physics_frame
sphere.freeze=false
var initial_speed: float=1.6 if connected else 1.2
sphere.linear_velocity=Vector3.ZERO if descending else basis*direction*initial_speed
sphere.angular_velocity=Vector3.UP.cross(sphere.linear_velocity)/sphere.radius
var closest:=100.0
var reached:=false
var contact_frames:=0
var highest_speed:=0.0
var trace: Array=[]
var time_at_exit:=-1.0
for frame in range(720):
await physics_frame
var p: Vector3=basis.inverse()*sphere.position
var delta_to_goal:=p-target
var axial:=delta_to_goal.dot(exit_direction)
var lateral:=(delta_to_goal-exit_direction*axial).length()
closest=minf(closest,delta_to_goal.length())
highest_speed=maxf(highest_speed,sphere.linear_velocity.length())
if sphere.contact_count>0:contact_frames+=1
if frame%12==0:trace.append({"t":frame/120.0,"p":vec(p),"v":vec(basis.inverse()*sphere.linear_velocity)})
if axial>.04 and lateral<.22:
reached=true
time_at_exit=frame/120.0
break
if p.y < -2:break
var path_name:="connected" if connected else "upper"
record("%s_%s_r%d_b%d" % [path_name,kind,rotation_step*90,branch],reached and contact_frames>0,
{"reached_exit":reached,"time":time_at_exit,"initial_speed":0.0 if descending else initial_speed,"closest_m":closest,"contact_frames":contact_frames,"max_speed":highest_speed,"final":vec(basis.inverse()*sphere.position),"trace":trace})
func run() -> void:
Engine.physics_ticks_per_second=120
await clear_arena()
var falling=lib.create_ball()
falling.drag_enabled=false
falling.rolling_enabled=false
arena.add_child(falling)
falling.position=Vector3(0,10,0)
await physics_frame
var start_y: float=falling.position.y
var start_v: float=falling.linear_velocity.y
for i in range(120):await physics_frame
var expected_drop: float=-start_v+4.905
var observed_drop: float=start_y-falling.position.y
record("vacuum_freefall_1s",absf((falling.linear_velocity.y-start_v)+9.81)<.02 and absf(observed_drop-expected_drop)<.05,
{"initial_velocity":start_v,"velocity_delta":falling.linear_velocity.y-start_v,"distance":observed_drop,"analytic_distance":expected_drop,"position_error":absf(observed_drop-expected_drop)})
await clear_arena()
arena.add_child(lib.create_piece("straight"))
var resting=lib.create_ball()
arena.add_child(resting)
resting.position=Vector3(0,1.8,0)
for i in range(300):await physics_frame
record("sphere_groove_rest",absf(resting.position.y-(1.0-float(lib.catalog["straight"].grooveRadius)+resting.radius))<.035 and resting.linear_velocity.length()<.1,
{"position":vec(resting.position),"speed":resting.linear_velocity.length(),"contacts":resting.contact_count})
# An independent analytic benchmark: sphere rolling on a 30 degree plane.
await clear_arena()
var plane=lib.create_box(Vector3(20,.2,4),Vector3(0,-.1,0),Color.GRAY)
plane.rotation.z=-PI/6
arena.add_child(plane)
var ramp_ball=lib.create_ball()
ramp_ball.drag_enabled=false
ramp_ball.rolling_enabled=false
arena.add_child(ramp_ball)
var normal: Vector3=plane.basis*Vector3.UP
var downhill: Vector3=plane.basis*Vector3.RIGHT
ramp_ball.position=plane.transform*Vector3(0,.1,0)+normal*(ramp_ball.radius+.005)
for i in range(30):await physics_frame
var first_velocity: float=ramp_ball.linear_velocity.dot(downhill)
for i in range(60):await physics_frame
var acceleration: float=(ramp_ball.linear_velocity.dot(downhill)-first_velocity)/.5
var slip: float=absf(ramp_ball.linear_velocity.dot(downhill)-ramp_ball.angular_velocity.length()*ramp_ball.radius)
record("solid_sphere_30_degree_plane",absf(acceleration-3.503571)<.09 and slip<.06,{"acceleration":acceleration,"analytic_acceleration":3.503571,"rolling_slip":slip})
var horizontal_speeds: Array=[]
for enabled in [false,true]:
await clear_arena()
arena.add_child(lib.create_box(Vector3(30,.2,4),Vector3(0,-.1,0),Color.GRAY))
var rolling_ball=lib.create_ball()
rolling_ball.drag_enabled=false
rolling_ball.rolling_enabled=enabled
arena.add_child(rolling_ball)
rolling_ball.position=Vector3(0,rolling_ball.radius+.001,0)
rolling_ball.linear_velocity=Vector3(2,0,0)
rolling_ball.angular_velocity=Vector3(0,0,-2/rolling_ball.radius)
for i in range(240):await physics_frame
horizontal_speeds.append(rolling_ball.linear_velocity.length())
record("rolling_resistance_dissipates",absf(horizontal_speeds[0]-2)<.05 and horizontal_speeds[1]<horizontal_speeds[0]-.15,{"disabled_enabled_speeds":horizontal_speeds})
await clear_arena()
var left=lib.create_ball()
var right=lib.create_ball()
for sphere in [left,right]:
sphere.gravity_scale=0
sphere.drag_enabled=false
sphere.rolling_enabled=false
arena.add_child(sphere)
left.position=Vector3(-1,2,0);right.position=Vector3(1,2,0)
left.linear_velocity=Vector3.RIGHT;right.linear_velocity=Vector3.LEFT
for i in range(150):await physics_frame
var momentum_error: float=(left.linear_velocity+right.linear_velocity).length()
record("ball_to_ball_collision_enabled",left.linear_velocity.x<-.02 and right.linear_velocity.x>.02 and momentum_error<.02,{"left_velocity":vec(left.linear_velocity),"right_velocity":vec(right.linear_velocity),"normalized_momentum_error":momentum_error})
for kind in ["straight","turn_90","gentle","steep","y_merge"]:
for q in range(4):
for branch in range(2 if kind=="y_merge" else 1):
await run_path(kind,q,branch)
for q in range(4):
for branch in range(2):await run_path("y_merge",q,branch,true)
# Air response independently of contacts; compare actual simulated velocities.
var air_velocities: Array=[]
for mass_factor in [1.0,10.0]:
await clear_arena()
var sphere=lib.create_ball()
sphere.gravity_scale=0
sphere.mass*=mass_factor
sphere.wind_velocity=Vector3(20,0,0)
arena.add_child(sphere)
sphere.position=Vector3(0,5,0)
for i in range(60):await physics_frame
air_velocities.append(sphere.linear_velocity.x)
var ratio: float=air_velocities[0]/maxf(air_velocities[1],.000001)
record("wind_mass_response",absf(ratio-10)<.15,{"speeds":air_velocities,"ratio":ratio})
var output={"engine":Engine.get_version_info().string,"physics_engine":ProjectSettings.get_setting("physics/3d/physics_engine"),"ticks_per_second":120,"passed":results.size()-failures,"failed":failures,"results":results}
var path: String=ProjectSettings.globalize_path("res://playtest/artifacts/baseline/physics_report.json")
var file:=FileAccess.open(path,FileAccess.WRITE)
file.store_string(JSON.stringify(output," "))
file.close()
print("PHYSICS_REPORT "+path+" failures="+str(failures))
if is_instance_valid(arena):arena.queue_free()
await process_frame
quit(1 if failures else 0)
@@ -1 +0,0 @@
uid://byeccpbcfaoj3
@@ -1,89 +0,0 @@
extends SceneTree
var results: Array=[]
var failed:=0
func _initialize() -> void:
call_deferred("run")
func check(name: String, passed: bool, detail: Dictionary={}) -> void:
results.append({"name":name,"passed":passed,"detail":detail})
if not passed:failed+=1
print(("PASS " if passed else "FAIL ")+name+" "+JSON.stringify(detail))
func run() -> void:
var app=load("res://playtest/baseline/scenes/main.tscn").instantiate()
root.add_child(app)
await physics_frame
check("one_iron_ball_ready",is_instance_valid(app.ball) and app.ball.freeze and is_equal_approx(app.ball.radius,.3),{"mass_kg":app.ball.mass,"radius_m":app.ball.radius})
app.start_button.pressed.emit()
check("release_button",app.started and not app.ball.freeze)
for i in range(1800):
await physics_frame
if app.status.begins_with("成功") or app.status.begins_with("已离开"):break
check("default_course_reaches_hole",app.status.begins_with("成功"),{"status":app.status,"time":app.elapsed,"position":[app.ball.position.x,app.ball.position.y,app.ball.position.z],"max_speed":app.max_speed})
app.reset_ball()
await physics_frame
check("retry_clears_state",not app.started and app.ball.freeze and app.trail_points.is_empty() and app.elapsed==0)
check("scenario_specific_quotas",app.quota("steep")==0 and app.quota("straight")==6)
app.choose_kind("steep")
check("reject_unavailable_type",app.selected_kind!="steep")
var click:=InputEventMouseButton.new()
click.button_index=MOUSE_BUTTON_LEFT
click.pressed=true
click.position=app.camera.unproject_position(Vector3(0,1.3,.5))
app._unhandled_input(click)
check("ray_select_visible_tile",app.selected_index==app.find_cell(Vector2i(0,0)) and is_equal_approx(app.placement_height,.5))
app.build_preset(1)
await physics_frame
for kind in app.IDS:
app.choose_kind(kind)
await physics_frame
check("library_"+kind,app.records.size()==1 and app.records[0].kind==kind and app.pieces.size()==1)
for i in range(4):app.rotate_selected()
check("rotation_cycle_"+kind,app.preview_quarter==0 and app.records[0].quarter==0)
check("y_has_declared_four_cell_footprint",app.lib.footprint("y_merge")==Vector2i(2,2) and app.lib.catalog.y_merge.declaredBoundsFits and app.lib.catalog.y_merge.ports.size()==3)
check("y_not_mislabelled_as_steep_exception",not app.warning_label.text.contains("陡坡"))
app.build_preset(2)
await physics_frame
var previous: int=app.records.size()
app.selected_cell=Vector2i(2,0)
app.placement_height=.5
app.choose_kind("turn_90")
app.place_selected()
check("place_adjacent_tile",app.records.size()==previous+1 and app.find_cell(Vector2i(2,0))>=0)
app.toggle_run()
var locked: int=app.records.size()
app.remove_selected()
check("editing_locked_after_release",app.records.size()==locked)
app.toggle_run()
check("pause_preserves_run_lock",app.paused and app.started and app.ball.freeze)
app.reset_ball()
app.remove_selected()
check("delete_after_retry",app.records.size()==previous)
app.selected_cell=Vector2i(4,4)
app.place_selected()
check("reject_unattached_tile",app.records.size()==previous)
app.selected_cell=Vector2i(0,0)
app.placement_height=.5
app.choose_kind("y_merge")
app.place_selected()
check("reject_y_overlap_with_neighbor",app.records.size()==previous and app.records[app.find_cell(Vector2i(0,0))].kind=="straight" and app.status.contains("重叠"))
app.selected_cell=Vector2i(-1,1)
app.place_selected()
var y_index: int=app.find_cell(Vector2i(-1,1))
var all_cells_match: bool=y_index>=0
for cell in [Vector2i(-1,1),Vector2i(0,1),Vector2i(-1,2),Vector2i(0,2)]:all_cells_match=all_cells_match and app.find_cell(cell)==y_index
check("y_reserves_four_cells",app.records.size()==previous+1 and all_cells_match)
var model_center: Vector3=app.pieces[y_index].position
for i in range(4):app.rotate_selected()
check("y_rotates_about_fixed_center",app.pieces[y_index].position.is_equal_approx(model_center) and app.preview_quarter==0)
app.choose_kind("straight")
app.place_selected()
check("replace_y_releases_extra_cells",app.find_cell(Vector2i(-1,1))==y_index and app.find_cell(Vector2i(0,2))==-1)
var path=ProjectSettings.globalize_path("res://playtest/artifacts/baseline/playtest_report.json")
var out=FileAccess.open(path,FileAccess.WRITE)
out.store_string(JSON.stringify({"passed":results.size()-failed,"failed":failed,"results":results}," "))
out.close()
app.queue_free()
await process_frame
quit(1 if failed else 0)
@@ -1 +0,0 @@
uid://ddf8i08g3bf4k
+6 -8
View File
@@ -34,7 +34,7 @@ func add_colliders(node: Node, kind: String) -> void:
body.collision_mask = 2
body.set_meta("piece_type",kind)
var material := PhysicsMaterial.new()
material.friction = .25 if kind=="goal_hole" else 1.0 # native pair uses min.
material.friction = 0.0
material.bounce = 0.0
body.physics_material_override = material
var collider := CollisionShape3D.new()
@@ -60,16 +60,13 @@ func create_ball() -> RigidBody3D:
body.radius = float(data["radius"])
body.mass = float(profile["massKg"])
body.inertia = Vector3.ONE * (0.4 * body.mass * body.radius * body.radius)
body.drag_coefficient = float(profile["dragCoefficient"])
body.air_density = float(physics["airDensity"])
body.mu_static = float(pair["staticFriction"])
body.mu_dynamic = float(pair["dynamicFriction"])
body.rolling_resistance = float(pair["rollingResistance"])
body.collision_layer = 2
body.collision_mask = 3
var material := PhysicsMaterial.new()
material.friction = body.mu_static
material.friction = 0.0
material.bounce = float(pair["restitution"])
body.base_bounce = material.bounce
body.physics_material_override = material
var shape := SphereShape3D.new()
shape.radius = body.radius
@@ -100,7 +97,7 @@ func create_box(size: Vector3, location: Vector3, color: Color, solid := true) -
root.collision_layer = 1
root.collision_mask = 2
var pm := PhysicsMaterial.new()
pm.friction = 1.0
pm.friction = 0.0
root.physics_material_override = pm
return root
@@ -143,7 +140,8 @@ func create_goal_hole(location: Vector3) -> Node3D:
return create_piece("goal_hole",location)
func crossed_goal(previous: Vector3, current: Vector3, goal: Vector3, radius: float) -> bool:
var height: float=goal.y-float(catalog["goal_hole"].depth)
# This older straight bore has its throat entrance at the rim.
var height: float=goal.y
if previous.y<=height or current.y>height:return false
var ratio: float=(previous.y-height)/maxf(previous.y-current.y,.000001)
var crossing: Vector3=previous.lerp(current,ratio)
+1 -67
View File
@@ -1,67 +1 @@
extends RigidBody3D
var radius: float = 0.3
var drag_coefficient: float = 0.47
var air_density: float = 1.225
var wind_velocity := Vector3.ZERO
var mu_static: float = 0.42
var mu_dynamic: float = 0.32
var rolling_resistance: float = 0.025
var friction_enabled := true
var rolling_enabled := true
var drag_enabled := true
var contact_count := 0
var ball_contact_count := 0
var contact_slip := 0.0
var air_force := Vector3.ZERO
var rolling_torque := Vector3.ZERO
var travelled := 0.0
var previous_position := Vector3.ZERO
var tracking_started := false
func _ready() -> void:
continuous_cd = true
contact_monitor = true
max_contacts_reported = 12
can_sleep = false
linear_damp_mode = RigidBody3D.DAMP_MODE_REPLACE
angular_damp_mode = RigidBody3D.DAMP_MODE_REPLACE
linear_damp = 0.0
angular_damp = 0.0
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
if freeze:
return
contact_count = state.get_contact_count()
ball_contact_count = 0
contact_slip = 0.0
var support_normal := Vector3.ZERO
for i in range(contact_count):
if state.get_contact_collider_object(i) is RigidBody3D:ball_contact_count+=1
# Contact positions are global; the sphere's radial direction is unambiguous.
var n := (state.transform.origin - state.get_contact_local_position(i)).normalized()
var relative := state.get_contact_local_velocity_at_position(i) - state.get_contact_collider_velocity_at_position(i)
var slip := relative - n * relative.dot(n)
contact_slip = maxf(contact_slip, slip.length())
if n.dot(Vector3.UP) > 0.15:
support_normal += n
# Godot exposes one native friction coefficient. Select a slip-dependent
# coefficient; native contact solver still owns the friction impulse.
physics_material_override.friction = (mu_static if contact_slip < 0.035 else mu_dynamic) if friction_enabled else 0.0
var relative_air := state.linear_velocity - wind_velocity
air_force = -0.5 * air_density * drag_coefficient * PI * radius * radius * relative_air.length() * relative_air if drag_enabled else Vector3.ZERO
state.apply_central_force(air_force)
rolling_torque = Vector3.ZERO
if rolling_enabled and support_normal.length_squared() > 0.001:
var n := support_normal.normalized()
var roll := state.angular_velocity - n * state.angular_velocity.dot(n)
if roll.length() > 0.0001:
var support := maxf(0.0, -(mass * state.total_gravity + air_force).dot(n))
var moment := 0.4 * mass * radius * radius
var limit := roll.length() * moment / state.step
rolling_torque = -roll.normalized() * minf(rolling_resistance * support * radius, limit)
state.apply_torque(rolling_torque)
if tracking_started:
travelled += state.transform.origin.distance_to(previous_position)
previous_position = state.transform.origin
tracking_started = true
extends "res://assets/balls/shared/physics.gd"
-10
View File
@@ -68,7 +68,6 @@ var start_button: Button
var quota_label: Label
var mode_selector: OptionButton
var speed_slider: HSlider
var wind_slider: HSlider
var type_buttons: Array = []
var ui_font: SystemFont
var capture_frames := -1
@@ -262,12 +261,6 @@ func setup_ui() -> void:
if not started: configure_spawn(); reset_ball()
)
column.add_child(speed_slider)
column.add_child(label_for("横风速度(m/s)",13,MUTED))
wind_slider = HSlider.new()
wind_slider.min_value = 0
wind_slider.max_value = 60
wind_slider.step = 5
column.add_child(wind_slider)
var checks := HBoxContainer.new()
var trail_check := CheckButton.new()
trail_check.text = "轨迹"
@@ -323,7 +316,6 @@ func build_preset(new_mode: int) -> void:
selected_kind="y_merge"
launch_speed=0
speed_slider.set_value_no_signal(0)
wind_slider.set_value_no_signal(0)
elif previous_mode==3:
launch_speed=1.2
speed_slider.set_value_no_signal(launch_speed)
@@ -674,7 +666,6 @@ func _physics_process(delta: float) -> void:
process_merge(delta)
return
if not is_instance_valid(ball):return
ball.wind_velocity=Vector3(0,0,float(wind_slider.value))
if started and not paused and not ball.freeze:
elapsed+=delta
max_speed=maxf(max_speed,ball.linear_velocity.length())
@@ -785,7 +776,6 @@ func process_merge(delta: float) -> void:
for i in range(merge_balls.size()):
if merge_entered.has(i) or merge_lost.has(i):continue
var sphere=merge_balls[i]
sphere.wind_velocity=Vector3(0,0,float(wind_slider.value))
max_speed=maxf(max_speed,sphere.linear_velocity.length())
if sphere.ball_contact_count>0:touching_ball=true
if lib.crossed_goal(merge_previous_positions[i],sphere.position,goal_position,sphere.radius):