Files
Yanchen bf6c355fa6 feat: 切换至滚动阻力运行模型并更新资产、编辑器与验证
- 物理规则:现行模型仅保留滚动阻力耗能与恢复系数碰撞,风力、空气阻力、静摩擦、动摩擦不再参与运行;确认三球质量 60/330/约890 kg 及水密度、流阻参数
- 定向加速改为真实顶面接触触发的一次性 +5 m/s 速度事件,模型新增渐进式 U 形导槽出口
- 更新球体、滑槽、水/冰/墙、球洞模型与 storybook 目录、物理、实体配置
- 工坊摆放、编辑器、运行适配与检查脚本同步;删除过时的 baseline 三组检查
- 新增谜题设计参考文档、关卡草稿与本轮实验产物
2026-12-05 10:37:31 +08:00

113 lines
5.6 KiB
GDScript

extends RefCounted
# The editor always works in bottom-face coordinates; imported mesh origins stay intact.
var lib
func _init(library) -> void:lib=library
func bottom_of(record: Dictionary) -> Vector3:
return record.position+Vector3.UP*float(lib.catalog[record.kind].boundsBlender.min[2])
func record_at(kind: String,bottom: Vector3,quarter: int,id: String) -> Dictionary:
var at:=bottom
# Surface joins can be at e.g. Y=1.82; half-metre rounding recreates a lip.
if kind!="goal_hole":at=Vector3(round(at.x),at.y,round(at.z))
var local_min: float=lib.catalog[kind].boundsBlender.min[2]
return {"id":id,"kind":kind,"position":at-Vector3.UP*local_min,"quarter":quarter}
func on_face(support: Dictionary,point: Vector3,normal: Vector3,kind: String,quarter: int,neighbors: Array=[]) -> Vector3:
var bounds: AABB=lib.record_bounds(support)
var size: Vector2i=lib.footprint(kind,quarter)
var height: float=lib.catalog[kind].boundsBlender.size[2]
var result:=Vector3(round(point.x),bounds.position.y,round(point.z))
var axis:=normal.abs().max_axis_index()
if axis==1:
result.y=bounds.end.y if normal.y>=0 else bounds.position.y-height
elif axis==0:
result.x=bounds.end.x+.5 if normal.x>=0 else bounds.position.x+.5-size.x
else:
result.z=bounds.end.z+.5 if normal.z>=0 else bounds.position.z+.5-size.y
if kind!="goal_hole":
if axis==0:result.x=ceilf(result.x-.0001) if normal.x>=0 else floorf(result.x+.0001)
elif axis==2:result.z=ceilf(result.z-.0001) if normal.z>=0 else floorf(result.z+.0001)
# Top/bottom clicks still mean stacking. Only side joins use rolling surfaces.
if axis!=1:
var nearby: Array=neighbors if not neighbors.is_empty() else [support]
result=bottom_of(align_surfaces(record_at(kind,result,quarter,"preview"),nearby,str(support.id)))
return result
func ports(record: Dictionary) -> Array:
# Catalog ports are authored groove-floor positions in runtime coordinates.
# Their travel vector is not an outward normal (both ends may share travel).
var result: Array=[]
var model: Dictionary=lib.catalog[record.kind]
var basis:=Basis(Vector3.UP,-int(record.quarter)*PI/2)
var center: Vector3=lib.record_center(record)
for port in model.get("ports",[]):
var local: Vector3=lib.vector(port.surface)
var half_x: float=model.boundsBlender.size[0]*.5
var half_z: float=model.boundsBlender.size[1]*.5
var outward:=Vector3(signf(local.x),0,0) if absf(absf(local.x)-half_x)<.001 else Vector3(0,0,signf(local.z))
if absf(absf(local.x)-half_x)>=.001 and absf(absf(local.z)-half_z)>=.001:continue
result.append({"surface":center+basis*local,"normal":basis*outward})
return result
func boost_mouth(record: Dictionary) -> Dictionary:
var bounds: AABB = lib.record_bounds(record)
var basis := Basis(Vector3.UP, -int(record.quarter)*PI/2)
var normal: Vector3 = basis * lib.vector(lib.catalog[record.kind].arrowDirectionGodot)
var surface := bounds.get_center() + normal*.5
surface.y = record.position.y + lib.catalog[record.kind].baseHeight
return {"surface":surface, "normal":normal}
func connections(candidate: Dictionary,neighbors: Array) -> Array:
var matches: Array=[]
var is_boost: bool = candidate.kind == "directional_boost"
var own_ports: Array = [boost_mouth(candidate)] if is_boost else ports(candidate)
for own in own_ports:
for other in neighbors:
if other.id==candidate.id:continue
var targets: Array=ports(other)
if not is_boost and other.kind in ["wall","directional_boost","ice","goal_hole"]:
# Flat solid tops and the goal rim have no groove. Use the edge at
# this lane, not the block bottom or the decorative arrow mesh.
var bounds: AABB=lib.record_bounds(other)
var p: Vector3=own.surface
var n: Vector3=own.normal
var axis:=0 if absf(n.x)>.5 else 2
var lateral:=2 if axis==0 else 0
var edge: float=bounds.position[axis] if n[axis]>0 else bounds.end[axis]
if absf(p[axis]-edge)<.001 and p[lateral]>bounds.position[lateral]+.001 and p[lateral]<bounds.end[lateral]-.001:
var rolling_y: float = boost_mouth(other).surface.y if other.kind=="directional_boost" else bounds.end.y
targets.append({"surface":Vector3(p.x,rolling_y,p.z),"normal":-n})
for target in targets:
var delta: Vector3=target.surface-own.surface
if Vector2(delta.x,delta.z).length()>.001 or own.normal.dot(target.normal)>-.999:continue
# Nearby layers only; a distant floor must not capture a grid pick.
var reach: float=maxf(lib.catalog[candidate.kind].boundsBlender.size[2],lib.catalog[other.kind].boundsBlender.size[2])
if absf(delta.y)>reach+.001:continue
matches.append({"offset":delta.y,"support":str(other.id)})
return matches
func align_surfaces(candidate: Dictionary,neighbors: Array,preferred: String="") -> Dictionary:
# Shared by workshop face picking and player grid placement/preview. Keep the
# chosen type, X/Z and rotation; solve only the translation along world Y.
var matches:=connections(candidate,neighbors)
if matches.is_empty():return candidate
var best: Dictionary={}
for match in matches:
var count:=0
for other in matches:
if absf(other.offset-match.offset)<.001:count+=1
var priority:=1 if match.support==preferred else 0
var better: bool=best.is_empty()
if not best.is_empty():
if priority!=best.priority:better=priority>best.priority
elif count!=best.count:better=count>best.count
elif not is_equal_approx(absf(match.offset),absf(best.offset)):better=absf(match.offset)<absf(best.offset)
else:better=match.offset<best.offset # Stable tie-break, independent of record order.
if better:
best={"offset":match.offset,"priority":priority,"count":count}
var result:=candidate.duplicate(true)
result.position.y+=float(best.offset)
return result