improve position fixing

This commit is contained in:
2025-01-11 18:17:44 +09:00
parent f1c191f61f
commit 4aba510ec0
8 changed files with 117 additions and 34 deletions
+13
View File
@@ -1,3 +1,4 @@
import QuickHull from 'quickhull' // DEPRECATED: hulls were a failed concept for position fixing
import SAT from 'sat'
import { Shape, ShapeUtils, Vector2 } from 'three'
@@ -8,6 +9,7 @@ export default class Terrain {
relativeVertices = []
#colliders = []
#hull = null
#vertices = []
#unadjustedWaypoints = []
@@ -24,6 +26,7 @@ export default class Terrain {
}
get colliders() { return this.#colliders }
get hull() { return this.#hull } // DEPRECATED: hulls were a failed concept for position fixing
get unadjustedWaypoints() { return this.#unadjustedWaypoints }
get vertices() { return this.#vertices }
@@ -73,6 +76,16 @@ export default class Terrain {
}
this.#colliders = ShapeUtils.triangulateShape(points.shape, points.holes).map(indicesToPolygon)
this.#calculateHull()
}
// DEPRECATED: hulls were a failed concept for position fixing
#calculateHull() {
const vertices = QuickHull(this.#vertices.map((v) => ({ x: v.x, y: v.y }))).map((v) => new Vector2(v.x, v.y))
const first = vertices.at(0)
const satPoints = [new SAT.Vector(...first.toArray()), ...vertices.slice(1).map((v) => new SAT.Vector(...v.clone(first).sub(first).toArray()))]
this.#hull = new SAT.Polygon(satPoints[0], [new SAT.Vector(), ...satPoints.slice(1)])
}
#calculatePosition() {