(renderable: Renderable, shapes: BodyShape[])
| 584 | } |
| 585 | |
| 586 | updateShape(renderable: Renderable, shapes: BodyShape[]): void { |
| 587 | // matter-js doesn't support live shape mutation cleanly — the |
| 588 | // pragmatic approach is to rebuild the body. Preserve the prior |
| 589 | // def, swap shapes, re-register — AND carry forward the velocity |
| 590 | // state (linear + angular) so a moving body whose shape changes |
| 591 | // mid-flight doesn't stop dead. |
| 592 | const oldDef = this.defMap.get(renderable); |
| 593 | if (!oldDef) { |
| 594 | return; |
| 595 | } |
| 596 | const oldBody = this.bodyMap.get(renderable); |
| 597 | const savedVel = oldBody |
| 598 | ? { x: oldBody.velocity.x, y: oldBody.velocity.y } |
| 599 | : undefined; |
| 600 | const savedAngVel = oldBody?.angularVelocity ?? 0; |
| 601 | this.removeBody(renderable); |
| 602 | const newBody = this.addBody(renderable, { ...oldDef, shapes }); |
| 603 | if (savedVel) { |
| 604 | Matter.Body.setVelocity(newBody, savedVel); |
| 605 | Matter.Body.setAngularVelocity(newBody, savedAngVel); |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | getVelocity(renderable: Renderable, out?: Vector2d): Vector2d { |
| 610 | const body = this.bodyMap.get(renderable); |
nothing calls this directly
no test coverage detected