diff --git a/packages/avatar/src/AvatarImage.ts b/packages/avatar/src/AvatarImage.ts index 4cc52cf..6f7e92b 100644 --- a/packages/avatar/src/AvatarImage.ts +++ b/packages/avatar/src/AvatarImage.ts @@ -293,6 +293,13 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener clear: true }); + for(const child of container.children) + { + child.removeChildren(); + } + + container.destroy({ children: true }); + //@ts-ignore this._activeTexture.source.hitMap = null; diff --git a/packages/room/src/object/visualization/avatar/AvatarVisualization.ts b/packages/room/src/object/visualization/avatar/AvatarVisualization.ts index ff2323e..ff2cbf6 100644 --- a/packages/room/src/object/visualization/avatar/AvatarVisualization.ts +++ b/packages/room/src/object/visualization/avatar/AvatarVisualization.ts @@ -1101,14 +1101,19 @@ export class AvatarVisualization extends RoomObjectSpriteVisualization implement if(oppositeDirection !== currentDirection) { - const highlightEnabled = ((this.object.model.getValue(RoomObjectVariable.FIGURE_HIGHLIGHT_ENABLE) === 1) && (this.object.model.getValue(RoomObjectVariable.FIGURE_HIGHLIGHT) === 1)); - - this._avatarImage.setDirection(AvatarSetType.FULL, oppositeDirection); - - const renderedOpposite = (this._avatarImage.processAsTexture(AvatarSetType.FULL, highlightEnabled) || sprite.texture); - - if((this._reflectionOppositeDirection !== currentDirection) || (this._reflectionOppositeBaseTexture !== sprite.texture) || !this._reflectionOppositeTexture) + // Reuse the cached opposite texture if direction and base texture haven't changed + if(this._reflectionOppositeTexture && (this._reflectionOppositeDirection === currentDirection) && (this._reflectionOppositeBaseTexture === sprite.texture)) { + oppositeTexture = this._reflectionOppositeTexture; + } + else + { + const highlightEnabled = ((this.object.model.getValue(RoomObjectVariable.FIGURE_HIGHLIGHT_ENABLE) === 1) && (this.object.model.getValue(RoomObjectVariable.FIGURE_HIGHLIGHT) === 1)); + + this._avatarImage.setDirection(AvatarSetType.FULL, oppositeDirection); + + const renderedOpposite = (this._avatarImage.processAsTexture(AvatarSetType.FULL, highlightEnabled) || sprite.texture); + if(this._reflectionOppositeTexture) { this._reflectionOppositeTexture.destroy(true); @@ -1118,15 +1123,15 @@ export class AvatarVisualization extends RoomObjectSpriteVisualization implement this._reflectionOppositeTexture = this.cloneTexture(renderedOpposite); this._reflectionOppositeDirection = currentDirection; this._reflectionOppositeBaseTexture = sprite.texture; + + oppositeTexture = (this._reflectionOppositeTexture || renderedOpposite); + + // Restore the live avatar direction and refresh the current texture so + // movement updates do not keep showing the opposite-facing texture. + this._avatarImage.setDirection(AvatarSetType.FULL, currentDirection); + + sprite.texture = (this._avatarImage.processAsTexture(AvatarSetType.FULL, highlightEnabled) || sprite.texture); } - - oppositeTexture = (this._reflectionOppositeTexture || renderedOpposite); - - // Restore the live avatar direction and refresh the current texture so - // movement updates do not keep showing the opposite-facing texture. - this._avatarImage.setDirection(AvatarSetType.FULL, currentDirection); - - sprite.texture = (this._avatarImage.processAsTexture(AvatarSetType.FULL, highlightEnabled) || sprite.texture); } } diff --git a/packages/room/src/object/visualization/room/RoomPlane.ts b/packages/room/src/object/visualization/room/RoomPlane.ts index 3556447..116bdd4 100644 --- a/packages/room/src/object/visualization/room/RoomPlane.ts +++ b/packages/room/src/object/visualization/room/RoomPlane.ts @@ -741,6 +741,7 @@ export class RoomPlane implements IRoomPlane }); animationCanvas.destroy(true); + animContainer.destroy({ children: true }); } private renderLandscapeLayer(texture: Texture, tint: number, alignBottom: boolean): void @@ -798,7 +799,7 @@ export class RoomPlane implements IRoomPlane clear: false }); - layerSprite.destroy(); + layerContainer.destroy({ children: true }); } private renderBackgroundColor(): void @@ -826,7 +827,7 @@ export class RoomPlane implements IRoomPlane clear: true }); - colorGraphics.destroy(); + colorContainer.destroy({ children: true }); } private clearPlaneTexture(): void @@ -838,12 +839,16 @@ export class RoomPlane implements IRoomPlane if(canvasWidth <= 0 || canvasHeight <= 0) { + const emptyContainer = new Container(); + GetRenderer().render({ target: this._planeTexture, - container: new Container(), + container: emptyContainer, clear: true }); + emptyContainer.destroy(); + return; } @@ -863,7 +868,7 @@ export class RoomPlane implements IRoomPlane clear: true }); - colorGraphics.destroy(); + colorContainer.destroy({ children: true }); } private renderWindowReflections(): void diff --git a/packages/room/src/object/visualization/room/animated/PlaneVisualizationAnimationLayer.ts b/packages/room/src/object/visualization/room/animated/PlaneVisualizationAnimationLayer.ts index 169650e..aac9ee8 100644 --- a/packages/room/src/object/visualization/room/animated/PlaneVisualizationAnimationLayer.ts +++ b/packages/room/src/object/visualization/room/animated/PlaneVisualizationAnimationLayer.ts @@ -154,5 +154,6 @@ export class PlaneVisualizationAnimationLayer const sprite = new Sprite(item.bitmapData.texture); sprite.position.set(x, y); TextureUtils.writeToTexture(sprite, canvas, false); + sprite.destroy(); } }