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