no message
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
# MsaMotion —— 读 .msa 文本里的根运动:移动动作每秒位移(cm/s,movSpd 100 时)。
|
||||
#
|
||||
# MotionDuration 0.600000
|
||||
# Accumulation 0.00 -255.45 0.00
|
||||
#
|
||||
# 服务端 CHARACTER::GetMoveMotionSpeed = -Accumulation.y / MotionDuration;
|
||||
# 客户端 CActorInstance::AccumulationMovement 按同一累计量推进。这里取 xy 长度。
|
||||
extends RefCounted
|
||||
|
||||
static var _cache := {} # path -> float
|
||||
|
||||
static func move_speed(path: String) -> float:
|
||||
if path == "" or not path.to_lower().ends_with(".msa"):
|
||||
return 0.0
|
||||
if _cache.has(path):
|
||||
return float(_cache[path])
|
||||
var speed := 0.0
|
||||
var f := FileAccess.open(path, FileAccess.READ)
|
||||
if f:
|
||||
var duration := 0.0
|
||||
var accum := Vector2.ZERO
|
||||
while not f.eof_reached():
|
||||
var parts := _fields(f.get_line())
|
||||
if parts.size() < 2:
|
||||
continue
|
||||
match String(parts[0]):
|
||||
"MotionDuration":
|
||||
duration = String(parts[1]).to_float()
|
||||
"Accumulation":
|
||||
if parts.size() >= 3:
|
||||
accum = Vector2(String(parts[1]).to_float(), String(parts[2]).to_float())
|
||||
if duration > 0.0:
|
||||
speed = accum.length() / duration
|
||||
_cache[path] = speed
|
||||
return speed
|
||||
|
||||
static func _fields(line: String) -> PackedStringArray:
|
||||
return line.strip_edges().replace("\t", " ").split(" ", false)
|
||||
Reference in New Issue
Block a user