diff --git a/packages/api/src/nitro/avatar/IAvatarImage.ts b/packages/api/src/nitro/avatar/IAvatarImage.ts index 72ce55e..c0ad032 100644 --- a/packages/api/src/nitro/avatar/IAvatarImage.ts +++ b/packages/api/src/nitro/avatar/IAvatarImage.ts @@ -17,6 +17,7 @@ export interface IAvatarImage processAsImageUrl(setType: string): string; processAsContainer(setType: string): Container; getDirection(): number; + getDirectionOffset(): number; getFigure(): IAvatarFigureContainer; getPartColor(_arg_1: string): IPartColor; getMainAction(): IActiveActionData; diff --git a/packages/avatar/src/AvatarImage.ts b/packages/avatar/src/AvatarImage.ts index 27b17e4..b34d1e5 100644 --- a/packages/avatar/src/AvatarImage.ts +++ b/packages/avatar/src/AvatarImage.ts @@ -399,6 +399,11 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener return this._mainDirection; } + public getDirectionOffset(): number + { + return this._directionOffset; + } + public initActionAppends(): void { this._actions = []; diff --git a/packages/room/src/object/visualization/avatar/AvatarVisualization.ts b/packages/room/src/object/visualization/avatar/AvatarVisualization.ts index 99643e6..4831392 100644 --- a/packages/room/src/object/visualization/avatar/AvatarVisualization.ts +++ b/packages/room/src/object/visualization/avatar/AvatarVisualization.ts @@ -1104,17 +1104,19 @@ export class AvatarVisualization extends RoomObjectSpriteVisualization implement if(sprite?.texture) { - const currentDirection = this._avatarImage?.getDirection(); + const displayedDirection = this._avatarImage?.getDirection(); + const directionOffset = this._avatarImage?.getDirectionOffset() ?? 0; let oppositeTexture = sprite.texture; - if((currentDirection !== undefined) && this._avatarImage) + if((displayedDirection !== undefined) && this._avatarImage) { - const oppositeDirection = ((currentDirection + 4) % 8); + const rawCurrent = ((displayedDirection - directionOffset) % 8 + 8) % 8; + const rawOpposite = (rawCurrent + 4) % 8; + const displayedOpposite = (displayedDirection + 4) % 8; - if(oppositeDirection !== currentDirection) + if(displayedOpposite !== displayedDirection) { - // Reuse the cached opposite texture if direction and base texture haven't changed - if(this._reflectionOppositeTexture && (this._reflectionOppositeDirection === currentDirection) && (this._reflectionOppositeBaseTexture === sprite.texture)) + if(this._reflectionOppositeTexture && (this._reflectionOppositeDirection === displayedDirection) && (this._reflectionOppositeBaseTexture === sprite.texture)) { oppositeTexture = this._reflectionOppositeTexture; } @@ -1122,7 +1124,7 @@ export class AvatarVisualization extends RoomObjectSpriteVisualization implement { 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); + this._avatarImage.setDirection(AvatarSetType.FULL, rawOpposite); const renderedOpposite = (this._avatarImage.processAsTexture(AvatarSetType.FULL, highlightEnabled) || sprite.texture); @@ -1133,14 +1135,10 @@ export class AvatarVisualization extends RoomObjectSpriteVisualization implement } this._reflectionOppositeTexture = this.cloneTexture(renderedOpposite); - this._reflectionOppositeDirection = currentDirection; + this._reflectionOppositeDirection = displayedDirection; 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); + this._avatarImage.setDirection(AvatarSetType.FULL, rawCurrent); sprite.texture = (this._avatarImage.processAsTexture(AvatarSetType.FULL, highlightEnabled) || sprite.texture); }