|
|
@ -13,7 +13,6 @@ class PhysicsWorker extends PhysicsBase { |
|
|
|
nodeIds: [], |
|
|
|
edgeIds: [] |
|
|
|
}; |
|
|
|
this.physicsTimeout = null; |
|
|
|
this.isWorker = true; |
|
|
|
this.emit = (event, data) => {this.postMessage({type: 'emit', data: {event: event, data: data}})}; |
|
|
|
} |
|
|
@ -24,7 +23,7 @@ class PhysicsWorker extends PhysicsBase { |
|
|
|
case 'physicsTick': |
|
|
|
this.processRemovals(); |
|
|
|
this.physicsTick(); |
|
|
|
this.sendPositions(); |
|
|
|
this.sendTickResults(); |
|
|
|
break; |
|
|
|
case 'updatePositions': |
|
|
|
this.receivePositions(msg.data); |
|
|
@ -44,6 +43,10 @@ class PhysicsWorker extends PhysicsBase { |
|
|
|
case 'setStabilized': |
|
|
|
this.stabilized = msg.data; |
|
|
|
break; |
|
|
|
case 'stabilized': |
|
|
|
this.startedStabilization = false; |
|
|
|
this.stabilizationIterations = 0; |
|
|
|
break; |
|
|
|
case 'initPhysicsData': |
|
|
|
console.debug('init physics data'); |
|
|
|
this.initPhysicsData(msg.data); |
|
|
@ -58,7 +61,7 @@ class PhysicsWorker extends PhysicsBase { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sendPositions() { |
|
|
|
sendTickResults() { |
|
|
|
let nodeIndices = this.physicsBody.physicsNodeIndices; |
|
|
|
let positions = {}; |
|
|
|
for (let i = 0; i < nodeIndices.length; i++) { |
|
|
@ -68,10 +71,11 @@ class PhysicsWorker extends PhysicsBase { |
|
|
|
} |
|
|
|
|
|
|
|
this.postMessage({ |
|
|
|
type: 'positions', |
|
|
|
type: 'tickResults', |
|
|
|
data: { |
|
|
|
positions: positions, |
|
|
|
stabilized: this.stabilized |
|
|
|
stabilized: this.stabilized, |
|
|
|
stabilizationIterations: this.stabilizationIterations |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
@ -254,12 +258,9 @@ class PhysicsWorker extends PhysicsBase { |
|
|
|
} |
|
|
|
|
|
|
|
_finalizeStabilization() { |
|
|
|
this.sendPositions(); |
|
|
|
this.sendTickResults(); |
|
|
|
this.postMessage({ |
|
|
|
type: 'finalizeStabilization', |
|
|
|
data: { |
|
|
|
stabilizationIterations: this.stabilizationIterations |
|
|
|
} |
|
|
|
type: 'finalizeStabilization' |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|