better default agent props & speed & position numeric, not strings
This commit is contained in:
@@ -38,14 +38,31 @@ class KeyframesModel extends WindozModel {
|
||||
)
|
||||
}
|
||||
|
||||
#normalizeAxisVector(vec) {
|
||||
if(!vec || typeof(vec) !== 'object') return(null)
|
||||
const axes = ['x', 'y', 'z']
|
||||
const out = {}
|
||||
for(const axis of axes) {
|
||||
const n = Number(vec[axis])
|
||||
if(!Number.isFinite(n)) return(null)
|
||||
out[axis] = n
|
||||
}
|
||||
return(out)
|
||||
}
|
||||
|
||||
async save(kfId, data) {
|
||||
const kfData = Object.keys(data).map(aid => {
|
||||
const { position, speed, ...storeValues} = data[aid].values
|
||||
const gpsPosition = this.#normalizeAxisVector(position)
|
||||
const gpsSpeed = this.#normalizeAxisVector(speed)
|
||||
if(!gpsPosition || !gpsSpeed) {
|
||||
throw(new Error(`Agent ${aid}: position and speed must be numeric vectors`))
|
||||
}
|
||||
return({
|
||||
aid: aid,
|
||||
type: data[aid].type,
|
||||
storeValues: storeValues,
|
||||
gpsValues: { position: data[aid].values.position, speed: data[aid].values.speed }
|
||||
gpsValues: { position: gpsPosition, speed: gpsSpeed },
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user