feat: 更新 IntoHole 的球体、滑槽和环境资产
- 为铁球、陶瓷球和木球制作风格化材质,归档 CC0 原始参考 - 更新方形球洞和实心滑槽,统一 90° 弯槽并兼容旧存档 - 用顺流泡沫表示水流方向,为冰块制作三种交错的裂纹 - 同步 Blender 源资产、Godot 加载、工坊和试玩预览
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
extends Node3D
|
||||
|
||||
# Fixed game rule. No exported/per-instance speed or level override.
|
||||
const FLOW_SPEED := 5.0
|
||||
const DENSITY := 1000.0
|
||||
const DRAG_COEFFICIENT := 0.47
|
||||
var bounds := AABB()
|
||||
var local_direction := Vector3.RIGHT
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("water_blocks")
|
||||
|
||||
func flow_velocity() -> Vector3:
|
||||
return (global_basis * local_direction).normalized() * FLOW_SPEED
|
||||
|
||||
func world_bounds() -> AABB:
|
||||
return global_transform * bounds
|
||||
|
||||
# Integrate vertical sphere columns against the UNION of nearby water cells.
|
||||
# Exact vertical intervals, normalized horizontal quadrature: no seam collision,
|
||||
# no doubled buoyancy in overlapping cells, and continuous partial immersion.
|
||||
static func sample(center: Vector3, radius: float, blocks: Array) -> Dictionary:
|
||||
var nearby: Array=[]
|
||||
for block in blocks:
|
||||
var box: AABB=block.world_bounds()
|
||||
if box.grow(radius).has_point(center):nearby.append({"box":box,"velocity":block.flow_velocity()})
|
||||
if nearby.is_empty():return {"fraction":0.0,"velocity":Vector3.ZERO}
|
||||
var total:=0.0
|
||||
var immersed:=0.0
|
||||
var flow:=Vector3.ZERO
|
||||
const SAMPLES := 12
|
||||
for x in range(SAMPLES):
|
||||
for z in range(SAMPLES):
|
||||
var dx:=radius*((x+.5)*2/SAMPLES-1)
|
||||
var dz:=radius*((z+.5)*2/SAMPLES-1)
|
||||
var square:=radius*radius-dx*dx-dz*dz
|
||||
if square<=0:continue
|
||||
var half:=sqrt(square)
|
||||
total+=2*half
|
||||
var intervals: Array=[]
|
||||
var edges: Array=[]
|
||||
for water in nearby:
|
||||
var box: AABB=water.box
|
||||
var px:=center.x+dx;var pz:=center.z+dz
|
||||
if px<box.position.x or px>=box.end.x or pz<box.position.z or pz>=box.end.z:continue
|
||||
var low:=maxf(center.y-half,box.position.y)
|
||||
var high:=minf(center.y+half,box.end.y)
|
||||
if high<=low:continue
|
||||
intervals.append({"low":low,"high":high,"velocity":water.velocity})
|
||||
edges.append(low);edges.append(high)
|
||||
edges.sort()
|
||||
for i in range(edges.size()-1):
|
||||
var length: float=edges[i+1]-edges[i]
|
||||
if length<=0:continue
|
||||
var midpoint: float=(edges[i+1]+edges[i])*.5
|
||||
var velocity:=Vector3.ZERO;var count:=0
|
||||
for interval in intervals:
|
||||
if midpoint>=interval.low and midpoint<interval.high:
|
||||
velocity+=interval.velocity;count+=1
|
||||
if count>0:
|
||||
immersed+=length;flow+=velocity/count*length
|
||||
return {"fraction":clampf(immersed/total,0,1),"velocity":flow/immersed if immersed>0 else Vector3.ZERO}
|
||||
Reference in New Issue
Block a user