mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2025-02-17 02:22:36 +01:00
Update mannequins
This commit is contained in:
parent
ebf481419f
commit
2a7e7e8864
@ -1,35 +1,20 @@
|
|||||||
import { AvatarSetType, IAvatarImageListener, IObjectVisualizationData, RoomObjectVariable } from '@nitrots/api';
|
import { AvatarSetType, IAvatarImage, IAvatarImageListener, IGraphicAsset, IObjectVisualizationData, RoomObjectVariable } from '@nitrots/api';
|
||||||
|
import { Texture } from 'pixi.js';
|
||||||
import { FurnitureMannequinVisualizationData } from './FurnitureMannequinVisualizationData';
|
import { FurnitureMannequinVisualizationData } from './FurnitureMannequinVisualizationData';
|
||||||
import { FurnitureVisualization } from './FurnitureVisualization';
|
import { FurnitureVisualization } from './FurnitureVisualization';
|
||||||
|
|
||||||
export class FurnitureMannequinVisualization extends FurnitureVisualization implements IAvatarImageListener
|
export class FurnitureMannequinVisualization extends FurnitureVisualization implements IAvatarImageListener
|
||||||
{
|
{
|
||||||
private static AVATAR_IMAGE_SPRITE_TAG: string = 'avatar_image';
|
private static AVATAR_IMAGE_SPRITE_TAG: string = 'avatar_image';
|
||||||
|
|
||||||
private _mannequinScale: number;
|
private _mannequinScale: number = -1;
|
||||||
private _figure: string;
|
private _figure: string = null;
|
||||||
private _gender: string;
|
private _gender: string = null;
|
||||||
private _dynamicAssetName: string;
|
private _avatarImage: IAvatarImage = null;
|
||||||
private _needsUpdate: boolean;
|
private _avatarWidth: number = 90;
|
||||||
|
private _avatarHeight: number = 130;
|
||||||
private _placeHolderFigure: string;
|
private _needsUpdate: boolean = false;
|
||||||
|
private _placeHolderFigure: string = 'hd-99999-99998';
|
||||||
private _disposed: boolean;
|
private _disposed: boolean = false;
|
||||||
|
|
||||||
constructor()
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
|
|
||||||
this._mannequinScale = -1;
|
|
||||||
this._figure = null;
|
|
||||||
this._gender = null;
|
|
||||||
this._dynamicAssetName = null;
|
|
||||||
this._needsUpdate = false;
|
|
||||||
|
|
||||||
this._placeHolderFigure = 'hd-99999-99998';
|
|
||||||
|
|
||||||
this._disposed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public initialize(data: IObjectVisualizationData): boolean
|
public initialize(data: IObjectVisualizationData): boolean
|
||||||
{
|
{
|
||||||
@ -44,11 +29,11 @@ export class FurnitureMannequinVisualization extends FurnitureVisualization impl
|
|||||||
|
|
||||||
this._disposed = true;
|
this._disposed = true;
|
||||||
|
|
||||||
if(this._dynamicAssetName && this.asset)
|
if(this._avatarImage)
|
||||||
{
|
{
|
||||||
this.asset.disposeAsset(this._dynamicAssetName);
|
this._avatarImage.dispose();
|
||||||
|
|
||||||
this._dynamicAssetName = null;
|
this._avatarImage = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
@ -81,7 +66,7 @@ export class FurnitureMannequinVisualization extends FurnitureVisualization impl
|
|||||||
|
|
||||||
if(figure)
|
if(figure)
|
||||||
{
|
{
|
||||||
this._figure = (figure + '.' + this._placeHolderFigure);
|
this._figure = `${ figure }.${ this._placeHolderFigure }`;
|
||||||
this._gender = (this.object.model.getValue<string>(RoomObjectVariable.FURNITURE_MANNEQUIN_GENDER) || null);
|
this._gender = (this.object.model.getValue<string>(RoomObjectVariable.FURNITURE_MANNEQUIN_GENDER) || null);
|
||||||
|
|
||||||
this.updateAvatar();
|
this.updateAvatar();
|
||||||
@ -95,60 +80,30 @@ export class FurnitureMannequinVisualization extends FurnitureVisualization impl
|
|||||||
return updateModel;
|
return updateModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateAvatar(forceUpdate: boolean = false): void
|
private updateAvatar(): void
|
||||||
{
|
{
|
||||||
if(!this.avatarExists() || forceUpdate)
|
if(this._avatarImage)
|
||||||
{
|
{
|
||||||
const avatarImage = this.data.createAvatarImage(this._figure, this._mannequinScale, this._gender, this);
|
this._avatarImage.dispose();
|
||||||
|
|
||||||
if(avatarImage)
|
this._avatarImage = null;
|
||||||
{
|
|
||||||
avatarImage.setDirection(AvatarSetType.FULL, this.direction);
|
|
||||||
|
|
||||||
if(this._dynamicAssetName) this.asset.disposeAsset(this._dynamicAssetName);
|
|
||||||
|
|
||||||
this.asset.addAsset(this.getAvatarAssetName(), avatarImage.getImage(AvatarSetType.FULL, false, 1, false), true);
|
|
||||||
|
|
||||||
this._dynamicAssetName = this.getAvatarAssetName();
|
|
||||||
this._needsUpdate = true;
|
|
||||||
|
|
||||||
avatarImage.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private avatarExists(): boolean
|
this._avatarImage = this.data.createAvatarImage(this._figure, this._mannequinScale, this._gender, this);
|
||||||
{
|
|
||||||
return (this._figure && (this.getAsset(this.getAvatarAssetName()) !== null));
|
|
||||||
}
|
|
||||||
|
|
||||||
private getAvatarAssetName(): string
|
|
||||||
{
|
|
||||||
return (((((('mannequin_' + this._figure) + '_') + this._mannequinScale) + '_') + this.direction) + '_') + this.object.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public resetFigure(figure: string): void
|
public resetFigure(figure: string): void
|
||||||
{
|
{
|
||||||
if(figure === this._figure) this.updateAvatar(true);
|
this.updateAvatar();
|
||||||
}
|
|
||||||
|
|
||||||
protected getSpriteAssetName(scale: number, layerId: number): string
|
this._needsUpdate = true;
|
||||||
{
|
|
||||||
const tag = this.getLayerTag(scale, this.direction, layerId);
|
|
||||||
|
|
||||||
if(this._figure && (tag === FurnitureMannequinVisualization.AVATAR_IMAGE_SPRITE_TAG) && this.avatarExists())
|
|
||||||
{
|
|
||||||
return this.getAvatarAssetName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.getSpriteAssetName(scale, layerId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getLayerXOffset(scale: number, direction: number, layerId: number): number
|
protected getLayerXOffset(scale: number, direction: number, layerId: number): number
|
||||||
{
|
{
|
||||||
const tag = this.getLayerTag(scale, direction, layerId);
|
const tag = this.getLayerTag(scale, direction, layerId);
|
||||||
|
|
||||||
if((tag === FurnitureMannequinVisualization.AVATAR_IMAGE_SPRITE_TAG) && this.avatarExists()) return (-(this.getSprite(layerId).width) / 2);
|
if((tag === FurnitureMannequinVisualization.AVATAR_IMAGE_SPRITE_TAG) && this._avatarImage) return (-(this._avatarWidth) / 3);
|
||||||
|
|
||||||
return super.getLayerXOffset(scale, direction, layerId);
|
return super.getLayerXOffset(scale, direction, layerId);
|
||||||
}
|
}
|
||||||
@ -157,11 +112,25 @@ export class FurnitureMannequinVisualization extends FurnitureVisualization impl
|
|||||||
{
|
{
|
||||||
const tag = this.getLayerTag(scale, direction, layerId);
|
const tag = this.getLayerTag(scale, direction, layerId);
|
||||||
|
|
||||||
if((tag === FurnitureMannequinVisualization.AVATAR_IMAGE_SPRITE_TAG) && this.avatarExists()) return -(this.getSprite(layerId).height);
|
if((tag === FurnitureMannequinVisualization.AVATAR_IMAGE_SPRITE_TAG) && this._avatarImage) return (-(this._avatarHeight) / 3);
|
||||||
|
|
||||||
return super.getLayerYOffset(scale, direction, layerId);
|
return super.getLayerYOffset(scale, direction, layerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getTexture(scale: number, layerId: number, asset: IGraphicAsset): Texture
|
||||||
|
{
|
||||||
|
const tag = this.getLayerTag(scale, this.direction, layerId);
|
||||||
|
|
||||||
|
if((tag === FurnitureMannequinVisualization.AVATAR_IMAGE_SPRITE_TAG) && this._avatarImage)
|
||||||
|
{
|
||||||
|
this._avatarImage.setDirection(AvatarSetType.FULL, this.direction);
|
||||||
|
|
||||||
|
return this._avatarImage.processAsTexture(AvatarSetType.FULL, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.getTexture(scale, layerId, asset);
|
||||||
|
}
|
||||||
|
|
||||||
public get disposed(): boolean
|
public get disposed(): boolean
|
||||||
{
|
{
|
||||||
return this._disposed;
|
return this._disposed;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { AlphaTolerance, IGraphicAsset, IObjectVisualizationData, IRoomGeometry, IRoomObjectSprite, RoomObjectVariable, RoomObjectVisualizationType } from '@nitrots/api';
|
import { AlphaTolerance, IGraphicAsset, IObjectVisualizationData, IRoomGeometry, IRoomObjectSprite, RoomObjectVariable, RoomObjectVisualizationType } from '@nitrots/api';
|
||||||
import { BLEND_MODES } from 'pixi.js';
|
import { BLEND_MODES, Texture } from 'pixi.js';
|
||||||
import { RoomObjectSpriteVisualization } from '../RoomObjectSpriteVisualization';
|
import { RoomObjectSpriteVisualization } from '../RoomObjectSpriteVisualization';
|
||||||
import { ColorData, LayerData } from '../data';
|
import { ColorData, LayerData } from '../data';
|
||||||
import { FurnitureVisualizationData } from './FurnitureVisualizationData';
|
import { FurnitureVisualizationData } from './FurnitureVisualizationData';
|
||||||
@ -279,11 +279,11 @@ export class FurnitureVisualization extends RoomObjectSpriteVisualization
|
|||||||
{
|
{
|
||||||
const assetData = this.getAsset(assetName, layerId);
|
const assetData = this.getAsset(assetName, layerId);
|
||||||
|
|
||||||
if(assetData && assetData.texture)
|
if(assetData)
|
||||||
{
|
{
|
||||||
sprite.visible = true;
|
sprite.visible = true;
|
||||||
sprite.type = this._type;
|
sprite.type = this._type;
|
||||||
sprite.texture = assetData.texture;
|
sprite.texture = this.getTexture(scale, layerId, assetData);
|
||||||
sprite.flipH = assetData.flipH;
|
sprite.flipH = assetData.flipH;
|
||||||
sprite.flipV = assetData.flipV;
|
sprite.flipV = assetData.flipV;
|
||||||
sprite.direction = this._direction;
|
sprite.direction = this._direction;
|
||||||
@ -577,6 +577,11 @@ export class FurnitureVisualization extends RoomObjectSpriteVisualization
|
|||||||
return this.asset.getAsset(name);
|
return this.asset.getAsset(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getTexture(scale: number, layerId: number, asset: IGraphicAsset): Texture
|
||||||
|
{
|
||||||
|
return asset?.texture ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
protected get direction(): number
|
protected get direction(): number
|
||||||
{
|
{
|
||||||
return this._direction;
|
return this._direction;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user