mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2024-11-22 23:50:52 +01:00
Various avatar updates
This commit is contained in:
parent
2a7e7e8864
commit
76af91a69b
@ -1,6 +1,4 @@
|
||||
import { IDisposable } from '../../common';
|
||||
|
||||
export interface IAvatarEffectListener extends IDisposable
|
||||
export interface IAvatarEffectListener
|
||||
{
|
||||
resetEffect(effect: number): void;
|
||||
}
|
||||
|
@ -1,23 +1,20 @@
|
||||
import { Sprite, Texture } from 'pixi.js';
|
||||
import { IGraphicAsset } from '../../asset';
|
||||
import { IDisposable } from '../../common';
|
||||
import { Container, Texture } from 'pixi.js';
|
||||
import { IAvatarFigureContainer } from './IAvatarFigureContainer';
|
||||
import { IAnimationLayerData, IAvatarDataContainer, ISpriteDataContainer } from './animation';
|
||||
import { IAnimationLayerData, ISpriteDataContainer } from './animation';
|
||||
import { IPartColor } from './structure';
|
||||
|
||||
export interface IAvatarImage extends IDisposable
|
||||
export interface IAvatarImage
|
||||
{
|
||||
getServerRenderData(): any;
|
||||
dispose(): void;
|
||||
setDirection(_arg_1: string, _arg_2: number): void;
|
||||
setDirectionAngle(_arg_1: string, _arg_2: number): void;
|
||||
updateAnimationByFrames(_arg_1?: number): void;
|
||||
getScale(): string;
|
||||
getSprites(): ISpriteDataContainer[];
|
||||
getLayerData(_arg_1: ISpriteDataContainer): IAnimationLayerData;
|
||||
getImage(setType: string, hightlight: boolean, scale?: number, cache?: boolean): Texture;
|
||||
getImageAsSprite(setType: string, scale?: number): Sprite;
|
||||
getCroppedImageUrl(setType: string, scale?: number): Promise<string>;
|
||||
getAsset(_arg_1: string): IGraphicAsset;
|
||||
processAsTexture(setType: string, hightlight: boolean, texture?: Texture): Texture;
|
||||
processAsImageUrl(setType: string): string;
|
||||
processAsContainer(setType: string): Container;
|
||||
getDirection(): number;
|
||||
getFigure(): IAvatarFigureContainer;
|
||||
getPartColor(_arg_1: string): IPartColor;
|
||||
@ -26,10 +23,7 @@ export interface IAvatarImage extends IDisposable
|
||||
initActionAppends(): void;
|
||||
endActionAppends(): void;
|
||||
appendAction(_arg_1: string, ..._args: any[]): boolean;
|
||||
avatarSpriteData: IAvatarDataContainer;
|
||||
isPlaceholder(): boolean;
|
||||
forceActionUpdate(): void;
|
||||
animationHasResetOnToggle: boolean;
|
||||
resetAnimationFrameCounter(): void;
|
||||
mainAction: string;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -16,10 +16,10 @@ export class ActionDefinition implements IActionDefinition
|
||||
private _startFromFrameZero: boolean;
|
||||
private _prevents: string[];
|
||||
private _preventHeadTurn: boolean;
|
||||
private _types: Map<number, ActionType>;
|
||||
private _params: Map<string, string>;
|
||||
private _defaultParameterValue: string;
|
||||
private _canvasOffsets: Map<string, Map<number, number[]>>;
|
||||
private _types: Map<number, ActionType> = new Map();
|
||||
private _params: Map<string, string> = new Map();
|
||||
private _defaultParameterValue: string = '';
|
||||
private _canvasOffsets: Map<string, Map<number, number[]>> = new Map();
|
||||
|
||||
constructor(data: any)
|
||||
{
|
||||
@ -36,10 +36,6 @@ export class ActionDefinition implements IActionDefinition
|
||||
this._startFromFrameZero = data.startFromFrameZero || false;
|
||||
this._prevents = data.prevents || [];
|
||||
this._preventHeadTurn = data.preventHeadTurn || false;
|
||||
this._types = new Map();
|
||||
this._params = new Map();
|
||||
this._defaultParameterValue = '';
|
||||
this._canvasOffsets = null;
|
||||
|
||||
if(data.params && (data.params.length > 0))
|
||||
{
|
||||
|
205
packages/avatar/src/cache/AvatarImageCache.ts
vendored
205
packages/avatar/src/cache/AvatarImageCache.ts
vendored
@ -1,4 +1,4 @@
|
||||
import { AvatarDirectionAngle, AvatarFigurePartType, AvatarScaleType, GeometryType, IActiveActionData, IAvatarImage, RoomObjectSpriteData } from '@nitrots/api';
|
||||
import { AvatarDirectionAngle, AvatarFigurePartType, AvatarScaleType, GeometryType, IActiveActionData, IAvatarImage } from '@nitrots/api';
|
||||
import { GetTickerTime } from '@nitrots/utils';
|
||||
import { Container, Matrix, Point, Rectangle, Sprite, Texture } from 'pixi.js';
|
||||
import { AvatarImageBodyPartContainer } from '../AvatarImageBodyPartContainer';
|
||||
@ -26,7 +26,6 @@ export class AvatarImageCache
|
||||
private _geometryType: string;
|
||||
private _unionImages: ImageData[];
|
||||
private _matrix: Matrix;
|
||||
private _serverRenderData: RoomObjectSpriteData[];
|
||||
|
||||
constructor(k: AvatarStructure, _arg_2: IAvatarImage, _arg_3: AssetAliasCollection, _arg_4: string)
|
||||
{
|
||||
@ -39,7 +38,6 @@ export class AvatarImageCache
|
||||
this._disposed = false;
|
||||
this._unionImages = [];
|
||||
this._matrix = new Matrix();
|
||||
this._serverRenderData = [];
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
@ -152,129 +150,91 @@ export class AvatarImageCache
|
||||
this._canvas = null;
|
||||
}
|
||||
|
||||
public getImageContainer(k: string, frameNumber: number, _arg_3: boolean = false): AvatarImageBodyPartContainer
|
||||
public getImageContainer(key: string, frameNumber: number, forceRefresh: boolean = false): AvatarImageBodyPartContainer
|
||||
{
|
||||
let _local_4 = this.getBodyPartCache(k);
|
||||
const bodyPartCache = this.getBodyPartCache(key) || new AvatarImageBodyPartCache();
|
||||
|
||||
if(!_local_4)
|
||||
this._cache.set(key, bodyPartCache);
|
||||
|
||||
let direction = bodyPartCache.getDirection();
|
||||
let action = bodyPartCache.getAction();
|
||||
let adjustedFrameCount = frameNumber;
|
||||
|
||||
if(action.definition.startFromFrameZero) adjustedFrameCount -= action.startFrame;
|
||||
|
||||
let adjustedAction = action;
|
||||
let removeData: string[] = [];
|
||||
let items: Map<string, string> = new Map();
|
||||
|
||||
const positionOffset = new Point();
|
||||
|
||||
if(action.definition.isAnimation)
|
||||
{
|
||||
_local_4 = new AvatarImageBodyPartCache();
|
||||
let adjustedDirection = direction;
|
||||
|
||||
this._cache.set(k, _local_4);
|
||||
}
|
||||
const animation = this._structure.getAnimation(((action.definition.state + '.') + action.actionParameter));
|
||||
const animationFrameOffset = (frameNumber - action.startFrame);
|
||||
|
||||
let _local_5 = _local_4.getDirection();
|
||||
let _local_7 = _local_4.getAction();
|
||||
let frameCount = frameNumber;
|
||||
|
||||
if(_local_7.definition.startFromFrameZero) frameCount -= _local_7.startFrame;
|
||||
|
||||
let _local_8 = _local_7;
|
||||
let _local_9: string[] = [];
|
||||
let _local_10: Map<string, string> = new Map();
|
||||
const _local_11 = new Point();
|
||||
|
||||
if(!((!(_local_7)) || (!(_local_7.definition))))
|
||||
{
|
||||
if(_local_7.definition.isAnimation)
|
||||
if(animation)
|
||||
{
|
||||
let _local_15 = _local_5;
|
||||
const layerData = animation.getLayerData(animationFrameOffset, key, action.overridingAction);
|
||||
|
||||
const _local_16 = this._structure.getAnimation(((_local_7.definition.state + '.') + _local_7.actionParameter));
|
||||
const _local_17 = (frameNumber - _local_7.startFrame);
|
||||
|
||||
if(_local_16)
|
||||
if(layerData)
|
||||
{
|
||||
const _local_18 = _local_16.getLayerData(_local_17, k, _local_7.overridingAction);
|
||||
adjustedDirection = (direction + layerData.dd + 8) % 8;
|
||||
|
||||
if(_local_18)
|
||||
positionOffset.x = this._scale === AvatarScaleType.LARGE ? layerData.dx : layerData.dx / 2;
|
||||
positionOffset.y = this._scale === AvatarScaleType.LARGE ? layerData.dy : layerData.dy / 2;
|
||||
|
||||
adjustedFrameCount = layerData.animationFrame;
|
||||
|
||||
if(layerData.action) action = layerData.action;
|
||||
|
||||
if(layerData.type === AvatarAnimationLayerData.BODYPART)
|
||||
{
|
||||
_local_15 = (_local_5 + _local_18.dd);
|
||||
if(layerData.action) adjustedAction = layerData.action;
|
||||
|
||||
if(_local_18.dd < 0)
|
||||
{
|
||||
if(_local_15 < 0)
|
||||
{
|
||||
_local_15 = (8 + _local_15);
|
||||
}
|
||||
else if(_local_15 > 7) _local_15 = (8 - _local_15);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_local_15 < 0)
|
||||
{
|
||||
_local_15 = (_local_15 + 8);
|
||||
}
|
||||
else if(_local_15 > 7) _local_15 = (_local_15 - 8);
|
||||
}
|
||||
|
||||
if(this._scale === AvatarScaleType.LARGE)
|
||||
{
|
||||
_local_11.x = _local_18.dx;
|
||||
_local_11.y = _local_18.dy;
|
||||
}
|
||||
else
|
||||
{
|
||||
_local_11.x = (_local_18.dx / 2);
|
||||
_local_11.y = (_local_18.dy / 2);
|
||||
}
|
||||
|
||||
frameCount = _local_18.animationFrame;
|
||||
|
||||
if(_local_18.action)
|
||||
{
|
||||
_local_7 = _local_18.action;
|
||||
}
|
||||
|
||||
if(_local_18.type === AvatarAnimationLayerData.BODYPART)
|
||||
{
|
||||
if(_local_18.action != null)
|
||||
{
|
||||
_local_8 = _local_18.action;
|
||||
}
|
||||
|
||||
_local_5 = _local_15;
|
||||
}
|
||||
else if(_local_18.type === AvatarAnimationLayerData.FX) _local_5 = _local_15;
|
||||
|
||||
_local_10 = _local_18.items;
|
||||
direction = adjustedDirection;
|
||||
}
|
||||
else if(layerData.type === AvatarAnimationLayerData.FX) direction = adjustedDirection;
|
||||
|
||||
_local_9 = _local_16.removeData;
|
||||
items = layerData.items;
|
||||
}
|
||||
|
||||
removeData = animation.removeData;
|
||||
}
|
||||
}
|
||||
|
||||
let _local_12 = _local_4.getActionCache(_local_8);
|
||||
let actionCache = bodyPartCache.getActionCache(adjustedAction);
|
||||
|
||||
if(!_local_12 || _arg_3)
|
||||
if(!actionCache || forceRefresh)
|
||||
{
|
||||
_local_12 = new AvatarImageActionCache();
|
||||
_local_4.updateActionCache(_local_8, _local_12);
|
||||
actionCache = new AvatarImageActionCache();
|
||||
bodyPartCache.updateActionCache(adjustedAction, actionCache);
|
||||
}
|
||||
|
||||
let _local_13 = _local_12.getDirectionCache(_local_5);
|
||||
let directionCache = actionCache.getDirectionCache(direction);
|
||||
|
||||
if(!_local_13 || _arg_3)
|
||||
if(!directionCache || forceRefresh)
|
||||
{
|
||||
const _local_19 = this._structure.getParts(k, this._avatar.getFigure(), _local_8, this._geometryType, _local_5, _local_9, this._avatar, _local_10);
|
||||
const partList = this._structure.getParts(key, this._avatar.getFigure(), adjustedAction, this._geometryType, direction, removeData, this._avatar, items);
|
||||
|
||||
_local_13 = new AvatarImageDirectionCache(_local_19);
|
||||
directionCache = new AvatarImageDirectionCache(partList);
|
||||
|
||||
_local_12.updateDirectionCache(_local_5, _local_13);
|
||||
actionCache.updateDirectionCache(direction, directionCache);
|
||||
}
|
||||
|
||||
let _local_14 = _local_13.getImageContainer(frameCount);
|
||||
let imageContainer = directionCache.getImageContainer(adjustedFrameCount);
|
||||
|
||||
if(!_local_14 || _arg_3)
|
||||
if(!imageContainer || forceRefresh)
|
||||
{
|
||||
const _local_20 = _local_13.getPartList();
|
||||
const partList = directionCache.getPartList();
|
||||
|
||||
_local_14 = this.renderBodyPart(_local_5, _local_20, frameCount, _local_7, _arg_3);
|
||||
imageContainer = this.renderBodyPart(direction, partList, adjustedFrameCount, action);
|
||||
|
||||
if(_local_14 && !_arg_3)
|
||||
if(imageContainer && !forceRefresh)
|
||||
{
|
||||
if(_local_14.isCacheable) _local_13.updateImageContainer(_local_14, frameCount);
|
||||
if(imageContainer.isCacheable) directionCache.updateImageContainer(imageContainer, adjustedFrameCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -282,21 +242,14 @@ export class AvatarImageCache
|
||||
}
|
||||
}
|
||||
|
||||
const offset = this._structure.getFrameBodyPartOffset(_local_8, _local_5, frameCount, k);
|
||||
const offset = this._structure.getFrameBodyPartOffset(adjustedAction, direction, adjustedFrameCount, key);
|
||||
|
||||
_local_11.x += offset.x;
|
||||
_local_11.y += offset.y;
|
||||
positionOffset.x += offset.x;
|
||||
positionOffset.y += offset.y;
|
||||
|
||||
_local_14.offset = _local_11;
|
||||
imageContainer.offset = positionOffset;
|
||||
|
||||
return _local_14;
|
||||
}
|
||||
|
||||
public getServerRenderData(): any[]
|
||||
{
|
||||
this._serverRenderData = [];
|
||||
|
||||
return this._serverRenderData;
|
||||
return imageContainer;
|
||||
}
|
||||
|
||||
public getBodyPartCache(k: string): AvatarImageBodyPartCache
|
||||
@ -313,7 +266,7 @@ export class AvatarImageCache
|
||||
return existing;
|
||||
}
|
||||
|
||||
private renderBodyPart(direction: number, containers: AvatarImagePartContainer[], frameCount: number, _arg_4: IActiveActionData, renderServerData: boolean = false): AvatarImageBodyPartContainer
|
||||
private renderBodyPart(direction: number, containers: AvatarImagePartContainer[], frameCount: number, action: IActiveActionData): AvatarImageBodyPartContainer
|
||||
{
|
||||
if(!containers || !containers.length) return null;
|
||||
|
||||
@ -325,7 +278,7 @@ export class AvatarImageCache
|
||||
}
|
||||
|
||||
const isFlipped = AvatarDirectionAngle.DIRECTION_IS_FLIPPED[direction] || false;
|
||||
let assetPartDefinition = _arg_4.definition.assetPartDefinition;
|
||||
let assetPartDefinition = action.definition.assetPartDefinition;
|
||||
let isCacheable = true;
|
||||
let containerIndex = (containers.length - 1);
|
||||
|
||||
@ -397,33 +350,6 @@ export class AvatarImageCache
|
||||
|
||||
if(flipH) offset.x = (offset.x + ((this._scale === AvatarScaleType.LARGE) ? 65 : 31));
|
||||
|
||||
if(renderServerData)
|
||||
{
|
||||
const spriteData = new RoomObjectSpriteData();
|
||||
|
||||
spriteData.name = this._assets.getAssetName(assetName);
|
||||
spriteData.x = (-(offset.x) - 33);
|
||||
spriteData.y = -(offset.y);
|
||||
spriteData.z = (this._serverRenderData.length * -0.0001);
|
||||
spriteData.width = asset.rectangle.width;
|
||||
spriteData.height = asset.rectangle.height;
|
||||
spriteData.flipH = flipH;
|
||||
|
||||
if(assetPartDefinition === 'lay') spriteData.x = (spriteData.x + 53);
|
||||
|
||||
if(isFlipped)
|
||||
{
|
||||
spriteData.flipH = (!(spriteData.flipH));
|
||||
|
||||
if(spriteData.flipH) spriteData.x = (-(spriteData.x) - texture.width);
|
||||
else spriteData.x = (spriteData.x + 65);
|
||||
}
|
||||
|
||||
if(container.isColorable) spriteData.color = `${color}`;
|
||||
|
||||
this._serverRenderData.push(spriteData);
|
||||
}
|
||||
|
||||
this._unionImages.push(new ImageData(texture, asset.rectangle, offset, flipH, color));
|
||||
}
|
||||
}
|
||||
@ -485,9 +411,6 @@ export class AvatarImageCache
|
||||
{
|
||||
if(!data) continue;
|
||||
|
||||
const texture = data.texture;
|
||||
const color = data.colorTransform;
|
||||
const flipH = (!(isFlipped && data.flipH) && (isFlipped || data.flipH));
|
||||
const regPoint = point.clone();
|
||||
|
||||
regPoint.x -= data.regPoint.x;
|
||||
@ -495,7 +418,7 @@ export class AvatarImageCache
|
||||
|
||||
if(isFlipped) regPoint.x = (container.width - (regPoint.x + data.rect.width));
|
||||
|
||||
if(flipH)
|
||||
if(isFlipped != data.flipH)
|
||||
{
|
||||
this._matrix.a = -1;
|
||||
this._matrix.tx = ((data.rect.x + data.rect.width) + regPoint.x);
|
||||
@ -508,9 +431,9 @@ export class AvatarImageCache
|
||||
this._matrix.ty = (regPoint.y - data.rect.y);
|
||||
}
|
||||
|
||||
const sprite = new Sprite(texture);
|
||||
const sprite = new Sprite(data.texture);
|
||||
|
||||
sprite.tint = color;
|
||||
sprite.tint = data.colorTransform;
|
||||
sprite.setFromMatrix(this._matrix);
|
||||
|
||||
container.addChild(sprite);
|
||||
|
@ -21,11 +21,6 @@ export class FigurePart implements IFigurePart
|
||||
this._breed = -1;
|
||||
}
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
|
@ -46,13 +46,6 @@ export class FigurePartSet implements IFigurePartSet
|
||||
|
||||
public dispose(): void
|
||||
{
|
||||
for(const part of this._parts)
|
||||
{
|
||||
const figurePart = part as FigurePart;
|
||||
|
||||
figurePart.dispose();
|
||||
}
|
||||
|
||||
this._parts = null;
|
||||
this._hiddenLayers = null;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { AlphaTolerance, AvatarAction, AvatarGuideStatus, AvatarSetType, IAdvancedMap, IAvatarEffectListener, IAvatarImage, IAvatarImageListener, IGraphicAsset, IObjectVisualizationData, IRoomGeometry, IRoomObject, IRoomObjectModel, RoomObjectSpriteType, RoomObjectVariable } from '@nitrots/api';
|
||||
import { GetAssetManager } from '@nitrots/assets';
|
||||
import { AdvancedMap } from '@nitrots/utils';
|
||||
import { Texture } from 'pixi.js';
|
||||
import { RoomObjectSpriteVisualization } from '../RoomObjectSpriteVisualization';
|
||||
@ -276,8 +277,7 @@ export class AvatarVisualization extends RoomObjectSpriteVisualization implement
|
||||
if(sprite)
|
||||
{
|
||||
const highlightEnabled = ((this.object.model.getValue<number>(RoomObjectVariable.FIGURE_HIGHLIGHT_ENABLE) === 1) && (this.object.model.getValue<number>(RoomObjectVariable.FIGURE_HIGHLIGHT) === 1));
|
||||
|
||||
const avatarImage = this._avatarImage.getImage(AvatarSetType.FULL, highlightEnabled);
|
||||
const avatarImage = this._avatarImage.processAsTexture(AvatarSetType.FULL, highlightEnabled);
|
||||
|
||||
if(avatarImage)
|
||||
{
|
||||
@ -411,7 +411,7 @@ export class AvatarVisualization extends RoomObjectSpriteVisualization implement
|
||||
|
||||
const assetName = ((((((this._avatarImage.getScale() + '_') + spriteData.member) + '_') + dd) + '_') + frameNumber);
|
||||
|
||||
const asset = this._avatarImage.getAsset(assetName);
|
||||
const asset = GetAssetManager().getAsset(assetName);
|
||||
|
||||
if(!asset) continue;
|
||||
|
||||
@ -995,6 +995,14 @@ export class AvatarVisualization extends RoomObjectSpriteVisualization implement
|
||||
|
||||
private clearAvatar(): void
|
||||
{
|
||||
const sprite = this.getSprite(AvatarVisualization.AVATAR_LAYER_ID);
|
||||
|
||||
if(sprite)
|
||||
{
|
||||
sprite.texture = Texture.EMPTY;
|
||||
sprite.alpha = 255;
|
||||
}
|
||||
|
||||
for(const avatar of this._cachedAvatars.getValues()) avatar && avatar.dispose();
|
||||
|
||||
for(const avatar of this._cachedAvatarEffects.getValues()) avatar && avatar.dispose();
|
||||
@ -1003,14 +1011,6 @@ export class AvatarVisualization extends RoomObjectSpriteVisualization implement
|
||||
this._cachedAvatarEffects.reset();
|
||||
|
||||
this._avatarImage = null;
|
||||
|
||||
const sprite = this.getSprite(AvatarVisualization.AVATAR_LAYER_ID);
|
||||
|
||||
if(sprite)
|
||||
{
|
||||
sprite.texture = Texture.EMPTY;
|
||||
sprite.alpha = 255;
|
||||
}
|
||||
}
|
||||
|
||||
private getAddition(id: number): IAvatarAddition
|
||||
@ -1071,7 +1071,7 @@ export class AvatarVisualization extends RoomObjectSpriteVisualization implement
|
||||
{
|
||||
sprite.libraryAssetName = 'sh_std_sd_1_0_0';
|
||||
|
||||
this._shadow = this._avatarImage.getAsset(sprite.libraryAssetName);
|
||||
this._shadow = GetAssetManager().getAsset(sprite.libraryAssetName);
|
||||
|
||||
offsetX = -8;
|
||||
offsetY = ((this._canStandUp) ? 6 : -3);
|
||||
@ -1080,7 +1080,7 @@ export class AvatarVisualization extends RoomObjectSpriteVisualization implement
|
||||
{
|
||||
sprite.libraryAssetName = 'h_std_sd_1_0_0';
|
||||
|
||||
this._shadow = this._avatarImage.getAsset(sprite.libraryAssetName);
|
||||
this._shadow = GetAssetManager().getAsset(sprite.libraryAssetName);
|
||||
|
||||
offsetX = -17;
|
||||
offsetY = ((this._canStandUp) ? 10 : -7);
|
||||
|
Loading…
Reference in New Issue
Block a user