- 为铁球、陶瓷球和木球制作风格化材质,归档 CC0 原始参考 - 更新方形球洞和实心滑槽,统一 90° 弯槽并兼容旧存档 - 用顺流泡沫表示水流方向,为冰块制作三种交错的裂纹 - 同步 Blender 源资产、Godot 加载、工坊和试玩预览
72 lines
3.5 KiB
GDScript
72 lines
3.5 KiB
GDScript
extends SceneTree
|
|
|
|
# Candidate ceramic masses only. The real profile file is read, never rewritten.
|
|
# Geometry, water, material pairs and force code are the current production ones.
|
|
const Library = preload("res://runtime/asset_library.gd")
|
|
var lib=Library.new()
|
|
var fixture:=Node3D.new()
|
|
var trials: Array=[]
|
|
var request_path: String
|
|
var result_path: String
|
|
|
|
func _initialize() -> void:
|
|
for arg in OS.get_cmdline_user_args():
|
|
if arg.begins_with("--request="):request_path=arg.trim_prefix("--request=")
|
|
if arg.begins_with("--result="):result_path=arg.trim_prefix("--result=")
|
|
call_deferred("run")
|
|
|
|
func frames(count: int) -> void:
|
|
for i in range(count):await physics_frame
|
|
|
|
func run() -> void:
|
|
if request_path.is_empty() or result_path.is_empty():quit(2);return
|
|
var request: Dictionary=JSON.parse_string(FileAccess.get_file_as_string(request_path))
|
|
var level: Dictionary=JSON.parse_string(FileAccess.get_file_as_string("res://playtest/environment/data/water.json"))
|
|
var spawn: Dictionary=level.balls.filter(func(b):return b.ballTypeId=="ceramic_ball")[0]
|
|
Engine.physics_ticks_per_second=int(request.physics_hz)
|
|
root.add_child(fixture)
|
|
for candidate in request.masses_kg:
|
|
for child in fixture.get_children():fixture.remove_child(child);child.queue_free()
|
|
await frames(2)
|
|
# The ceramic lane, with the SAME real floor, banks, water and downstream end.
|
|
# The end wall is 8.2m from release, well beyond the requested 2m acceptance.
|
|
for record in level.entities:
|
|
if absf(float(record.position[2])-float(spawn.position[2]))>1.01:continue
|
|
fixture.add_child(lib.create_piece(record.kind,lib.vector(record.position),int(record.quarter)))
|
|
var body=lib.create_ball("ceramic_ball")
|
|
var profile_mass: float=body.mass
|
|
body.mass=float(candidate)
|
|
body.inertia=Vector3.ONE*(.4*body.mass*body.radius*body.radius)
|
|
body.freeze=true;fixture.add_child(body);body.position=lib.vector(spawn.position)
|
|
await frames(3)
|
|
var initial: Vector3=body.position
|
|
var maximum:=0.0
|
|
var min_y: float=initial.y
|
|
var contact_seconds: float=-1
|
|
var contact_x: float=-1
|
|
var trace: Array=[]
|
|
body.freeze=false
|
|
for frame in range(int(float(request.duration_seconds)*Engine.physics_ticks_per_second)):
|
|
await physics_frame
|
|
maximum=maxf(maximum,body.position.x-initial.x)
|
|
min_y=minf(min_y,body.position.y)
|
|
if contact_seconds<0 and body.active_surface=="wall" and body.position.y<1.35:
|
|
contact_seconds=(frame+1.0)/Engine.physics_ticks_per_second
|
|
contact_x=body.position.x-initial.x
|
|
if frame%12==0:
|
|
trace.append({"seconds":(frame+1.0)/Engine.physics_ticks_per_second,
|
|
"downstream_m":body.position.x-initial.x,"center_y_m":body.position.y,
|
|
"vx_mps":body.linear_velocity.x,"immersion":body.submerged_fraction})
|
|
var row={"candidate_mass_kg":body.mass,"original_profile_mass_kg":profile_mass,
|
|
"duration_seconds":request.duration_seconds,"physics_hz":Engine.physics_ticks_per_second,
|
|
"max_downstream_m":maximum,"final_downstream_m":body.position.x-initial.x,
|
|
"final_speed_mps":body.linear_velocity.length(),"final_center_y_m":body.position.y,
|
|
"minimum_center_y_m":min_y,"first_bed_contact_seconds":contact_seconds,"bed_contact_x_m":contact_x,
|
|
"settled_on_bed":body.position.y<1.35 and body.active_surface=="wall" and body.submerged_fraction>.95,
|
|
"hit_downstream_end":maximum>=8.15,"trace":trace}
|
|
trials.append(row)
|
|
print("MASS_TRIAL ",candidate," kg; x=",maximum," m; final_y=",body.position.y)
|
|
var file:=FileAccess.open(result_path,FileAccess.WRITE)
|
|
file.store_string(JSON.stringify({"trials":trials,"engine":Engine.get_version_info().string}," "));file.close()
|
|
quit()
|