diff --git a/packages/api/src/nitro/avatar/IAvatarImage.ts b/packages/api/src/nitro/avatar/IAvatarImage.ts index 0ddba339..b6ffec25 100644 --- a/packages/api/src/nitro/avatar/IAvatarImage.ts +++ b/packages/api/src/nitro/avatar/IAvatarImage.ts @@ -16,7 +16,7 @@ export interface IAvatarImage extends IDisposable getLayerData(_arg_1: ISpriteDataContainer): IAnimationLayerData; getImage(setType: string, hightlight: boolean, scale?: number, cache?: boolean): Texture; getImageAsSprite(setType: string, scale?: number): Sprite; - getCroppedImage(setType: string, scale?: number): Promise; + getCroppedImageUrl(setType: string, scale?: number): Promise; getAsset(_arg_1: string): IGraphicAsset; getDirection(): number; getFigure(): IAvatarFigureContainer; diff --git a/packages/avatar/src/AvatarImage.ts b/packages/avatar/src/AvatarImage.ts index 37838bc9..a1a9bb2a 100644 --- a/packages/avatar/src/AvatarImage.ts +++ b/packages/avatar/src/AvatarImage.ts @@ -1,5 +1,5 @@ -import { AvatarAction, AvatarDirectionAngle, AvatarScaleType, AvatarSetType, IActionDefinition, IActiveActionData, IAdvancedMap, IAnimationLayerData, IAvatarDataContainer, IAvatarEffectListener, IAvatarFigureContainer, IAvatarImage, IGraphicAsset, IPartColor, ISpriteDataContainer } from '@nitrots/api'; -import { AdvancedMap, GetTickerTime, TextureUtils } from '@nitrots/utils'; +import { AvatarAction, AvatarDirectionAngle, AvatarScaleType, AvatarSetType, IActionDefinition, IActiveActionData, IAnimationLayerData, IAvatarDataContainer, IAvatarEffectListener, IAvatarFigureContainer, IAvatarImage, IGraphicAsset, IPartColor, ISpriteDataContainer } from '@nitrots/api'; +import { GetRenderer, GetTickerTime, TextureUtils } from '@nitrots/utils'; import { ColorMatrixFilter, Container, Rectangle, RenderTexture, Sprite, Texture } from 'pixi.js'; import { AvatarFigureContainer } from './AvatarFigureContainer'; import { AvatarStructure } from './AvatarStructure'; @@ -46,8 +46,6 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener private _sortedActions: IActiveActionData[]; private _lastActionsString: string; private _currentActionsString: string; - private _fullImageCache: IAdvancedMap; - private _fullImageCacheSize: number = 5; protected _isCachedImage: boolean = false; private _useFullImageCache: boolean = false; private _effectIdInUse: number = -1; @@ -86,7 +84,6 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener this._defaultAction = new ActiveActionData(AvatarAction.POSTURE_STAND); this._defaultAction.definition = this._structure.getActionDefinition(AvatarImage.DEFAULT_ACTION); this.resetActions(); - this._fullImageCache = new AdvancedMap(); this._animationFrameCount = 0; } @@ -121,13 +118,6 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener this._cache = null; } - if(this._fullImageCache) - { - for(const k of this._fullImageCache.getValues()) (k && k.destroy()); - - this._fullImageCache = null; - } - this._image = null; this._canvasOffsets = null; this._disposed = true; @@ -534,7 +524,7 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener return container; } - public async getCroppedImage(setType: string, scale: number = 1): Promise + public async getCroppedImageUrl(setType: string, scale: number = 1): Promise { if(!this._mainAction) return null; @@ -547,6 +537,13 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener const setTypes = this.getBodyParts(setType, this._mainAction.definition.geometryType, this._mainDirection); const container = new Container(); + /* const sprite = new Sprite(Texture.EMPTY); + + sprite.width = avatarCanvas.width; + sprite.height = avatarCanvas.height; + + container.addChild(sprite); */ + let partCount = (setTypes.length - 1); while(partCount >= 0) @@ -593,10 +590,18 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener partCount--; } - return await TextureUtils.generateImage(TextureUtils.generateTexture({ + const texture = TextureUtils.generateTexture({ target: container, frame: new Rectangle(0, 0, avatarCanvas.width, avatarCanvas.height) - })); + }); + let canvas = GetRenderer().texture.generateCanvas(texture); + const base64 = canvas.toDataURL('image/png'); + + canvas = null; + + texture.destroy(true); + + return base64; } public getAsset(k: string): IGraphicAsset diff --git a/packages/room/src/object/visualization/room/RoomPlane.ts b/packages/room/src/object/visualization/room/RoomPlane.ts index 60c07e1a..1b795daf 100644 --- a/packages/room/src/object/visualization/room/RoomPlane.ts +++ b/packages/room/src/object/visualization/room/RoomPlane.ts @@ -1,7 +1,7 @@ import { IAssetPlaneVisualizationLayer, IAssetRoomVisualizationData, IRoomGeometry, IRoomPlane, IVector3D } from '@nitrots/api'; import { GetAssetManager } from '@nitrots/assets'; import { GetRenderer, PlaneMaskFilter, TextureUtils, Vector3d } from '@nitrots/utils'; -import { Container, Matrix, Point, Sprite, Texture, TilingSprite } from 'pixi.js'; +import { Container, Filter, Matrix, Point, Sprite, Texture, TilingSprite } from 'pixi.js'; import { RoomGeometry } from '../../../utils'; import { RoomPlaneBitmapMask } from './RoomPlaneBitmapMask'; import { RoomPlaneRectangleMask } from './RoomPlaneRectangleMask'; @@ -59,6 +59,7 @@ export class RoomPlane implements IRoomPlane private _planeSprite: TilingSprite = null; private _planeTexture: Texture = null; + private _maskFilter: Filter = null; constructor(origin: IVector3D, location: IVector3D, leftSide: IVector3D, rightSide: IVector3D, type: number, usesMask: boolean, secondaryNormals: IVector3D[], randomSeed: number, textureOffsetX: number = 0, textureOffsetY: number = 0, textureMaxX: number = 0, textureMaxY: number = 0) { @@ -126,7 +127,12 @@ export class RoomPlane implements IRoomPlane let needsUpdate = false; - if(this._geometryUpdateId !== geometry.updateId) needsUpdate = true; + if(this._geometryUpdateId !== geometry.updateId) + { + this._geometryUpdateId = geometry.updateId; + + needsUpdate = true; + } if(!needsUpdate || !this._canBeVisible) { @@ -187,7 +193,6 @@ export class RoomPlane implements IRoomPlane this._relativeDepth = relativeDepth; this._isVisible = true; - this._geometryUpdateId = geometry.updateId; Randomizer.setSeed(this._randomSeed); @@ -549,9 +554,9 @@ export class RoomPlane implements IRoomPlane this._maskChanged = false; - container.filterArea = container.getBounds().rectangle; + if(!this._maskFilter) this._maskFilter = new PlaneMaskFilter({}); - container.filters = [ new PlaneMaskFilter({}) ]; + if(!container.filters) container.filters = [ this._maskFilter ]; return true; }