spine资源引入

This commit is contained in:
tianmo committed 2026-08-29 03:10:16 +08:00
1 parent 166b5015c2
commit 5f4667f736
25 files changed
+31151 -9082

No files matched your search

+22 -8
View File
@@ -23,6 +23,8 @@ export interface SceneCollider {
x: number
y: number
rotation: number
scaleX: number
scaleY: number
radius: number
radiusX: number
radiusY: number
@@ -1590,15 +1592,27 @@ type ColliderHit = { x: number; y: number; nx: number; ny: number }
function resolveColliderPoint(collider: SceneCollider, worldX: number, worldY: number): ColliderHit | null {
const angle = collider.rotation * Math.PI / 180
const cos = Math.cos(angle), sin = Math.sin(angle)
const scaleX = Math.max(0.0001, Math.abs(collider.scaleX ?? 1))
const scaleY = Math.max(0.0001, Math.abs(collider.scaleY ?? 1))
const dx = worldX - collider.x, dy = worldY - collider.y
const localX = cos * dx + sin * dy
const localY = -sin * dx + cos * dy
const toWorld = (x: number, y: number, nx: number, ny: number): ColliderHit => ({
x: collider.x + cos * x - sin * y + (cos * nx - sin * ny) * 0.05,
y: collider.y + sin * x + cos * y + (sin * nx + cos * ny) * 0.05,
nx: cos * nx - sin * ny,
ny: sin * nx + cos * ny,
})
const localX = (cos * dx + sin * dy) / scaleX
const localY = (-sin * dx + cos * dy) / scaleY
const toWorld = (x: number, y: number, nx: number, ny: number): ColliderHit => {
// 非等比缩放下,法线使用逆转置缩放后再旋转,保证反弹方向正确。
const scaledNormalX = nx / scaleX
const scaledNormalY = ny / scaleY
const normalLength = Math.max(0.0001, Math.hypot(scaledNormalX, scaledNormalY))
const localNormalX = scaledNormalX / normalLength
const localNormalY = scaledNormalY / normalLength
const worldNormalX = cos * localNormalX - sin * localNormalY
const worldNormalY = sin * localNormalX + cos * localNormalY
return {
x: collider.x + cos * x * scaleX - sin * y * scaleY + worldNormalX * 0.05,
y: collider.y + sin * x * scaleX + cos * y * scaleY + worldNormalY * 0.05,
nx: worldNormalX,
ny: worldNormalY,
}
}
if (collider.shape === 'circle') {
const radius = Math.max(0.001, collider.radius)
const distance = Math.hypot(localX, localY)