Pixi 6.5.8 & Landscapes (#84)

* Changes

* More changes

* fix some var names

* Fix door mask

* Add tilemap back

* Begin landscapes

* Add vite

* Add landscapes

* Add texture caching

* More changes

* Fix flipped plane material cells

* Changes

* More landscape changes

* Fix PlaneMaterialCell tiling

* Add more caching

* Destroy BaseRenderTexture

* Performance improvements

* More improvements

* More improvements

* Cache mask pixels

* Fix settings

Co-authored-by: dank074 <torresefrain10@gmail.com>
This commit is contained in:
Bill 2023-01-03 01:04:48 -05:00 committed by GitHub
parent 32bc877318
commit 36b203f33a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
85 changed files with 2637 additions and 1767 deletions

26
.vscode/settings.json vendored
View File

@ -4,13 +4,29 @@
"typescript.preferences.quoteStyle": "single", "typescript.preferences.quoteStyle": "single",
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true, "typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"typescript.format.placeOpenBraceOnNewLineForFunctions": true, "typescript.format.placeOpenBraceOnNewLineForFunctions": true,
"editor.wordWrap": "on",
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.fixAll": true, "source.fixAll.eslint": true,
"source.organizeImports": true, "source.fixAll.sortJSON": false,
"source.organizeImports": true
}, },
"emmet.showExpandedAbbreviation": "never", "editor.formatOnSave": false,
"git.ignoreLimitWarning": true, "git.ignoreLimitWarning": true,
"files.eol": "\n", "files.eol": "\n",
"files.insertFinalNewline": true, "files.insertFinalNewline": true,
"files.trimFinalNewlines": true "files.trimFinalNewlines": true,
"emmet.showExpandedAbbreviation": "never",
"eslint.format.enable": true,
"eslint.validate": [
"javascript",
"typescript"
],
"eslint.workingDirectories": [
{
"pattern": "./src"
}
],
"javascript.format.enable": false,
"thunder-client.saveToWorkspace": false,
"thunder-client.workspaceRelativePath": "."
} }

View File

@ -16,53 +16,58 @@
"homepage": "https://git.krews.org/nitro/nitro-renderer", "homepage": "https://git.krews.org/nitro/nitro-renderer",
"type": "module", "type": "module",
"scripts": { "scripts": {
"compile": "tsc --project ./tsconfig.json", "build": "vite build",
"compile": "tsc --project ./tsconfig.json --noEmit false",
"eslint": "eslint ./src --fix" "eslint": "eslint ./src --fix"
}, },
"main": "./index",
"dependencies": { "dependencies": {
"@pixi/app": "~6.4.2", "@pixi/app": "~6.5.0",
"@pixi/basis": "~6.4.2", "@pixi/basis": "~6.5.0",
"@pixi/canvas-display": "~6.4.2", "@pixi/canvas-display": "~6.5.0",
"@pixi/canvas-extract": "~6.4.2", "@pixi/canvas-extract": "~6.5.0",
"@pixi/canvas-renderer": "~6.4.2", "@pixi/canvas-renderer": "~6.5.0",
"@pixi/constants": "~6.4.2", "@pixi/constants": "~6.5.0",
"@pixi/core": "~6.4.2", "@pixi/core": "~6.5.0",
"@pixi/display": "~6.4.2", "@pixi/display": "~6.5.0",
"@pixi/events": "~6.4.2", "@pixi/events": "~6.5.0",
"@pixi/extract": "~6.4.2", "@pixi/extensions": "~6.5.0",
"@pixi/filter-adjustment": "^4.1.3", "@pixi/extract": "~6.5.0",
"@pixi/filter-alpha": "~6.4.2", "@pixi/filter-alpha": "~6.5.0",
"@pixi/filter-color-matrix": "~6.4.2", "@pixi/filter-color-matrix": "~6.5.0",
"@pixi/graphics": "~6.4.2", "@pixi/graphics": "~6.5.0",
"@pixi/graphics-extras": "~6.4.2", "@pixi/graphics-extras": "~6.5.0",
"@pixi/interaction": "~6.4.2", "@pixi/interaction": "~6.5.0",
"@pixi/loaders": "~6.4.2", "@pixi/loaders": "~6.5.0",
"@pixi/math": "~6.4.2", "@pixi/math": "~6.5.0",
"@pixi/math-extras": "~6.4.2", "@pixi/math-extras": "~6.5.0",
"@pixi/mixin-cache-as-bitmap": "~6.4.2", "@pixi/mixin-cache-as-bitmap": "~6.5.0",
"@pixi/mixin-get-child-by-name": "~6.4.2", "@pixi/mixin-get-child-by-name": "~6.5.0",
"@pixi/mixin-get-global-position": "~6.4.2", "@pixi/mixin-get-global-position": "~6.5.0",
"@pixi/polyfill": "~6.4.2", "@pixi/polyfill": "~6.5.0",
"@pixi/runner": "~6.4.2", "@pixi/runner": "~6.5.0",
"@pixi/settings": "~6.4.2", "@pixi/settings": "~6.5.0",
"@pixi/sprite": "~6.4.2", "@pixi/sprite": "~6.5.0",
"@pixi/sprite-tiling": "~6.4.2", "@pixi/sprite-tiling": "~6.5.0",
"@pixi/spritesheet": "~6.4.2", "@pixi/spritesheet": "~6.5.0",
"@pixi/text": "~6.4.2", "@pixi/text": "~6.5.0",
"@pixi/ticker": "~6.4.2", "@pixi/ticker": "~6.5.0",
"@pixi/tilemap": "^3.2.2", "@pixi/tilemap": "^3.2.2",
"@pixi/utils": "~6.4.2", "@pixi/utils": "~6.5.0",
"gifuct-js": "^2.1.2", "gifuct-js": "^2.1.2",
"howler": "^2.2.3", "howler": "^2.2.3",
"pako": "^2.0.4" "pako": "^2.0.4"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-typescript": "^10.0.1",
"@types/howler": "^2.2.7", "@types/howler": "^2.2.7",
"@types/pako": "^1.0.3", "@types/pako": "^1.0.3",
"@typescript-eslint/eslint-plugin": "^5.30.7", "@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7", "@typescript-eslint/parser": "^5.30.7",
"eslint": "^8.20.0", "eslint": "^8.20.0",
"tslib": "^2.3.1", "tslib": "^2.3.1",
"typescript": "~4.4.4" "typescript": "~4.4.4",
"vite": "^4.0.2",
"vite-plugin-minify": "^1.5.2"
} }
} }

View File

@ -175,15 +175,9 @@ export class AssetManager implements IAssetManager
{ {
const spritesheet = new Spritesheet(baseTexture, spritesheetData); const spritesheet = new Spritesheet(baseTexture, spritesheetData);
return new Promise<void>((resolve, reject) => await spritesheet.parse();
{
spritesheet.parse(() =>
{
this.createCollection(data, spritesheet);
return resolve(); this.createCollection(data, spritesheet);
});
});
}; };
if(baseTexture.valid) if(baseTexture.valid)

View File

@ -1,5 +1,7 @@
import { Resource, Texture } from '@pixi/core'; import { Resource, Texture } from '@pixi/core';
import { Rectangle } from '@pixi/math'; import { Rectangle } from '@pixi/math';
import { Sprite } from '@pixi/sprite';
import { TextureUtils } from '../../pixi-proxy';
import { IGraphicAsset } from './IGraphicAsset'; import { IGraphicAsset } from './IGraphicAsset';
export class GraphicAsset implements IGraphicAsset export class GraphicAsset implements IGraphicAsset
@ -64,6 +66,11 @@ export class GraphicAsset implements IGraphicAsset
this._initialized = true; this._initialized = true;
} }
public getImageUrl(): string
{
return TextureUtils.generateImageUrl(new Sprite(this._texture));
}
public get name(): string public get name(): string
{ {
return this._name; return this._name;

View File

@ -3,6 +3,7 @@ import { IAsset } from './IAsset';
import { IAssetAlias } from './IAssetAlias'; import { IAssetAlias } from './IAssetAlias';
import { IAssetPalette } from './IAssetPalette'; import { IAssetPalette } from './IAssetPalette';
import { IAssetLogicData } from './logic'; import { IAssetLogicData } from './logic';
import { IAssetRoomVisualizationData } from './room-visualization';
import { ISpritesheetData } from './spritesheet'; import { ISpritesheetData } from './spritesheet';
import { IAssetVisualizationData } from './visualization'; import { IAssetVisualizationData } from './visualization';
@ -18,4 +19,5 @@ export interface IAssetData {
animations?: { [index: string]: IAssetAnimation }; animations?: { [index: string]: IAssetAnimation };
palettes?: { [index: string]: IAssetPalette }; palettes?: { [index: string]: IAssetPalette };
visualizations?: IAssetVisualizationData[]; visualizations?: IAssetVisualizationData[];
roomVisualization?: IAssetRoomVisualizationData;
} }

View File

@ -17,6 +17,7 @@ export * from './IGraphicAssetPalette';
export * from './logic'; export * from './logic';
export * from './logic/model'; export * from './logic/model';
export * from './logic/particlesystem'; export * from './logic/particlesystem';
export * from './room-visualization';
export * from './spritesheet'; export * from './spritesheet';
export * from './visualization'; export * from './visualization';
export * from './visualization/animation'; export * from './visualization/animation';

View File

@ -0,0 +1,8 @@
import { IAssetPlaneVisualization } from './IAssetPlaneVisualization';
export interface IAssetPlane
{
id?: string;
visualizations?: IAssetPlaneVisualization[];
animatedVisualization?: IAssetPlaneVisualization[];
}

View File

@ -0,0 +1,7 @@
import { IAssetPlaneMaskVisualization } from './IAssetPlaneMaskVisualization';
export interface IAssetPlaneMask
{
id?: string;
visualizations?: IAssetPlaneMaskVisualization[];
}

View File

@ -0,0 +1,6 @@
import { IAssetPlaneMask } from './IAssetPlaneMask';
export interface IAssetPlaneMaskData
{
masks?: IAssetPlaneMask[];
}

View File

@ -0,0 +1,7 @@
import { IAssetPlaneTextureBitmap } from './IAssetPlaneTextureBitmap';
export interface IAssetPlaneMaskVisualization
{
size?: number;
bitmaps?: IAssetPlaneTextureBitmap[];
}

View File

@ -0,0 +1,7 @@
import { IAssetPlaneMaterialCellMatrix } from './IAssetPlaneMaterialCellMatrix';
export interface IAssetPlaneMaterial
{
id?: string;
matrices?: IAssetPlaneMaterialCellMatrix[];
}

View File

@ -0,0 +1,7 @@
import { IAssetPlaneMaterialCellExtraItemData } from './IAssetPlaneMaterialCellExtraItemData';
export interface IAssetPlaneMaterialCell
{
textureId?: string;
extraData?: IAssetPlaneMaterialCellExtraItemData;
}

View File

@ -0,0 +1,8 @@
import { IAssetPlaneMaterialCell } from './IAssetPlaneMaterialCell';
export interface IAssetPlaneMaterialCellColumn
{
repeatMode?: string;
width?: number;
cells?: IAssetPlaneMaterialCell[];
}

View File

@ -0,0 +1,6 @@
export interface IAssetPlaneMaterialCellExtraItemData
{
limitMax?: number;
extraItemTypes?: string[];
offsets?: [number, number][];
}

View File

@ -0,0 +1,12 @@
import { IAssetPlaneMaterialCellColumn } from './IAssetPlaneMaterialCellColumn';
export interface IAssetPlaneMaterialCellMatrix
{
repeatMode?: string;
align?: string;
normalMinX?: number;
normalMaxX?: number;
normalMinY?: number;
normalMaxY?: number;
columns?: IAssetPlaneMaterialCellColumn[];
}

View File

@ -0,0 +1,7 @@
import { IAssetPlaneTextureBitmap } from './IAssetPlaneTextureBitmap';
export interface IAssetPlaneTexture
{
id?: string;
bitmaps?: IAssetPlaneTextureBitmap[];
}

View File

@ -0,0 +1,8 @@
export interface IAssetPlaneTextureBitmap
{
assetName?: string;
normalMinX?: number;
normalMaxX?: number;
normalMinY?: number;
normalMaxY?: number;
}

View File

@ -0,0 +1,10 @@
import { IAssetPlaneVisualizationAnimatedLayer } from './IAssetPlaneVisualizationAnimatedLayer';
import { IAssetPlaneVisualizationLayer } from './IAssetPlaneVisualizationLayer';
export interface IAssetPlaneVisualization
{
size?: number;
horizontalAngle?: number;
verticalAngle?: number;
allLayers?: (IAssetPlaneVisualizationLayer | IAssetPlaneVisualizationAnimatedLayer)[];
}

View File

@ -0,0 +1,6 @@
import { IAssetPlaneVisualizationAnimatedLayerItem } from './IAssetPlaneVisualizationAnimatedLayerItem';
export interface IAssetPlaneVisualizationAnimatedLayer
{
items?: IAssetPlaneVisualizationAnimatedLayerItem[];
}

View File

@ -0,0 +1,11 @@
export interface IAssetPlaneVisualizationAnimatedLayerItem
{
id?: number;
assetId?: string;
x?: string;
y?: string;
randomX?: string;
randomY?: string;
speedX?: number;
speedY?: number;
}

View File

@ -0,0 +1,10 @@
import { IAssetPlane } from './IAssetPlane';
import { IAssetPlaneMaterial } from './IAssetPlaneMaterial';
import { IAssetPlaneTexture } from './IAssetPlaneTexture';
export interface IAssetPlaneVisualizationData
{
planes?: IAssetPlane[];
materials?: IAssetPlaneMaterial[];
textures?: IAssetPlaneTexture[];
}

View File

@ -0,0 +1,7 @@
export interface IAssetPlaneVisualizationLayer
{
materialId?: string;
color?: number;
offset?: number;
align?: string;
}

View File

@ -0,0 +1,10 @@
import { IAssetPlaneMaskData } from './IAssetPlaneMaskData';
import { IAssetPlaneVisualizationData } from './IAssetPlaneVisualizationData';
export interface IAssetRoomVisualizationData
{
floorData?: IAssetPlaneVisualizationData;
wallData?: IAssetPlaneVisualizationData;
landscapeData?: IAssetPlaneVisualizationData;
maskData?: IAssetPlaneMaskData;
}

View File

@ -0,0 +1,17 @@
export * from './IAssetPlane';
export * from './IAssetPlaneMask';
export * from './IAssetPlaneMaskData';
export * from './IAssetPlaneMaskVisualization';
export * from './IAssetPlaneMaterial';
export * from './IAssetPlaneMaterialCell';
export * from './IAssetPlaneMaterialCellColumn';
export * from './IAssetPlaneMaterialCellExtraItemData';
export * from './IAssetPlaneMaterialCellMatrix';
export * from './IAssetPlaneTexture';
export * from './IAssetPlaneTextureBitmap';
export * from './IAssetPlaneVisualization';
export * from './IAssetPlaneVisualizationAnimatedLayer';
export * from './IAssetPlaneVisualizationAnimatedLayerItem';
export * from './IAssetPlaneVisualizationData';
export * from './IAssetPlaneVisualizationLayer';
export * from './IAssetRoomVisualizationData';

View File

@ -1,4 +1,4 @@
import { AdjustmentFilter } from '@pixi/filter-adjustment'; import { AdjustmentFilter } from '../../../../pixi-proxy';
export interface IAvatarDataContainer export interface IAvatarDataContainer
{ {

3
src/api/utils/Dict.ts Normal file
View File

@ -0,0 +1,3 @@
export type Dict<T> = {
[key: string]: T;
};

View File

@ -2,6 +2,7 @@ export * from './AdvancedMap';
export * from './ArrayBufferToBase64'; export * from './ArrayBufferToBase64';
export * from './BinaryReader'; export * from './BinaryReader';
export * from './BinaryWriter'; export * from './BinaryWriter';
export * from './Dict';
export * from './IAdvancedMap'; export * from './IAdvancedMap';
export * from './IBinaryReader'; export * from './IBinaryReader';
export * from './IBinaryWriter'; export * from './IBinaryWriter';

View File

@ -14,7 +14,7 @@ import { GameMessageHandler } from './game';
import { INitro } from './INitro'; import { INitro } from './INitro';
import { NitroLocalizationManager } from './localization'; import { NitroLocalizationManager } from './localization';
import './Plugins'; import './Plugins';
import { RoomEngine } from './room'; import { LandscapeRasterizer, RoomEngine } from './room';
import { RoomSessionManager, SessionDataManager } from './session'; import { RoomSessionManager, SessionDataManager } from './session';
import { SoundManager } from './sound'; import { SoundManager } from './sound';
import { HabboWebTools } from './utils/HabboWebTools'; import { HabboWebTools } from './utils/HabboWebTools';
@ -23,6 +23,7 @@ LegacyExternalInterface.available;
settings.SCALE_MODE = (!(window.devicePixelRatio % 1)) ? SCALE_MODES.NEAREST : SCALE_MODES.LINEAR; settings.SCALE_MODE = (!(window.devicePixelRatio % 1)) ? SCALE_MODES.NEAREST : SCALE_MODES.LINEAR;
settings.ROUND_PIXELS = true; settings.ROUND_PIXELS = true;
settings.GC_MAX_IDLE = 120;
export class Nitro implements INitro export class Nitro implements INitro
{ {
@ -87,9 +88,9 @@ export class Nitro implements INitro
const instance = new this(new NitroCore(), { const instance = new this(new NitroCore(), {
autoDensity: false, autoDensity: false,
resolution: window.devicePixelRatio,
width: window.innerWidth, width: window.innerWidth,
height: window.innerHeight, height: window.innerHeight,
resolution: window.devicePixelRatio,
view: canvas view: canvas
}); });
@ -192,16 +193,15 @@ export class Nitro implements INitro
private onConfigurationLoadedEvent(event: ConfigurationEvent): void private onConfigurationLoadedEvent(event: ConfigurationEvent): void
{ {
const animationFPS = NitroConfiguration.getValue<number>('system.animation.fps', 24); GetTicker().maxFPS = NitroConfiguration.getValue<number>('system.fps.max', 24);
const limitsFPS = NitroConfiguration.getValue<boolean>('system.limits.fps', false);
if(limitsFPS) GetTicker().maxFPS = animationFPS;
NitroLogger.LOG_DEBUG = NitroConfiguration.getValue<boolean>('system.log.debug', true); NitroLogger.LOG_DEBUG = NitroConfiguration.getValue<boolean>('system.log.debug', true);
NitroLogger.LOG_WARN = NitroConfiguration.getValue<boolean>('system.log.warn', false); NitroLogger.LOG_WARN = NitroConfiguration.getValue<boolean>('system.log.warn', false);
NitroLogger.LOG_ERROR = NitroConfiguration.getValue<boolean>('system.log.error', false); NitroLogger.LOG_ERROR = NitroConfiguration.getValue<boolean>('system.log.error', false);
NitroLogger.LOG_EVENTS = NitroConfiguration.getValue<boolean>('system.log.events', false); NitroLogger.LOG_EVENTS = NitroConfiguration.getValue<boolean>('system.log.events', false);
NitroLogger.LOG_PACKETS = NitroConfiguration.getValue<boolean>('system.log.packets', false); NitroLogger.LOG_PACKETS = NitroConfiguration.getValue<boolean>('system.log.packets', false);
LandscapeRasterizer.LANDSCAPES_ENABLED = NitroConfiguration.getValue<boolean>('room.landscapes.enabled', true);
} }
private onRoomEngineReady(event: RoomEngineEvent): void private onRoomEngineReady(event: RoomEngineEvent): void

View File

@ -1,10 +1,9 @@
import { Application } from '@pixi/app';
import '@pixi/canvas-display'; import '@pixi/canvas-display';
import { BatchRenderer, Renderer } from '@pixi/core'; import { BatchRenderer, extensions } from '@pixi/core';
import { Extract } from '@pixi/extract'; import { Extract } from '@pixi/extract';
import '@pixi/graphics-extras'; import '@pixi/graphics-extras';
import { InteractionManager } from '@pixi/interaction'; import { InteractionManager } from '@pixi/interaction';
import { AppLoaderPlugin, Loader } from '@pixi/loaders'; import { AppLoaderPlugin } from '@pixi/loaders';
import '@pixi/math-extras'; import '@pixi/math-extras';
import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-cache-as-bitmap';
import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-child-by-name';
@ -13,33 +12,12 @@ import '@pixi/polyfill';
import { TilingSpriteRenderer } from '@pixi/sprite-tiling'; import { TilingSpriteRenderer } from '@pixi/sprite-tiling';
import { SpritesheetLoader } from '@pixi/spritesheet'; import { SpritesheetLoader } from '@pixi/spritesheet';
import { TickerPlugin } from '@pixi/ticker'; import { TickerPlugin } from '@pixi/ticker';
import { TileRenderer } from '@pixi/tilemap';
import * as utils from '@pixi/utils';
export * from '@pixi/app';
export * from '@pixi/canvas-renderer';
export * from '@pixi/constants';
export * from '@pixi/core';
export * from '@pixi/display';
export * from '@pixi/events';
export * from '@pixi/extract';
export * from '@pixi/graphics';
export * from '@pixi/loaders';
export * from '@pixi/math';
export * from '@pixi/runner';
export * from '@pixi/settings';
export * from '@pixi/sprite';
export * from '@pixi/spritesheet';
export * from '@pixi/text';
export * from '@pixi/ticker';
export { utils };
Renderer.registerPlugin('batch', BatchRenderer); extensions.add(
Renderer.registerPlugin('extract', Extract); BatchRenderer,
Renderer.registerPlugin('tilingSprite', TilingSpriteRenderer); Extract,
Renderer.registerPlugin('tilemap', TileRenderer); TilingSpriteRenderer,
Renderer.registerPlugin('interaction', InteractionManager); InteractionManager,
SpritesheetLoader,
Loader.registerPlugin(SpritesheetLoader); AppLoaderPlugin,
TickerPlugin);
Application.registerPlugin(AppLoaderPlugin);
Application.registerPlugin(TickerPlugin);

View File

@ -1,5 +1,5 @@
import { AdjustmentFilter } from '@pixi/filter-adjustment'; import { IActionDefinition, IPartColor } from '../../api';
import { IActionDefinition, IPartColor } from '../../api'; import { AdjustmentFilter } from '../../pixi-proxy';
import { AvatarAnimationFrame } from './structure'; import { AvatarAnimationFrame } from './structure';
export class AvatarImagePartContainer export class AvatarImagePartContainer

View File

@ -1,5 +1,5 @@
import { AdjustmentFilter } from '@pixi/filter-adjustment'; import { IAssetAnimationAvatar, IAvatarDataContainer } from '../../../api';
import { IAssetAnimationAvatar, IAvatarDataContainer } from '../../../api'; import { AdjustmentFilter } from '../../../pixi-proxy';
export class AvatarDataContainer implements IAvatarDataContainer export class AvatarDataContainer implements IAvatarDataContainer
{ {

View File

@ -541,15 +541,9 @@ export class RoomContentLoader implements IFurnitureDataListener, IRoomContentLo
{ {
const spritesheet = new Spritesheet(baseTexture, spritesheetData); const spritesheet = new Spritesheet(baseTexture, spritesheetData);
return new Promise<void>((resolve, reject) => await spritesheet.parse();
{
spritesheet.parse(() =>
{
this.createCollection(data, spritesheet);
return resolve(); this.createCollection(data, spritesheet);
});
});
}; };
if(baseTexture.valid) if(baseTexture.valid)

View File

@ -350,7 +350,7 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato
instance.model.setValue(RoomVariableEnum.ROOM_MIN_Y, minY); instance.model.setValue(RoomVariableEnum.ROOM_MIN_Y, minY);
instance.model.setValue(RoomVariableEnum.ROOM_MAX_Y, maxY); instance.model.setValue(RoomVariableEnum.ROOM_MAX_Y, maxY);
const seed = ((((minX * 423) + (maxX * 671)) + (minY * 913)) + (maxY * 7509)); const seed = Math.trunc((minX * 423) + (maxX * 671) + (minY * 913) + (maxY * 7509));
if(roomObject && roomObject.model) roomObject.model.setValue(RoomObjectVariable.ROOM_RANDOM_SEED, seed); if(roomObject && roomObject.model) roomObject.model.setValue(RoomObjectVariable.ROOM_RANDOM_SEED, seed);
} }

View File

@ -1168,7 +1168,7 @@ export class RoomPlaneParser
private addWall(k: IVector3D, _arg_2: IVector3D, _arg_3: IVector3D, _arg_4: IVector3D, _arg_5: boolean, _arg_6: boolean, _arg_7: boolean): void private addWall(k: IVector3D, _arg_2: IVector3D, _arg_3: IVector3D, _arg_4: IVector3D, _arg_5: boolean, _arg_6: boolean, _arg_7: boolean): void
{ {
this.addPlane(RoomPlaneData.PLANE_WALL, k, _arg_2, _arg_3, [_arg_4]); this.addPlane(RoomPlaneData.PLANE_WALL, k, _arg_2, _arg_3, [_arg_4]);
//this.addPlane(RoomPlaneData.PLANE_LANDSCAPE, k, _arg_2, _arg_3, [_arg_4]); this.addPlane(RoomPlaneData.PLANE_LANDSCAPE, k, _arg_2, _arg_3, [_arg_4]);
const _local_8: number = (RoomPlaneParser.WALL_THICKNESS * this._wallThicknessMultiplier); const _local_8: number = (RoomPlaneParser.WALL_THICKNESS * this._wallThicknessMultiplier);
const _local_9: number = (RoomPlaneParser.FLOOR_THICKNESS * this._floorThicknessMultiplier); const _local_9: number = (RoomPlaneParser.FLOOR_THICKNESS * this._floorThicknessMultiplier);
const _local_10: Vector3d = Vector3d.crossProduct(_arg_2, _arg_3); const _local_10: Vector3d = Vector3d.crossProduct(_arg_2, _arg_3);

View File

@ -14,7 +14,7 @@ export class FurnitureWindowLogic extends FurnitureMultiStateLogic
if(asset.logic.maskType && (asset.logic.maskType !== '') && (asset.logic.maskType.length > 0)) maskType = asset.logic.maskType; if(asset.logic.maskType && (asset.logic.maskType !== '') && (asset.logic.maskType.length > 0)) maskType = asset.logic.maskType;
} }
this.object.model.setValue(RoomObjectVariable.FURNITURE_USES_PLANE_MASK, 0); this.object.model.setValue(RoomObjectVariable.FURNITURE_USES_PLANE_MASK, 1);
this.object.model.setValue(RoomObjectVariable.FURNITURE_PLANE_MASK_TYPE, maskType); this.object.model.setValue(RoomObjectVariable.FURNITURE_PLANE_MASK_TYPE, maskType);
} }
} }

View File

@ -8,8 +8,6 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
public static TYPE: string = RoomObjectVisualizationType.FURNITURE_ANIMATED; public static TYPE: string = RoomObjectVisualizationType.FURNITURE_ANIMATED;
public static DEFAULT_ANIMATION_ID: number = 0; public static DEFAULT_ANIMATION_ID: number = 0;
protected _data: FurnitureAnimatedVisualizationData;
protected _state: number; protected _state: number;
protected _frameIncrease: number; protected _frameIncrease: number;
private _animationData: AnimationStateData; private _animationData: AnimationStateData;
@ -62,7 +60,7 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
protected getAnimationId(animationData: AnimationStateData): number protected getAnimationId(animationData: AnimationStateData): number
{ {
if((this.animationId !== FurnitureAnimatedVisualization.DEFAULT_ANIMATION_ID) && this._data.hasAnimation(this._animationScale, this.animationId)) return this.animationId; if((this.animationId !== FurnitureAnimatedVisualization.DEFAULT_ANIMATION_ID) && this.data.hasAnimation(this._animationScale, this.animationId)) return this.animationId;
return FurnitureAnimatedVisualization.DEFAULT_ANIMATION_ID; return FurnitureAnimatedVisualization.DEFAULT_ANIMATION_ID;
} }
@ -108,7 +106,7 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
if(!isNaN(state)) if(!isNaN(state))
{ {
const animationId = this._data.getAnimationId(this._animationScale, state); const animationId = this.data.getAnimationId(this._animationScale, state);
this.setAnimation(animationId); this.setAnimation(animationId);
} }
@ -141,7 +139,7 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
protected setAnimation(animationId: number): void protected setAnimation(animationId: number): void
{ {
if(!this._data) return; if(!this.data) return;
this.setSubAnimation(this._animationData, animationId, (this._state >= 0)); this.setSubAnimation(this._animationData, animationId, (this._state >= 0));
} }
@ -158,11 +156,11 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
if(animationId !== state) if(animationId !== state)
{ {
if(!this._data.isImmediateChange(this._animationScale, animationId, state)) if(!this.data.isImmediateChange(this._animationScale, animationId, state))
{ {
let transition = AnimationData.getTransitionFromAnimationId(state); let transition = AnimationData.getTransitionFromAnimationId(state);
if(this._data.hasAnimation(this._animationScale, transition)) if(this.data.hasAnimation(this._animationScale, transition))
{ {
animationData.animationAfterTransitionId = animationId; animationData.animationAfterTransitionId = animationId;
animationId = transition; animationId = transition;
@ -171,7 +169,7 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
{ {
transition = AnimationData.getTransitionToAnimationId(animationId); transition = AnimationData.getTransitionToAnimationId(animationId);
if(this._data.hasAnimation(this._animationScale, transition)) if(this.data.hasAnimation(this._animationScale, transition))
{ {
animationData.animationAfterTransitionId = animationId; animationData.animationAfterTransitionId = animationId;
animationId = transition; animationId = transition;
@ -185,7 +183,7 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
{ {
const transition = AnimationData.getTransitionToAnimationId(animationId); const transition = AnimationData.getTransitionToAnimationId(animationId);
if(this._data.hasAnimation(this._animationScale, transition)) if(this.data.hasAnimation(this._animationScale, transition))
{ {
animationData.animationAfterTransitionId = animationId; animationData.animationAfterTransitionId = animationId;
animationId = transition; animationId = transition;
@ -198,7 +196,7 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
{ {
const transition = AnimationData.getTransitionFromAnimationId(state); const transition = AnimationData.getTransitionFromAnimationId(state);
if(this._data.hasAnimation(this._animationScale, transition)) if(this.data.hasAnimation(this._animationScale, transition))
{ {
animationData.animationAfterTransitionId = animationId; animationData.animationAfterTransitionId = animationId;
animationId = transition; animationId = transition;
@ -207,7 +205,7 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
{ {
const transition = AnimationData.getTransitionToAnimationId(animationId); const transition = AnimationData.getTransitionToAnimationId(animationId);
if(this._data.hasAnimation(this._animationScale, transition)) if(this.data.hasAnimation(this._animationScale, transition))
{ {
animationData.animationAfterTransitionId = animationId; animationData.animationAfterTransitionId = animationId;
animationId = transition; animationId = transition;
@ -242,12 +240,12 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
protected updateAnimation(scale: number): number protected updateAnimation(scale: number): number
{ {
if(!this._data) return 0; if(!this.data) return 0;
if(scale !== this._animationScale) if(scale !== this._animationScale)
{ {
this._animationScale = scale; this._animationScale = scale;
this._animatedLayerCount = this._data.getLayerCount(scale); this._animatedLayerCount = this.data.getLayerCount(scale);
this.resetAllAnimationFrames(); this.resetAllAnimationFrames();
} }
@ -284,7 +282,7 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
const animationId = this.getAnimationId(animationData); const animationId = this.getAnimationId(animationData);
let frameCount = animationData.frameCounter; let frameCount = animationData.frameCounter;
if(!frameCount) frameCount = this._data.getStartFrame(scale, animationId, this._direction); if(!frameCount) frameCount = this.data.getStartFrame(scale, animationId, this._direction);
frameCount += this.frameIncrease; frameCount += this.frameIncrease;
animationData.frameCounter = frameCount; animationData.frameCounter = frameCount;
@ -322,11 +320,11 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
if(sequenceId === AnimationFrame.SEQUENCE_NOT_DEFINED) if(sequenceId === AnimationFrame.SEQUENCE_NOT_DEFINED)
{ {
frame = this._data.getFrame(scale, animationId, this._direction, layerId, frameCount); frame = this.data.getFrame(scale, animationId, this._direction, layerId, frameCount);
} }
else else
{ {
frame = this._data.getFrameFromSequence(scale, animationId, this._direction, layerId, sequenceId, (frame.activeSequenceOffset + frame.repeats), frameCount); frame = this.data.getFrameFromSequence(scale, animationId, this._direction, layerId, sequenceId, (frame.activeSequenceOffset + frame.repeats), frameCount);
} }
animationData.setFrame(layerId, frame); animationData.setFrame(layerId, frame);
@ -405,4 +403,9 @@ export class FurnitureAnimatedVisualization extends FurnitureVisualization
{ {
return this._frameIncrease; return this._frameIncrease;
} }
protected get data(): FurnitureAnimatedVisualizationData
{
return this._data as FurnitureAnimatedVisualizationData;
}
} }

View File

@ -6,8 +6,6 @@ export class FurnitureMannequinVisualization extends FurnitureVisualization impl
{ {
private static AVATAR_IMAGE_SPRITE_TAG: string = 'avatar_image'; private static AVATAR_IMAGE_SPRITE_TAG: string = 'avatar_image';
protected _data: FurnitureMannequinVisualizationData;
private _mannequinScale: number; private _mannequinScale: number;
private _figure: string; private _figure: string;
private _gender: string; private _gender: string;
@ -101,7 +99,7 @@ export class FurnitureMannequinVisualization extends FurnitureVisualization impl
{ {
if(!this.avatarExists() || forceUpdate) if(!this.avatarExists() || forceUpdate)
{ {
const avatarImage = this._data.createAvatarImage(this._figure, this._mannequinScale, this._gender, this); const avatarImage = this.data.createAvatarImage(this._figure, this._mannequinScale, this._gender, this);
if(avatarImage) if(avatarImage)
{ {
@ -168,4 +166,9 @@ export class FurnitureMannequinVisualization extends FurnitureVisualization impl
{ {
return this._disposed; return this._disposed;
} }
protected get data(): FurnitureMannequinVisualizationData
{
return this._data as FurnitureMannequinVisualizationData;
}
} }

View File

@ -580,4 +580,9 @@ export class FurnitureVisualization extends RoomObjectSpriteVisualization
{ {
return this._direction; return this._direction;
} }
protected get data(): FurnitureVisualizationData
{
return this._data;
}
} }

View File

@ -19,8 +19,6 @@ export class PetVisualization extends FurnitureAnimatedVisualization
private static GESTURE_ANIMATION_INDEX: number = 1; private static GESTURE_ANIMATION_INDEX: number = 1;
private static ANIMATION_INDEX_COUNT: number = 2; private static ANIMATION_INDEX_COUNT: number = 2;
protected _data: PetVisualizationData;
private _posture: string; private _posture: string;
private _gesture: string; private _gesture: string;
private _isSleeping: boolean; private _isSleeping: boolean;
@ -48,8 +46,6 @@ export class PetVisualization extends FurnitureAnimatedVisualization
{ {
super(); super();
this._data = null;
this._posture = ''; this._posture = '';
this._gesture = ''; this._gesture = '';
this._isSleeping = false; this._isSleeping = false;
@ -195,7 +191,7 @@ export class PetVisualization extends FurnitureAnimatedVisualization
const headDirection = model.getValue<number>(RoomObjectVariable.HEAD_DIRECTION); const headDirection = model.getValue<number>(RoomObjectVariable.HEAD_DIRECTION);
if(!isNaN(headDirection) && this._data.isAllowedToTurnHead) if(!isNaN(headDirection) && this.data.isAllowedToTurnHead)
{ {
this._headDirection = headDirection; this._headDirection = headDirection;
} }
@ -253,22 +249,22 @@ export class PetVisualization extends FurnitureAnimatedVisualization
protected setPostureAndGesture(posture: string, gesture: string): void protected setPostureAndGesture(posture: string, gesture: string): void
{ {
if(!this._data) return; if(!this.data) return;
if(posture !== this._posture) if(posture !== this._posture)
{ {
this._posture = posture; this._posture = posture;
this.setAnimationForIndex(PetVisualization.POSTURE_ANIMATION_INDEX, this._data.postureToAnimation(this._scale, posture)); this.setAnimationForIndex(PetVisualization.POSTURE_ANIMATION_INDEX, this.data.postureToAnimation(this._scale, posture));
} }
if(this._data.getGestureDisabled(this._scale, posture)) gesture = null; if(this.data.getGestureDisabled(this._scale, posture)) gesture = null;
if(gesture !== this._gesture) if(gesture !== this._gesture)
{ {
this._gesture = gesture; this._gesture = gesture;
this.setAnimationForIndex(PetVisualization.GESTURE_ANIMATION_INDEX, this._data.gestureToAnimation(this._scale, gesture)); this.setAnimationForIndex(PetVisualization.GESTURE_ANIMATION_INDEX, this.data.gestureToAnimation(this._scale, gesture));
} }
} }
@ -431,16 +427,16 @@ export class PetVisualization extends FurnitureAnimatedVisualization
protected getLayerZOffset(scale: number, direction: number, layerId: number): number protected getLayerZOffset(scale: number, direction: number, layerId: number): number
{ {
if(!this._data) return LayerData.DEFAULT_ZOFFSET; if(!this.data) return LayerData.DEFAULT_ZOFFSET;
return this._data.getLayerZOffset(scale, this.getDirection(scale, layerId), layerId); return this.data.getLayerZOffset(scale, this.getDirection(scale, layerId), layerId);
} }
private getDirection(scale: number, layerId: number): number private getDirection(scale: number, layerId: number): number
{ {
if(!this.isHeadSprite(layerId)) return this._direction; if(!this.isHeadSprite(layerId)) return this._direction;
return this._data.getValidDirection(scale, this._headDirection); return this.data.getValidDirection(scale, this._headDirection);
} }
protected getFrameNumber(scale: number, layerId: number): number protected getFrameNumber(scale: number, layerId: number): number
@ -468,8 +464,8 @@ export class PetVisualization extends FurnitureAnimatedVisualization
{ {
if(this._headSprites[layerId] === undefined) if(this._headSprites[layerId] === undefined)
{ {
const isHead = (this._data.getLayerTag(this._scale, DirectionData.USE_DEFAULT_DIRECTION, layerId) === PetVisualization.HEAD); const isHead = (this.data.getLayerTag(this._scale, DirectionData.USE_DEFAULT_DIRECTION, layerId) === PetVisualization.HEAD);
const isHair = (this._data.getLayerTag(this._scale, DirectionData.USE_DEFAULT_DIRECTION, layerId) === PetVisualization.HAIR); const isHair = (this.data.getLayerTag(this._scale, DirectionData.USE_DEFAULT_DIRECTION, layerId) === PetVisualization.HAIR);
if(isHead || isHair) this._headSprites[layerId] = true; if(isHead || isHair) this._headSprites[layerId] = true;
else this._headSprites[layerId] = false; else this._headSprites[layerId] = false;
@ -484,7 +480,7 @@ export class PetVisualization extends FurnitureAnimatedVisualization
{ {
if(layerId < (this.totalSprites - (1 + PetVisualization.ADDITIONAL_SPRITE_COUNT))) if(layerId < (this.totalSprites - (1 + PetVisualization.ADDITIONAL_SPRITE_COUNT)))
{ {
const tag = this._data.getLayerTag(this._scale, DirectionData.USE_DEFAULT_DIRECTION, layerId); const tag = this.data.getLayerTag(this._scale, DirectionData.USE_DEFAULT_DIRECTION, layerId);
if(((tag && (tag.length > 0)) && (tag !== PetVisualization.HEAD)) && (tag !== PetVisualization.HAIR)) if(((tag && (tag.length > 0)) && (tag !== PetVisualization.HEAD)) && (tag !== PetVisualization.HAIR))
{ {
@ -508,7 +504,7 @@ export class PetVisualization extends FurnitureAnimatedVisualization
{ {
if(this._saddleSprites[layerId] === undefined) if(this._saddleSprites[layerId] === undefined)
{ {
if(this._data.getLayerTag(this._scale, DirectionData.USE_DEFAULT_DIRECTION, layerId) === PetVisualization.SADDLE) if(this.data.getLayerTag(this._scale, DirectionData.USE_DEFAULT_DIRECTION, layerId) === PetVisualization.SADDLE)
{ {
this._saddleSprites[layerId] = true; this._saddleSprites[layerId] = true;
} }
@ -583,9 +579,9 @@ export class PetVisualization extends FurnitureAnimatedVisualization
part = part.split('@')[0]; part = part.split('@')[0];
posture = this._data.animationToPosture(scale, (parseInt(part) / 100), false); posture = this.data.animationToPosture(scale, (parseInt(part) / 100), false);
if(!posture) posture = this._data.getGestureForAnimationId(scale, (parseInt(part) / 100)); if(!posture) posture = this.data.getGestureForAnimationId(scale, (parseInt(part) / 100));
} }
return posture; return posture;
@ -595,4 +591,9 @@ export class PetVisualization extends FurnitureAnimatedVisualization
{ {
return GetAssetManager().getTexture(name); return GetAssetManager().getTexture(name);
} }
protected get data(): PetVisualizationData
{
return this._data as PetVisualizationData;
}
} }

View File

@ -1,14 +1,14 @@
import { RenderTexture, Resource, Texture } from '@pixi/core'; import { Renderer, RenderTexture, Resource, Texture } from '@pixi/core';
import { Graphics } from '@pixi/graphics'; import { Matrix, Point } from '@pixi/math';
import { Matrix, Point, Rectangle } from '@pixi/math'; import { Sprite } from '@pixi/sprite';
import { IRoomGeometry, IRoomPlane, IVector3D, Vector3d } from '../../../../../api'; import { IRoomGeometry, IRoomPlane, IVector3D, Vector3d } from '../../../../../api';
import { NitroRenderTexture, TextureUtils } from '../../../../../pixi-proxy'; import { PixiApplicationProxy, RoomTextureUtils, TextureUtils } from '../../../../../pixi-proxy';
import { ColorConverter } from '../../../../../room';
import { PlaneMaskManager } from './mask'; import { PlaneMaskManager } from './mask';
import { PlaneDrawingData } from './PlaneDrawingData'; import { PlaneDrawingData } from './PlaneDrawingData';
import { IPlaneRasterizer, PlaneVisualizationLayer } from './rasterizer'; import { IPlaneRasterizer } from './rasterizer';
import { RoomPlaneBitmapMask } from './RoomPlaneBitmapMask'; import { RoomPlaneBitmapMask } from './RoomPlaneBitmapMask';
import { RoomPlaneRectangleMask } from './RoomPlaneRectangleMask'; import { RoomPlaneRectangleMask } from './RoomPlaneRectangleMask';
import { RoomVisualization } from './RoomVisualization';
import { PlaneBitmapData, Randomizer } from './utils'; import { PlaneBitmapData, Randomizer } from './utils';
export class RoomPlane implements IRoomPlane export class RoomPlane implements IRoomPlane
@ -31,8 +31,7 @@ export class RoomPlane implements IRoomPlane
private _geometryUpdateId: number; private _geometryUpdateId: number;
private _type: number; private _type: number;
private _isVisible: boolean; private _isVisible: boolean;
private _bitmapTexture: NitroRenderTexture; private _bitmapData: RenderTexture;
private _bitmapData: Graphics;
private _hasTexture: boolean; private _hasTexture: boolean;
private _offset: Point; private _offset: Point;
private _relativeDepth: number; private _relativeDepth: number;
@ -51,7 +50,8 @@ export class RoomPlane implements IRoomPlane
private _bitmapMasks: RoomPlaneBitmapMask[]; private _bitmapMasks: RoomPlaneBitmapMask[];
private _rectangleMasks: RoomPlaneRectangleMask[]; private _rectangleMasks: RoomPlaneRectangleMask[];
private _maskChanged: boolean; private _maskChanged: boolean;
private _maskBitmapData: Graphics; private _maskBitmapData: RenderTexture;
private _maskPixels: Uint8Array;
private _bitmapMasksOld: RoomPlaneBitmapMask[]; private _bitmapMasksOld: RoomPlaneBitmapMask[];
private _rectangleMasksOld: RoomPlaneRectangleMask[]; private _rectangleMasksOld: RoomPlaneRectangleMask[];
private _cornerA: Vector3d; private _cornerA: Vector3d;
@ -128,10 +128,9 @@ export class RoomPlane implements IRoomPlane
this._uniqueId = ++RoomPlane._uniqueIdCounter; this._uniqueId = ++RoomPlane._uniqueIdCounter;
} }
private static blend(k: number, _arg_2: number): number private static blend(a: number, b: number): number
{ {
return 0; return ColorConverter.colorize(b, (a | 0xFF000000)) & 0xFFFFFF;
//return Canvas.colorize(_arg_2, (k | 0xFF000000)) & 0xFFFFFF;
} }
public set canBeVisible(k: boolean) public set canBeVisible(k: boolean)
@ -153,16 +152,14 @@ export class RoomPlane implements IRoomPlane
{ {
if(!this.visible || !this._bitmapData) return null; if(!this.visible || !this._bitmapData) return null;
let texture: RenderTexture = RoomVisualization.getTextureCache(this._bitmapData); return this._bitmapData;
}
if(!texture) public get maskBitmapData(): RenderTexture
{ {
texture = TextureUtils.generateTexture(this._bitmapData, new Rectangle(0, 0, this._width, this._height)); if(!this.visible || !this._maskBitmapData) return null;
RoomVisualization.addTextureCache(this._bitmapData, texture); return this._maskBitmapData;
}
return texture;
} }
public get visible(): boolean public get visible(): boolean
@ -252,7 +249,7 @@ export class RoomPlane implements IRoomPlane
{ {
if(this._bitmapData) if(this._bitmapData)
{ {
this._bitmapData.destroy(); this._bitmapData.destroy(true);
this._bitmapData = null; this._bitmapData = null;
} }
@ -263,7 +260,7 @@ export class RoomPlane implements IRoomPlane
{ {
if(!bitmap) continue; if(!bitmap) continue;
if(bitmap.bitmap) bitmap.bitmap.destroy(); if(bitmap.texture) bitmap.texture.destroy();
bitmap.dispose(); bitmap.dispose();
} }
@ -284,10 +281,11 @@ export class RoomPlane implements IRoomPlane
this._cornerD = null; this._cornerD = null;
this._bitmapMasks = null; this._bitmapMasks = null;
this._rectangleMasks = null; this._rectangleMasks = null;
this._maskPixels = null;
if(this._maskBitmapData) if(this._maskBitmapData)
{ {
this._maskBitmapData.destroy(); this._maskBitmapData.destroy(true);
this._maskBitmapData = null; this._maskBitmapData = null;
} }
@ -322,7 +320,7 @@ export class RoomPlane implements IRoomPlane
return true; return true;
} }
private resetTextureCache(k: Graphics = null): void private resetTextureCache(k: RenderTexture = null): void
{ {
if(this._textures && this._textures.size) if(this._textures && this._textures.size)
{ {
@ -364,75 +362,68 @@ export class RoomPlane implements IRoomPlane
return false; return false;
} }
private getTexture(k: IRoomGeometry, _arg_2: number): Graphics private getTexture(geometry: IRoomGeometry, timeSinceStartMs: number): RenderTexture
{ {
if(!k) return null; if(!geometry) return null;
let _local_3: PlaneBitmapData = null; let bitmapData: PlaneBitmapData = null;
if(this.needsNewTexture(k, _arg_2)) if(this.needsNewTexture(geometry, timeSinceStartMs))
{ {
const _local_4 = this.getTextureIdentifier(k.scale); const identifier = this.getTextureIdentifier(geometry.scale);
const _local_5 = (this._leftSide.length * k.scale); const width = this._leftSide.length * geometry.scale;
const _local_6 = (this._rightSide.length * k.scale); const height = this._rightSide.length * geometry.scale;
const _local_7 = k.getCoordinatePosition(this._normal); const normal = geometry.getCoordinatePosition(this._normal);
if(this._activeTexture) if(this._activeTexture)
{ {
_local_3 = this._activeTexture; bitmapData = this._activeTexture;
} }
else else
{ {
_local_3 = this._textures.get(_local_4); bitmapData = this._textures.get(identifier);
} }
let _local_8: Graphics = null; let texture: RenderTexture = null;
if(_local_3) _local_8 = _local_3.bitmap; if(bitmapData) texture = bitmapData.texture;
if(this._rasterizer) if(this._rasterizer)
{ {
_local_3 = this._rasterizer.render(_local_8, this._id, _local_5, _local_6, k.scale, _local_7, this._hasTexture, this._textureOffsetX, this._textureOffsetY, this._textureMaxX, this._textureMaxY, _arg_2); bitmapData = this._rasterizer.render(this._uniqueId.toString(), texture, this._id, width, height, geometry.scale, normal, this._hasTexture, this._textureOffsetX, this._textureOffsetY, this._textureMaxX, this._textureMaxY, timeSinceStartMs);
if(_local_3) if(bitmapData && texture && (bitmapData?.texture !== texture)) texture.destroy(true);
{
if(_local_8 && (_local_3.bitmap !== _local_8)) _local_8.destroy();
}
} }
else else
{ {
const _local_9 = new Graphics(); const renderTexture = RoomTextureUtils.createAndFillRenderTexture(width, height);
_local_9.beginFill(0xFFFFFF); bitmapData = new PlaneBitmapData(renderTexture, -1);
_local_9.drawRect(0, 0, _local_5, _local_6);
_local_9.endFill();
_local_3 = new PlaneBitmapData(_local_9, -1);
} }
if(_local_3) if(bitmapData)
{ {
this.updateMask(_local_3.bitmap, k); this.updateMask(bitmapData.texture, geometry);
this.cacheTexture(_local_4, _local_3); this.cacheTexture(identifier, bitmapData);
} }
} }
else else
{ {
if(this._activeTexture) if(this._activeTexture)
{ {
_local_3 = this._activeTexture; bitmapData = this._activeTexture;
} }
else else
{ {
_local_3 = this._textures.get(this.getTextureIdentifier(k.scale)); bitmapData = this._textures.get(this.getTextureIdentifier(geometry.scale));
} }
} }
if(_local_3) if(bitmapData)
{ {
this._activeTexture = _local_3; this._activeTexture = bitmapData;
return _local_3.bitmap; return bitmapData.texture;
} }
return null; return null;
@ -442,7 +433,7 @@ export class RoomPlane implements IRoomPlane
{ {
if(!this._useMask) return null; if(!this._useMask) return null;
const _local_5 = new PlaneDrawingData(); const drawingData = new PlaneDrawingData();
const index = 0; const index = 0;
@ -465,18 +456,17 @@ export class RoomPlane implements IRoomPlane
if(asset) if(asset)
{ {
const _local_3 = (this._maskBitmapData.width * (1 - (mask.leftSideLoc / this._leftSide.length))); const x = (this._maskBitmapData.width * (1 - (mask.leftSideLoc / this._leftSide.length)));
const _local_4 = (this._maskBitmapData.height * (1 - (mask.rightSideLoc / this._rightSide.length))); const y = (this._maskBitmapData.height * (1 - (mask.rightSideLoc / this._rightSide.length)));
const _local_11 = new Point((_local_3 + asset.offsetX), (_local_4 + asset.offsetY));
_local_5.addMask(assetName, _local_11, asset.flipH, asset.flipV); drawingData.addMask(assetName, new Point((x + asset.offsetX), (y + asset.offsetY)), asset.flipH, asset.flipV);
} }
} }
} }
} }
} }
return _local_5; return drawingData;
} }
private screenWidth(k: IRoomGeometry): number private screenWidth(k: IRoomGeometry): number
@ -496,54 +486,43 @@ export class RoomPlane implements IRoomPlane
const maskData = this.resolveMasks(geometry); const maskData = this.resolveMasks(geometry);
const layers = this._rasterizer.getLayers(this._id); const layers = this._rasterizer.getLayers(this._id);
let i = 0; for(const layer of layers)
while(i < layers.length)
{ {
const layer = (layers[i] as PlaneVisualizationLayer); if(this._hasTexture && layer.getMaterial())
if(layer)
{ {
if(this._hasTexture && layer.getMaterial()) const normal = geometry.getCoordinatePosition(this._normal);
const cellMatrix = layer.getMaterial().getMaterialCellMatrix(normal);
const data = new PlaneDrawingData(maskData, RoomPlane.blend(this._color, layer.getColor()), cellMatrix.isBottomAligned());
Randomizer.setSeed(this._randomSeed);
for(const column of cellMatrix.getColumns(this.screenWidth(geometry)))
{ {
const normal = geometry.getCoordinatePosition(this._normal); const assetNames: string[] = [];
const cm = layer.getMaterial().getMaterialCellMatrix(normal);
//const data = new PlaneDrawingData(maskData, blend(this._color, layer.getColor()), cm.isBottomAligned());
const data = new PlaneDrawingData(maskData, this._color, cm.isBottomAligned());
Randomizer.setSeed(this._randomSeed); for(const cell of column.getCells())
for(const column of cm.getColumns(this.screenWidth(geometry)))
{ {
const assetNames: string[] = []; const name = cell.getAssetName(normal);
for(const cell of column.getCells()) if(name) assetNames.push(name);
{
const name = cell.getAssetName(normal);
if(name) assetNames.push(name);
}
if(assetNames.length > 0)
{
if(!column.isRepeated()) assetNames.push('');
data.addAssetColumn(assetNames);
}
} }
if(data.assetNameColumns.length > 0) drawingDatas.push(data); if(assetNames.length > 0)
} {
else if(!column.isRepeated()) assetNames.push('');
{
//data = new PlaneDrawingData(maskData, blend(this._color, layer.getColor()));
const data = new PlaneDrawingData(maskData, this._color);
drawingDatas.push(data); data.addAssetColumn(assetNames);
}
} }
if(data.assetNameColumns.length > 0) drawingDatas.push(data);
} }
else
{
const data = new PlaneDrawingData(maskData, RoomPlane.blend(this._color, layer.getColor()));
i++; drawingDatas.push(data);
}
} }
if(!drawingDatas.length) drawingDatas.push(new PlaneDrawingData(maskData, this._color)); if(!drawingDatas.length) drawingDatas.push(new PlaneDrawingData(maskData, this._color));
@ -636,31 +615,42 @@ export class RoomPlane implements IRoomPlane
{ {
if(this._bitmapData) if(this._bitmapData)
{ {
this._bitmapData.destroy(); if((this._width !== this._bitmapData.width) || (this._height !== this._bitmapData.height))
{
this._bitmapData.destroy();
this._bitmapData = null; this._bitmapData = null;
if((this._width < 1) || (this._height < 1)) return true; if((this._width < 1) || (this._height < 1)) return true;
this._bitmapData = RoomTextureUtils.createAndFillRenderTexture(this._width, this._height);
}
else
{
if((this._width < 1) || (this._height < 1))
{
this._bitmapData.destroy();
this._bitmapData = null;
return true;
}
TextureUtils.clearAndFillRenderTexture(this._bitmapData);
}
} }
else else
{ {
if((this._width < 1) || (this._height < 1)) return false; if((this._width < 1) || (this._height < 1)) return false;
this._bitmapData = RoomTextureUtils.createAndFillRenderTexture(this._width, this._height);
} }
const graphic = new Graphics();
graphic.beginFill(0xFFFFFF, 0);
graphic.drawRect(0, 0, this._width, this._height);
graphic.endFill();
this._bitmapData = graphic;
if(!this._bitmapData) return false; if(!this._bitmapData) return false;
} }
else else
{ {
//this._bitmapData.lock(); TextureUtils.clearAndFillRenderTexture(this._bitmapData);
//this._bitmapData.fillRect(this._bitmapData.rect, 0xFFFFFF);
} }
Randomizer.setSeed(this._randomSeed); Randomizer.setSeed(this._randomSeed);
@ -684,13 +674,13 @@ export class RoomPlane implements IRoomPlane
return false; return false;
} }
private updateCorners(k: IRoomGeometry): void private updateCorners(geometry: IRoomGeometry): void
{ {
this._cornerA.assign(k.getScreenPosition(this._location)); this._cornerA.assign(geometry.getScreenPosition(this._location));
this._cornerB.assign(k.getScreenPosition(Vector3d.sum(this._location, this._rightSide))); this._cornerB.assign(geometry.getScreenPosition(Vector3d.sum(this._location, this._rightSide)));
this._cornerC.assign(k.getScreenPosition(Vector3d.sum(Vector3d.sum(this._location, this._leftSide), this._rightSide))); this._cornerC.assign(geometry.getScreenPosition(Vector3d.sum(Vector3d.sum(this._location, this._leftSide), this._rightSide)));
this._cornerD.assign(k.getScreenPosition(Vector3d.sum(this._location, this._leftSide))); this._cornerD.assign(geometry.getScreenPosition(Vector3d.sum(this._location, this._leftSide)));
this._offset = k.getScreenPoint(this._origin); this._offset = geometry.getScreenPoint(this._origin);
this._cornerA.x = Math.round(this._cornerA.x); this._cornerA.x = Math.round(this._cornerA.x);
this._cornerA.y = Math.round(this._cornerA.y); this._cornerA.y = Math.round(this._cornerA.y);
this._cornerB.x = Math.round(this._cornerB.x); this._cornerB.x = Math.round(this._cornerB.x);
@ -701,76 +691,74 @@ export class RoomPlane implements IRoomPlane
this._cornerD.y = Math.round(this._cornerD.y); this._cornerD.y = Math.round(this._cornerD.y);
this._offset.x = Math.round(this._offset.x); this._offset.x = Math.round(this._offset.x);
this._offset.y = Math.round(this._offset.y); this._offset.y = Math.round(this._offset.y);
const _local_2: number = Math.min(this._cornerA.x, this._cornerB.x, this._cornerC.x, this._cornerD.x);
let _local_3: number = Math.max(this._cornerA.x, this._cornerB.x, this._cornerC.x, this._cornerD.x); const minX = Math.min(this._cornerA.x, this._cornerB.x, this._cornerC.x, this._cornerD.x);
const _local_4: number = Math.min(this._cornerA.y, this._cornerB.y, this._cornerC.y, this._cornerD.y); const maxX = Math.max(this._cornerA.x, this._cornerB.x, this._cornerC.x, this._cornerD.x) - minX;
let _local_5: number = Math.max(this._cornerA.y, this._cornerB.y, this._cornerC.y, this._cornerD.y); const minY = Math.min(this._cornerA.y, this._cornerB.y, this._cornerC.y, this._cornerD.y);
_local_3 = (_local_3 - _local_2); const maxY = Math.max(this._cornerA.y, this._cornerB.y, this._cornerC.y, this._cornerD.y) - minY;
this._offset.x = (this._offset.x - _local_2);
this._cornerA.x = (this._cornerA.x - _local_2); this._offset.x = (this._offset.x - minX);
this._cornerB.x = (this._cornerB.x - _local_2); this._cornerA.x = (this._cornerA.x - minX);
this._cornerC.x = (this._cornerC.x - _local_2); this._cornerB.x = (this._cornerB.x - minX);
this._cornerD.x = (this._cornerD.x - _local_2); this._cornerC.x = (this._cornerC.x - minX);
_local_5 = (_local_5 - _local_4); this._cornerD.x = (this._cornerD.x - minX);
this._offset.y = (this._offset.y - _local_4);
this._cornerA.y = (this._cornerA.y - _local_4); this._offset.y = (this._offset.y - minY);
this._cornerB.y = (this._cornerB.y - _local_4); this._cornerA.y = (this._cornerA.y - minY);
this._cornerC.y = (this._cornerC.y - _local_4); this._cornerB.y = (this._cornerB.y - minY);
this._cornerD.y = (this._cornerD.y - _local_4); this._cornerC.y = (this._cornerC.y - minY);
this._width = _local_3; this._cornerD.y = (this._cornerD.y - minY);
this._height = _local_5;
this._width = maxX;
this._height = maxY;
} }
private renderTexture(k: IRoomGeometry, _arg_2: Graphics): void private getMatrixForDimensions(width: number, height: number): Matrix
{
let _local_3: number = (this._cornerD.x - this._cornerC.x);
let _local_4: number = (this._cornerD.y - this._cornerC.y);
let _local_5: number = (this._cornerB.x - this._cornerC.x);
let _local_6: number = (this._cornerB.y - this._cornerC.y);
if((this._type === RoomPlane.TYPE_WALL) || (this._type === RoomPlane.TYPE_LANDSCAPE))
{
if(Math.abs((_local_5 - width)) <= 1) _local_5 = width;
if(Math.abs((_local_6 - width)) <= 1) _local_6 = width;
if(Math.abs((_local_3 - height)) <= 1) _local_3 = height;
if(Math.abs((_local_4 - height)) <= 1) _local_4 = height;
}
const xScale: number = (_local_5 / width);
const ySkew: number = (_local_6 / width);
const xSkew: number = (_local_3 / height);
const yScale: number = (_local_4 / height);
const matrix = new Matrix(xScale, ySkew, xSkew, yScale);
matrix.translate(this._cornerC.x, this._cornerC.y);
return matrix;
}
private renderTexture(geometry: IRoomGeometry, _arg_2: RenderTexture): void
{ {
if(((((((this._cornerA == null) || (this._cornerB == null)) || (this._cornerC == null)) || (this._cornerD == null)) || (_arg_2 == null)) || (this._bitmapData == null))) if(((((((this._cornerA == null) || (this._cornerB == null)) || (this._cornerC == null)) || (this._cornerD == null)) || (_arg_2 == null)) || (this._bitmapData == null)))
{ {
return; return;
} }
let _local_3: number = (this._cornerD.x - this._cornerC.x);
let _local_4: number = (this._cornerD.y - this._cornerC.y);
let _local_5: number = (this._cornerB.x - this._cornerC.x);
let _local_6: number = (this._cornerB.y - this._cornerC.y);
if(((this._type == RoomPlane.TYPE_WALL) || (this._type == RoomPlane.TYPE_LANDSCAPE)))
{
if(Math.abs((_local_5 - _arg_2.width)) <= 1)
{
_local_5 = _arg_2.width;
}
if(Math.abs((_local_6 - _arg_2.width)) <= 1)
{
_local_6 = _arg_2.width;
}
if(Math.abs((_local_3 - _arg_2.height)) <= 1)
{
_local_3 = _arg_2.height;
}
if(Math.abs((_local_4 - _arg_2.height)) <= 1)
{
_local_4 = _arg_2.height;
}
}
const _local_7: number = (_local_5 / _arg_2.width);
const _local_8: number = (_local_6 / _arg_2.width);
const _local_9: number = (_local_3 / _arg_2.height);
const _local_10: number = (_local_4 / _arg_2.height);
const matrix = new Matrix();
matrix.a = _local_7;
matrix.b = _local_8;
matrix.c = _local_9;
matrix.d = _local_10;
matrix.translate(this._cornerC.x, this._cornerC.y);
this.draw(_arg_2, matrix); this.draw(_arg_2, this.getMatrixForDimensions(_arg_2.width, _arg_2.height));
} }
private draw(k: Graphics, matrix: Matrix): void private draw(k: RenderTexture, matrix: Matrix): void
{ {
const clone = k.clone(); //k.baseTexture.mipmap = MIPMAP_MODES.OFF;
//k.baseTexture.scaleMode = SCALE_MODES.LINEAR;
clone.transform.setFromMatrix(matrix); TextureUtils.writeToRenderTexture(new Sprite(k), this._bitmapData, true, matrix);
this._bitmapData = clone;
} }
public resetBitmapMasks(): void public resetBitmapMasks(): void
@ -781,25 +769,18 @@ export class RoomPlane implements IRoomPlane
this._bitmapMasks = []; this._bitmapMasks = [];
} }
public addBitmapMask(k: string, _arg_2: number, _arg_3: number): boolean public addBitmapMask(maskType: string, leftSideLoc: number, rightSideLoc: number): boolean
{ {
if(!this._useMask) return false; if(!this._useMask) return false;
let _local_5 = 0; for(const mask of this._bitmapMasks)
while(_local_5 < this._bitmapMasks.length)
{ {
const mask = this._bitmapMasks[_local_5]; if(!mask) continue;
if(mask) if((((mask.type === maskType) && (mask.leftSideLoc === leftSideLoc)) && (mask.rightSideLoc === rightSideLoc))) return false;
{
if((((mask.type === k) && (mask.leftSideLoc === _arg_2)) && (mask.rightSideLoc === _arg_3))) return false;
}
_local_5++;
} }
const mask = new RoomPlaneBitmapMask(k, _arg_2, _arg_3); const mask = new RoomPlaneBitmapMask(maskType, leftSideLoc, rightSideLoc);
this._bitmapMasks.push(mask); this._bitmapMasks.push(mask);
this._maskChanged = true; this._maskChanged = true;
@ -841,8 +822,7 @@ export class RoomPlane implements IRoomPlane
{ {
if(!this._maskChanged) return; if(!this._maskChanged) return;
let _local_3 = true; let maskChanged = true;
let _local_6: boolean;
if(this._bitmapMasks.length === this._bitmapMasksOld.length) if(this._bitmapMasks.length === this._bitmapMasksOld.length)
{ {
@ -850,7 +830,7 @@ export class RoomPlane implements IRoomPlane
{ {
if(!mask) continue; if(!mask) continue;
_local_6 = false; let _local_6 = false;
for(const plane of this._bitmapMasksOld) for(const plane of this._bitmapMasksOld)
{ {
@ -866,7 +846,7 @@ export class RoomPlane implements IRoomPlane
if(!_local_6) if(!_local_6)
{ {
_local_3 = false; maskChanged = false;
break; break;
} }
@ -874,22 +854,22 @@ export class RoomPlane implements IRoomPlane
} }
else else
{ {
_local_3 = false; maskChanged = false;
} }
if(this._rectangleMasks.length > this._rectangleMasksOld.length) _local_3 = false; if(this._rectangleMasks.length > this._rectangleMasksOld.length) maskChanged = false;
if(_local_3) this._maskChanged = false; if(maskChanged) this._maskChanged = false;
} }
private updateMask(texture: Graphics, geometry: IRoomGeometry): void private updateMask(canvas: RenderTexture, geometry: IRoomGeometry): void
{ {
if(!texture || !geometry) return; if(!canvas || !geometry) return;
if(((!this._useMask) || ((!this._bitmapMasks.length && !this._rectangleMasks.length) && !this._maskChanged)) || !this._maskManager) return; if(((!this._useMask) || ((!this._bitmapMasks.length && !this._rectangleMasks.length) && !this._maskChanged)) || !this._maskManager) return;
const width = texture.width; const width = canvas.width;
const height = texture.height; const height = canvas.height;
this.updateMaskChangeStatus(); this.updateMaskChangeStatus();
@ -897,18 +877,11 @@ export class RoomPlane implements IRoomPlane
{ {
if(this._maskBitmapData) if(this._maskBitmapData)
{ {
this._maskBitmapData.destroy(); this._maskBitmapData.destroy(true);
this._maskBitmapData = null; this._maskBitmapData = null;
} }
const graphic = new Graphics(); this._maskBitmapData = RoomTextureUtils.createAndFillRenderTexture(width, height);
graphic
.beginFill(0xFFFFFF, 0)
.drawRect(0, 0, width, height)
.endFill();
this._maskBitmapData = graphic;
this._maskChanged = true; this._maskChanged = true;
} }
@ -917,15 +890,9 @@ export class RoomPlane implements IRoomPlane
this._bitmapMasksOld = []; this._bitmapMasksOld = [];
this._rectangleMasksOld = []; this._rectangleMasksOld = [];
if(this._maskBitmapData) if(this._maskBitmapData) TextureUtils.clearAndFillRenderTexture(this._maskBitmapData);
{
this._maskBitmapData
.beginFill(0xFFFFFF, 0)
.drawRect(0, 0, width, height)
.endFill();
}
this.resetTextureCache(texture); this.resetTextureCache(canvas);
const normal = geometry.getCoordinatePosition(this._normal); const normal = geometry.getCoordinatePosition(this._normal);
@ -965,10 +932,10 @@ export class RoomPlane implements IRoomPlane
const wd = ((this._maskBitmapData.width * rectMask.leftSideLength) / this._leftSide.length); const wd = ((this._maskBitmapData.width * rectMask.leftSideLength) / this._leftSide.length);
const ht = ((this._maskBitmapData.height * rectMask.rightSideLength) / this._rightSide.length); const ht = ((this._maskBitmapData.height * rectMask.rightSideLength) / this._rightSide.length);
this._maskBitmapData /* this._maskBitmapData
.beginFill(0xFF0000) .beginFill(0xFF0000)
.drawRect((posX - wd), (posY - ht), wd, ht) .drawRect((posX - wd), (posY - ht), wd, ht)
.endFill(); .endFill(); */
this._rectangleMasksOld.push(new RoomPlaneRectangleMask(rectMask.leftSideLength, rectMask.rightSideLoc, rectMask.leftSideLength, rectMask.rightSideLength)); this._rectangleMasksOld.push(new RoomPlaneRectangleMask(rectMask.leftSideLength, rectMask.rightSideLoc, rectMask.leftSideLength, rectMask.rightSideLength));
} }
@ -976,45 +943,36 @@ export class RoomPlane implements IRoomPlane
i++; i++;
} }
this._maskPixels = TextureUtils.getPixels(this._maskBitmapData);
this._maskChanged = false; this._maskChanged = false;
} }
this.combineTextureMask(texture, this._maskBitmapData); this.combineTextureMask(canvas, this._maskPixels);
} }
private combineTextureMask(texture: Graphics, mask: Graphics): void private combineTextureMask(canvas: RenderTexture, maskPixels: Uint8Array): void
{ {
if(!texture || !mask) return; if(!canvas || !maskPixels) return;
const maskCanvas = TextureUtils.generateCanvas(mask); const canvasPixels = TextureUtils.getPixels(canvas);
const textureCanvas = TextureUtils.generateCanvas(texture);
const textureCtx = textureCanvas.getContext('2d');
textureCtx.drawImage(maskCanvas, 0, 0); for(let i = 0; i < canvasPixels.length; i += 4)
const textureImageData = textureCtx.getImageData(0, 0, textureCanvas.width, textureCanvas.height);
const data = textureImageData.data;
for(let i = 0; i < data.length; i += 4)
{ {
const red = data[i]; const maskRed = maskPixels[i];
const green = data[i + 1]; const maskGreen = maskPixels[i + 1];
const blue = data[i + 2]; const maskBlue = maskPixels[i + 2];
const alpha = data[i + 3]; const maskAlpha = maskPixels[i + 3];
if(!red && !green && !blue) data[i + 3] = 0; if(!maskRed && !maskGreen && !maskBlue) canvasPixels[i + 3] = 0;
} }
textureCtx.putImageData(textureImageData, 0, 0); const canvaGLTexture = canvas.baseTexture._glTextures['1']?.texture;
const gl = (PixiApplicationProxy.instance.renderer as Renderer)?.gl;
const newTexture = Texture.from(textureCanvas); if(!canvaGLTexture || !gl) return;
if(!newTexture) return; gl.bindTexture(gl.TEXTURE_2D, canvaGLTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, canvasPixels);
texture
.clear()
.beginTextureFill({ texture: newTexture })
.drawRect(0, 0, newTexture.width, newTexture.height)
.endFill();
} }
} }

View File

@ -4,11 +4,11 @@
private _leftSideLoc: number; private _leftSideLoc: number;
private _rightSideLoc: number; private _rightSideLoc: number;
constructor(k: string, _arg_2: number, _arg_3: number) constructor(maskType: string, leftSideLoc: number, rightSideLoc: number)
{ {
this._type = k; this._type = maskType;
this._leftSideLoc = _arg_2; this._leftSideLoc = leftSideLoc;
this._rightSideLoc = _arg_3; this._rightSideLoc = rightSideLoc;
} }
public get type(): string public get type(): string

View File

@ -1,7 +1,8 @@
import { RenderTexture, Resource, Texture } from '@pixi/core';
import { Rectangle } from '@pixi/math'; import { Rectangle } from '@pixi/math';
import { AdvancedMap, AlphaTolerance, IObjectVisualizationData, IPlaneVisualization, IRoomGeometry, IRoomObjectModel, IRoomObjectSprite, IRoomPlane, RoomObjectSpriteType, RoomObjectVariable, Vector3d } from '../../../../../api'; import { AlphaTolerance, IObjectVisualizationData, IPlaneVisualization, IRoomGeometry, IRoomObjectModel, IRoomObjectSprite, IRoomPlane, RoomObjectSpriteType, RoomObjectVariable, Vector3d } from '../../../../../api';
import { RoomTextureUtils } from '../../../../../pixi-proxy';
import { RoomObjectSpriteVisualization } from '../../../../../room'; import { RoomObjectSpriteVisualization } from '../../../../../room';
import { ToInt32 } from '../../../../utils';
import { RoomMapData } from '../../RoomMapData'; import { RoomMapData } from '../../RoomMapData';
import { RoomMapMaskData } from '../../RoomMapMaskData'; import { RoomMapMaskData } from '../../RoomMapMaskData';
import { RoomPlaneBitmapMaskData } from '../../RoomPlaneBitmapMaskData'; import { RoomPlaneBitmapMaskData } from '../../RoomPlaneBitmapMaskData';
@ -13,10 +14,6 @@ import { RoomVisualizationData } from './RoomVisualizationData';
export class RoomVisualization extends RoomObjectSpriteVisualization implements IPlaneVisualization export class RoomVisualization extends RoomObjectSpriteVisualization implements IPlaneVisualization
{ {
public static LAST_VISUALIZATION: RoomVisualization = null;
public static RENDER_TEXTURE_CACHE: Map<RoomVisualization, AdvancedMap<any, RenderTexture>> = new Map();
public static FLOOR_COLOR: number = 0xFFFFFF; public static FLOOR_COLOR: number = 0xFFFFFF;
public static FLOOR_COLOR_LEFT: number = 0xDDDDDD; public static FLOOR_COLOR_LEFT: number = 0xDDDDDD;
public static FLOOR_COLOR_RIGHT: number = 0xBBBBBB; public static FLOOR_COLOR_RIGHT: number = 0xBBBBBB;
@ -102,31 +99,6 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
this._typeVisibility[RoomPlane.TYPE_LANDSCAPE] = true; this._typeVisibility[RoomPlane.TYPE_LANDSCAPE] = true;
} }
public static getTextureCache(key: any): RenderTexture
{
const existing = RoomVisualization.RENDER_TEXTURE_CACHE.get(RoomVisualization.LAST_VISUALIZATION);
if(!existing) return null;
return existing.getValue(key);
}
public static addTextureCache(key: any, value: RenderTexture): void
{
if(!RoomVisualization.LAST_VISUALIZATION) return;
let existing = RoomVisualization.RENDER_TEXTURE_CACHE.get(RoomVisualization.LAST_VISUALIZATION);
if(!existing)
{
existing = new AdvancedMap();
RoomVisualization.RENDER_TEXTURE_CACHE.set(RoomVisualization.LAST_VISUALIZATION, existing);
}
existing.add(key, value);
}
public initialize(data: IObjectVisualizationData): boolean public initialize(data: IObjectVisualizationData): boolean
{ {
if(!(data instanceof RoomVisualizationData)) return false; if(!(data instanceof RoomVisualizationData)) return false;
@ -171,19 +143,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
this._data = null; this._data = null;
} }
const existingTextureCache = RoomVisualization.RENDER_TEXTURE_CACHE.get(this); RoomTextureUtils.clearCache();
if(existingTextureCache)
{
for(const texture of existingTextureCache.getValues())
{
texture.destroy(true);
}
existingTextureCache.dispose();
RoomVisualization.RENDER_TEXTURE_CACHE.delete(this);
}
} }
protected reset(): void protected reset(): void
@ -202,14 +162,6 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
{ {
if(!this.object || !geometry) return; if(!this.object || !geometry) return;
RoomVisualization.LAST_VISUALIZATION = this;
let removeCount = 0;
const existing = RoomVisualization.RENDER_TEXTURE_CACHE.get(RoomVisualization.LAST_VISUALIZATION);
if(existing) removeCount = existing.length;
const geometryUpdate = this.updateGeometry(geometry); const geometryUpdate = this.updateGeometry(geometry);
const objectModel = this.object.model; const objectModel = this.object.model;
@ -219,28 +171,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
if(this.updateHole(objectModel)) needsUpdate = true; if(this.updateHole(objectModel)) needsUpdate = true;
if(this.initializeRoomPlanes()) this.initializeRoomPlanes();
{
if(existing && removeCount)
{
setTimeout(() =>
{
while(removeCount)
{
const texture = existing.getWithIndex(0);
if(texture)
{
texture.destroy(true);
existing.remove(existing.getKey(0));
}
removeCount--;
}
}, 0);
}
}
needsUpdate = this.updateMasks(objectModel); needsUpdate = this.updateMasks(objectModel);
@ -436,9 +367,9 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
this.reset(); this.reset();
} }
protected initializeRoomPlanes(): boolean protected initializeRoomPlanes(): void
{ {
if(!this.object || this._isPlaneSet) return false; if(!this.object || this._isPlaneSet) return;
if(!isNaN(this._floorThickness)) this._roomPlaneParser.floorThicknessMultiplier = this._floorThickness; if(!isNaN(this._floorThickness)) this._roomPlaneParser.floorThicknessMultiplier = this._floorThickness;
if(!isNaN(this._wallThickness)) this._roomPlaneParser.wallThicknessMultiplier = this._wallThickness; if(!isNaN(this._wallThickness)) this._roomPlaneParser.wallThicknessMultiplier = this._wallThickness;
@ -447,8 +378,8 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
if(!this._roomPlaneParser.initializeFromMapData(mapData)) return; if(!this._roomPlaneParser.initializeFromMapData(mapData)) return;
const _local_3 = this.getLandscapeWidth(); const maxX = this.getLandscapeWidth();
const _local_4 = this.getLandscapeHeight(); const maxY = this.getLandscapeHeight();
let _local_5 = 0; let _local_5 = 0;
let randomSeed = this.object.model.getValue<number>(RoomObjectVariable.ROOM_RANDOM_SEED); let randomSeed = this.object.model.getValue<number>(RoomObjectVariable.ROOM_RANDOM_SEED);
@ -468,7 +399,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
{ {
const _local_14 = Vector3d.crossProduct(leftSide, rightSide); const _local_14 = Vector3d.crossProduct(leftSide, rightSide);
randomSeed = ((randomSeed * 7613) + 517); randomSeed = ToInt32(Math.trunc((randomSeed * 7613) + 517) >>> 0);
plane = null; plane = null;
if(planeType === RoomPlaneData.PLANE_FLOOR) if(planeType === RoomPlaneData.PLANE_FLOOR)
@ -529,7 +460,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
else if(planeType === RoomPlaneData.PLANE_LANDSCAPE) else if(planeType === RoomPlaneData.PLANE_LANDSCAPE)
{ {
plane = new RoomPlane(this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_LANDSCAPE, true, secondaryNormals, randomSeed, _local_5, 0, _local_3, _local_4); plane = new RoomPlane(this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_LANDSCAPE, true, secondaryNormals, randomSeed, _local_5, 0, maxX, maxY);
if(_local_14.y > 0) if(_local_14.y > 0)
{ {
@ -619,8 +550,6 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
this._isPlaneSet = true; this._isPlaneSet = true;
this.defineSprites(); this.defineSprites();
return true;
} }
protected defineSprites(): void protected defineSprites(): void
@ -768,90 +697,93 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
this._visiblePlaneSpriteNumbers = []; this._visiblePlaneSpriteNumbers = [];
} }
protected updatePlanes(k: IRoomGeometry, _arg_2: boolean, _arg_3: number): boolean protected updatePlanes(geometry: IRoomGeometry, geometryUpdate: boolean, timeSinceStartMs: number): boolean
{ {
if(!k || !this.object) return; if(!geometry || !this.object) return;
this._assetUpdateCounter++; this._assetUpdateCounter++;
if(_arg_2) if(geometryUpdate)
{ {
this._visiblePlanes = []; this._visiblePlanes = [];
this._visiblePlaneSpriteNumbers = []; this._visiblePlaneSpriteNumbers = [];
} }
const _local_8 = (this._visiblePlanes.length > 0); const hasVisiblePlanes = (this._visiblePlanes.length > 0);
let _local_6 = this._visiblePlanes; let visiblePlanes = this._visiblePlanes;
if(!this._visiblePlanes.length) _local_6 = this._planes; if(!this._visiblePlanes.length) visiblePlanes = this._planes;
let depth = 0; let depth = 0;
let updated = false; let updated = false;
let index = 0; let index = 0;
while(index < _local_6.length) while(index < visiblePlanes.length)
{ {
let _local_10 = index; let id = index;
if(_local_8) _local_10 = this._visiblePlaneSpriteNumbers[index]; if(hasVisiblePlanes) id = this._visiblePlaneSpriteNumbers[index];
const _local_11 = this.getSprite(_local_10); const sprite = this.getSprite(id);
if(_local_11) if(sprite)
{ {
const _local_12 = _local_6[index]; const plane = visiblePlanes[index];
if(_local_12) if(plane)
{ {
_local_11.id = _local_12.uniqueId; sprite.id = plane.uniqueId;
if(_local_12.update(k, _arg_3)) if(plane.update(geometry, timeSinceStartMs))
{ {
if(_local_12.visible) if(plane.visible)
{ {
depth = ((_local_12.relativeDepth + this.floorRelativeDepth) + (_local_10 / 1000)); depth = ((plane.relativeDepth + this.floorRelativeDepth) + (id / 1000));
if(_local_12.type !== RoomPlane.TYPE_FLOOR) if(plane.type !== RoomPlane.TYPE_FLOOR)
{ {
depth = ((_local_12.relativeDepth + this.wallRelativeDepth) + (_local_10 / 1000)); depth = ((plane.relativeDepth + this.wallRelativeDepth) + (id / 1000));
if((_local_12.leftSide.length < 1) || (_local_12.rightSide.length < 1)) if((plane.leftSide.length < 1) || (plane.rightSide.length < 1))
{ {
depth = (depth + (RoomVisualization.ROOM_DEPTH_OFFSET * 0.5)); depth = (depth + (RoomVisualization.ROOM_DEPTH_OFFSET * 0.5));
} }
} }
const _local_14 = ((('plane ' + _local_10) + ' ') + k.scale); this.updateSprite(sprite, geometry, plane, `plane ${ id } ${ geometry.scale }`, depth);
this.updateSprite(_local_11, _local_12, _local_14, depth);
} }
updated = true; updated = true;
} }
if(_local_11.visible != ((_local_12.visible) && (this._typeVisibility[_local_12.type])))
if(sprite.visible != ((plane.visible) && (this._typeVisibility[plane.type])))
{ {
_local_11.visible = (!(_local_11.visible)); sprite.visible = (!(sprite.visible));
updated = true; updated = true;
} }
if(_local_11.visible)
if(sprite.visible)
{ {
if(!_local_8) if(!hasVisiblePlanes)
{ {
this._visiblePlanes.push(_local_12); this._visiblePlanes.push(plane);
this._visiblePlaneSpriteNumbers.push(index); this._visiblePlaneSpriteNumbers.push(index);
} }
} }
} }
else else
{ {
_local_11.id = 0; sprite.id = 0;
if(_local_11.visible)
if(sprite.visible)
{ {
_local_11.visible = false; sprite.visible = false;
updated = true; updated = true;
} }
} }
} }
index++; index++;
} }
@ -909,12 +841,12 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
{ {
if(plane.leftSide && plane.rightSide) if(plane.leftSide && plane.rightSide)
{ {
const _local_16 = Vector3d.scalarProjection(_local_14, plane.leftSide); const leftSideLoc = Vector3d.scalarProjection(_local_14, plane.leftSide);
const _local_17 = Vector3d.scalarProjection(_local_14, plane.rightSide); const rightSideLoc = Vector3d.scalarProjection(_local_14, plane.rightSide);
if((plane.type === RoomPlane.TYPE_WALL) || ((plane.type === RoomPlane.TYPE_LANDSCAPE) && (maskCategory === RoomPlaneBitmapMaskData.HOLE))) if((plane.type === RoomPlane.TYPE_WALL) || ((plane.type === RoomPlane.TYPE_LANDSCAPE) && (maskCategory === RoomPlaneBitmapMaskData.HOLE)))
{ {
plane.addBitmapMask(maskType, _local_16, _local_17); plane.addBitmapMask(maskType, leftSideLoc, rightSideLoc);
} }
else else
{ {
@ -961,21 +893,16 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
} }
} }
private updateSprite(k: IRoomObjectSprite, _arg_2: RoomPlane, _arg_3: string, _arg_4: number): void private updateSprite(sprite: IRoomObjectSprite, geometry: IRoomGeometry, plane: RoomPlane, _arg_3: string, relativeDepth: number): void
{ {
const offset = _arg_2.offset; const offset = plane.offset;
k.offsetX = -(offset.x); sprite.offsetX = -(offset.x);
k.offsetY = -(offset.y); sprite.offsetY = -(offset.y);
k.relativeDepth = _arg_4; sprite.relativeDepth = relativeDepth;
k.color = _arg_2.color; sprite.color = plane.color;
k.texture = this.getPlaneBitmap(_arg_2, _arg_3); sprite.texture = plane.bitmapData;
k.name = ((_arg_3 + '_') + this._assetUpdateCounter); sprite.name = ((_arg_3 + '_') + this._assetUpdateCounter);
}
private getPlaneBitmap(k: RoomPlane, _arg_2: string): Texture<Resource>
{
return k.bitmapData;
} }
public getBoundingRectangle(): Rectangle public getBoundingRectangle(): Rectangle

View File

@ -24,23 +24,21 @@ export class RoomVisualizationData extends Disposable implements IObjectVisualiz
public initialize(asset: IAssetData): boolean public initialize(asset: IAssetData): boolean
{ {
//@ts-ignore if(!asset.roomVisualization) return false;
const wallData = asset.wallData;
const wallData = asset.roomVisualization.wallData;
if(wallData) this._wallRasterizer.initialize(wallData); if(wallData) this._wallRasterizer.initialize(wallData);
//@ts-ignore const floorData = asset.roomVisualization.floorData;
const floorData = asset.floorData;
if(floorData) this._floorRasterizer.initialize(floorData); if(floorData) this._floorRasterizer.initialize(floorData);
//@ts-ignore const landscapeData = asset.roomVisualization.landscapeData;
const landscapeData = asset.landscapeData;
if(landscapeData) this._landscapeRasterizer.initialize(landscapeData); if(landscapeData) this._landscapeRasterizer.initialize(landscapeData);
//@ts-ignore const maskData = asset.roomVisualization.maskData;
const maskData = asset.maskData;
if(maskData) this._maskManager.initialize(maskData); if(maskData) this._maskManager.initialize(maskData);

View File

@ -55,7 +55,7 @@ export class PlaneMask
private getSizeIndex(k: number): number private getSizeIndex(k: number): number
{ {
let sizeIndex = 0; let sizeIndex = 0;
const index = 1; let index = 1;
while(index < this._sizes.length) while(index < this._sizes.length)
{ {
@ -67,6 +67,8 @@ export class PlaneMask
} }
sizeIndex = index; sizeIndex = index;
index++;
} }
return sizeIndex; return sizeIndex;

View File

@ -1,6 +1,8 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
import { Matrix, Point } from '@pixi/math'; import { Matrix, Point } from '@pixi/math';
import { IGraphicAssetCollection, IVector3D } from '../../../../../../api'; import { Sprite } from '@pixi/sprite';
import { IAssetPlaneMaskData, IAssetPlaneTextureBitmap, IGraphicAssetCollection, IVector3D } from '../../../../../../api';
import { PixiApplicationProxy } from '../../../../../../pixi-proxy';
import { PlaneMask } from './PlaneMask'; import { PlaneMask } from './PlaneMask';
import { PlaneMaskVisualization } from './PlaneMaskVisualization'; import { PlaneMaskVisualization } from './PlaneMaskVisualization';
@ -8,7 +10,7 @@ export class PlaneMaskManager
{ {
private _assetCollection: IGraphicAssetCollection; private _assetCollection: IGraphicAssetCollection;
private _masks: Map<string, PlaneMask>; private _masks: Map<string, PlaneMask>;
private _data: any; private _data: IAssetPlaneMaskData;
constructor() constructor()
{ {
@ -17,7 +19,7 @@ export class PlaneMaskManager
this._data = null; this._data = null;
} }
public get data(): any public get data(): IAssetPlaneMaskData
{ {
return this._data; return this._data;
} }
@ -40,7 +42,7 @@ export class PlaneMaskManager
} }
} }
public initialize(k: any): void public initialize(k: IAssetPlaneMaskData): void
{ {
this._data = k; this._data = k;
} }
@ -54,17 +56,17 @@ export class PlaneMaskManager
this.parseMasks(this.data, k); this.parseMasks(this.data, k);
} }
private parseMasks(k: any, _arg_2: IGraphicAssetCollection): void private parseMasks(maskData: IAssetPlaneMaskData, _arg_2: IGraphicAssetCollection): void
{ {
if(!k || !_arg_2) return; if(!maskData || !_arg_2) return;
if(k.masks && k.masks.length) if(maskData.masks && maskData.masks.length)
{ {
let index = 0; let index = 0;
while(index < k.masks.length) while(index < maskData.masks.length)
{ {
const mask = k.masks[index]; const mask = maskData.masks[index];
if(mask) if(mask)
{ {
@ -85,7 +87,7 @@ export class PlaneMaskManager
if(visualization) if(visualization)
{ {
const size = visualization.size as number; const size = visualization.size;
const maskVisualization = newMask.createMaskVisualization(size); const maskVisualization = newMask.createMaskVisualization(size);
if(maskVisualization) if(maskVisualization)
@ -108,18 +110,18 @@ export class PlaneMaskManager
} }
} }
private parseMaskBitmaps(k: any, _arg_2: PlaneMaskVisualization, _arg_3: IGraphicAssetCollection): string private parseMaskBitmaps(bitmaps: IAssetPlaneTextureBitmap[], maskVisualization: PlaneMaskVisualization, assetCollection: IGraphicAssetCollection): string
{ {
if(!k || !k.length) return null; if(!bitmaps || !bitmaps.length) return null;
let graphicName: string = null; let graphicName: string = null;
for(const bitmap of k) for(const bitmap of bitmaps)
{ {
if(!bitmap) continue; if(!bitmap) continue;
const assetName = bitmap.assetName; const assetName = bitmap.assetName;
const asset = _arg_3.getAsset(assetName); const asset = assetCollection.getAsset(assetName);
if(!asset) continue; if(!asset) continue;
@ -135,19 +137,19 @@ export class PlaneMaskManager
if(!asset.flipH) graphicName = assetName; if(!asset.flipH) graphicName = assetName;
_arg_2.addBitmap(asset, normalMinX, normalMaxX, normalMinY, normalMaxY); maskVisualization.addBitmap(asset, normalMinX, normalMaxX, normalMinY, normalMaxY);
} }
return graphicName; return graphicName;
} }
public updateMask(k: Graphics, _arg_2: string, _arg_3: number, _arg_4: IVector3D, _arg_5: number, _arg_6: number): boolean public updateMask(canvas: RenderTexture, type: string, scale: number, normal: IVector3D, posX: number, posY: number): boolean
{ {
const mask = this._masks.get(_arg_2); const mask = this._masks.get(type);
if(!mask) return true; if(!mask) return true;
const asset = mask.getGraphicAsset(_arg_3, _arg_4); const asset = mask.getGraphicAsset(scale, normal);
if(!asset) return true; if(!asset) return true;
@ -155,34 +157,41 @@ export class PlaneMaskManager
if(!texture) return true; if(!texture) return true;
const point = new Point((_arg_5 + asset.offsetX), (_arg_6 + asset.offsetY)); const point = new Point((posX + asset.offsetX), (posY + asset.offsetY));
const matrix = new Matrix(); const matrix = new Matrix();
let a = 1; let xScale = 1;
let b = 1; let ySkew = 1;
let c = 0; let xSkew = 0;
let d = 0; let yScale = 0;
let tx = (point.x + xSkew);
let ty = (point.y + yScale);
if(asset.flipH) if(asset.flipH)
{ {
a = -1; xScale = -1;
c = -(texture.width); xSkew = texture.width;
tx = ((point.x + xSkew) - texture.width);
} }
if(asset.flipV) if(asset.flipV)
{ {
b = -1; ySkew = -1;
d = -(texture.height); yScale = texture.height;
ty = ((point.y + yScale) - texture.height);
} }
matrix.scale(a, b); matrix.scale(xScale, ySkew);
matrix.translate((point.x + c), (point.y + d)); matrix.translate(tx, ty);
k PixiApplicationProxy.instance.renderer.render(new Sprite(texture), {
.beginTextureFill({ texture, matrix }) renderTexture: canvas,
.drawRect(matrix.tx, matrix.ty, texture.width, texture.height) clear: false,
.endFill(); transform: matrix
});
return true; return true;
} }

View File

@ -1,4 +1,4 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
import { IVector3D } from '../../../../../../api'; import { IVector3D } from '../../../../../../api';
import { PlaneBitmapData } from '../utils'; import { PlaneBitmapData } from '../utils';
import { PlaneVisualizationLayer } from './basic'; import { PlaneVisualizationLayer } from './basic';
@ -6,7 +6,7 @@ import { PlaneVisualizationLayer } from './basic';
export interface IPlaneRasterizer export interface IPlaneRasterizer
{ {
initializeDimensions(_arg_1: number, _arg_2: number): boolean; initializeDimensions(_arg_1: number, _arg_2: number): boolean;
render(_arg_1: Graphics, _arg_2: string, _arg_3: number, _arg_4: number, _arg_5: number, _arg_6: IVector3D, _arg_7: boolean, _arg_8?: number, _arg_9?: number, _arg_10?: number, _arg_11?: number, _arg_12?: number): PlaneBitmapData; render(planeId: string, canvas: RenderTexture, id: string, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX?: number, offsetY?: number, maxX?: number, maxY?: number, timeSinceStartMs?: number): PlaneBitmapData;
getTextureIdentifier(_arg_1: number, _arg_2: IVector3D): string; getTextureIdentifier(_arg_1: number, _arg_2: IVector3D): string;
getLayers(_arg_1: string): PlaneVisualizationLayer[]; getLayers(_arg_1: string): PlaneVisualizationLayer[];
reinitialize(): void; reinitialize(): void;

View File

@ -7,15 +7,15 @@ export class AnimationItem
private _y: number; private _y: number;
private _speedX: number; private _speedX: number;
private _speedY: number; private _speedY: number;
private _bitmapData: IGraphicAsset; private _asset: IGraphicAsset;
constructor(k: number, _arg_2: number, _arg_3: number, _arg_4: number, _arg_5: IGraphicAsset) constructor(x: number, y: number, speedX: number, speedY: number, asset: IGraphicAsset)
{ {
this._x = k; this._x = x;
this._y = _arg_2; this._y = y;
this._speedX = _arg_3; this._speedX = speedX;
this._speedY = _arg_4; this._speedY = speedY;
this._bitmapData = _arg_5; this._asset = asset;
if(isNaN(this._x)) this._x = 0; if(isNaN(this._x)) this._x = 0;
@ -28,25 +28,25 @@ export class AnimationItem
public get bitmapData(): IGraphicAsset public get bitmapData(): IGraphicAsset
{ {
return this._bitmapData; return this._asset;
} }
public dispose(): void public dispose(): void
{ {
this._bitmapData = null; this._asset = null;
} }
public getPosition(k: number, _arg_2: number, _arg_3: number, _arg_4: number, _arg_5: number): Point public getPosition(maxX: number, maxY: number, dimensionX: number, dimensionY: number, timeSinceStartMs: number): Point
{ {
let _local_6 = this._x; let x = this._x;
let _local_7 = this._y; let y = this._y;
if(_arg_3 > 0) _local_6 = (_local_6 + (((this._speedX / _arg_3) * _arg_5) / 1000)); if(dimensionX > 0) x = (x + (((this._speedX / dimensionX) * timeSinceStartMs) / 1000));
if(_arg_4 > 0) _local_7 = (_local_7 + (((this._speedY / _arg_4) * _arg_5) / 1000)); if(dimensionY > 0) y = (y + (((this._speedY / dimensionY) * timeSinceStartMs) / 1000));
const _local_8 = ((_local_6 % 1) * k); const _local_8 = Math.trunc((x % 1) * maxX);
const _local_9 = ((_local_7 % 1) * _arg_2); const _local_9 = Math.trunc((y % 1) * maxY);
return new Point(_local_8, _local_9); return new Point(_local_8, _local_9);
} }

View File

@ -1,4 +1,4 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
import { IVector3D, Vector3d } from '../../../../../../../api'; import { IVector3D, Vector3d } from '../../../../../../../api';
import { Plane } from '../basic'; import { Plane } from '../basic';
@ -11,31 +11,31 @@ export class LandscapePlane extends Plane
private _width: number = 0; private _width: number = 0;
private _height: number = 0; private _height: number = 0;
public isStatic(k: number): boolean public isStatic(scale: number): boolean
{ {
const _local_2 = this.getPlaneVisualization(k); const visualization = this.getPlaneVisualization(scale);
if(_local_2) return !(_local_2.hasAnimationLayers); if(visualization) return !visualization.hasAnimationLayers;
return super.isStatic(k); return super.isStatic(scale);
} }
public initializeDimensions(k: number, _arg_2: number): void public initializeDimensions(width: number, height: number): void
{ {
if(k < 0) k = 0; if(width < 0) width = 0;
if(_arg_2 < 0) _arg_2 = 0; if(height < 0) height = 0;
if((k !== this._width) || (_arg_2 !== this._height)) if((width !== this._width) || (height !== this._height))
{ {
this._width = k; this._width = width;
this._height = _arg_2; this._height = height;
} }
} }
public render(k: Graphics, _arg_2: number, _arg_3: number, _arg_4: number, _arg_5: IVector3D, _arg_6: boolean, _arg_7: number, _arg_8: number, _arg_9: number, _arg_10: number, _arg_11: number): Graphics public render(planeId: string, canvas: RenderTexture, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, maxX: number, maxY: number, timeSinceStartMs: number): RenderTexture
{ {
const visualization = this.getPlaneVisualization(_arg_4); const visualization = this.getPlaneVisualization(scale);
if(!visualization || !visualization.geometry) return null; if(!visualization || !visualization.geometry) return null;
@ -45,15 +45,15 @@ export class LandscapePlane extends Plane
if(_local_13 && _local_14 && _local_15) if(_local_13 && _local_14 && _local_15)
{ {
_arg_2 = Math.round(Math.abs((((_local_13.x - _local_15.x) * _arg_2) / visualization.geometry.scale))); width = Math.round(Math.abs((((_local_13.x - _local_15.x) * width) / visualization.geometry.scale)));
_arg_3 = Math.round(Math.abs((((_local_13.y - _local_14.y) * _arg_3) / visualization.geometry.scale))); height = Math.round(Math.abs((((_local_13.y - _local_14.y) * height) / visualization.geometry.scale)));
const _local_16 = (_arg_7 * Math.abs((_local_13.x - _local_15.x))); const renderOffsetX = Math.trunc(offsetX * Math.abs((_local_13.x - _local_15.x)));
const _local_17 = (_arg_8 * Math.abs((_local_13.y - _local_14.y))); const renderOffsetY = Math.trunc(offsetY * Math.abs((_local_13.y - _local_14.y)));
const _local_18 = (_arg_9 * Math.abs((_local_13.x - _local_15.x))); const renderMaxX = Math.trunc(maxX * Math.abs((_local_13.x - _local_15.x)));
const _local_19 = (_arg_10 * Math.abs((_local_13.y - _local_14.y))); const renderMaxY = Math.trunc(maxY * Math.abs((_local_13.y - _local_14.y)));
return visualization.render(k, _arg_2, _arg_3, _arg_5, _arg_6, _local_16, _local_17, _local_18, _local_19, _arg_9, _arg_10, _arg_11); return visualization.render(planeId, canvas, width, height, normal, useTexture, renderOffsetX, renderOffsetY, renderMaxX, renderMaxY, maxX, maxY, timeSinceStartMs);
} }
return null; return null;

View File

@ -1,15 +1,20 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
import { IVector3D, NitroConfiguration } from '../../../../../../../api'; import { IAssetPlane, IAssetPlaneVisualizationAnimatedLayer, IAssetPlaneVisualizationLayer, IVector3D, Vector3d } from '../../../../../../../api';
import { RoomTextureUtils, TextureUtils } from '../../../../../../../pixi-proxy';
import { PlaneBitmapData, Randomizer } from '../../utils'; import { PlaneBitmapData, Randomizer } from '../../utils';
import { PlaneMaterial, PlaneRasterizer, PlaneVisualizationLayer } from '../basic'; import { PlaneMaterial, PlaneRasterizer, PlaneVisualizationLayer } from '../basic';
import { LandscapePlane } from './LandscapePlane'; import { LandscapePlane } from './LandscapePlane';
export class LandscapeRasterizer extends PlaneRasterizer export class LandscapeRasterizer extends PlaneRasterizer
{ {
public static LANDSCAPES_ENABLED: boolean = true;
public static LANDSCAPE_DEFAULT_COLOR: number = 8828617;
private static UPDATE_INTERVAL: number = 500; private static UPDATE_INTERVAL: number = 500;
private _landscapeWidth: number = 0; private _landscapeWidth: number = 0;
private _landscapeHeight: number = 0; private _landscapeHeight: number = 0;
private _cachedBitmap: RenderTexture = null;
public initializeDimensions(k: number, _arg_2: number): boolean public initializeDimensions(k: number, _arg_2: number): boolean
{ {
@ -27,12 +32,12 @@ export class LandscapeRasterizer extends PlaneRasterizer
{ {
if(!this.data) return; if(!this.data) return;
const landscapes = this.data.landscapes; const landscapes = this.data.planes;
if(landscapes && landscapes.length) this.parseLandscapes(landscapes); if(landscapes && landscapes.length) this.parseLandscapes(landscapes);
} }
private parseLandscapes(k: any): void private parseLandscapes(k: IAssetPlane[]): void
{ {
if(!k) return; if(!k) return;
@ -45,7 +50,7 @@ export class LandscapeRasterizer extends PlaneRasterizer
if(!landscape) continue; if(!landscape) continue;
const id = landscape.id; const id = landscape.id;
const visualizations = landscape.animatedVisualizations; const visualizations = landscape.animatedVisualization;
const plane = new LandscapePlane(); const plane = new LandscapePlane();
@ -58,14 +63,10 @@ export class LandscapeRasterizer extends PlaneRasterizer
let horizontalAngle = LandscapePlane.HORIZONTAL_ANGLE_DEFAULT; let horizontalAngle = LandscapePlane.HORIZONTAL_ANGLE_DEFAULT;
let verticalAngle = LandscapePlane.VERTICAL_ANGLE_DEFAULT; let verticalAngle = LandscapePlane.VERTICAL_ANGLE_DEFAULT;
if(visualization.horizontalAngle) horizontalAngle = visualization.horizontalAngle; if(visualization.horizontalAngle !== undefined) horizontalAngle = visualization.horizontalAngle;
if(visualization.verticalAngle) verticalAngle = visualization.verticalAngle; if(visualization.verticalAngle !== undefined) verticalAngle = visualization.verticalAngle;
const basicLayers = visualization.layers; const totalLayers = (visualization.allLayers.length ?? 0);
const animatedLayers = visualization.animationLayers;
const totalBasicLayers = ((basicLayers && basicLayers.length) || 0);
const totalAnimatedLayers = ((animatedLayers && animatedLayers.length) || 0);
const totalLayers = (totalBasicLayers + totalAnimatedLayers);
const planeVisualization = plane.createPlaneVisualization(size, (totalLayers || 0), this.getGeometry(size, horizontalAngle, verticalAngle)); const planeVisualization = plane.createPlaneVisualization(size, (totalLayers || 0), this.getGeometry(size, horizontalAngle, verticalAngle));
@ -75,55 +76,45 @@ export class LandscapeRasterizer extends PlaneRasterizer
let layerId = 0; let layerId = 0;
if(totalBasicLayers) while(layerId < totalLayers)
{ {
while(layerId < basicLayers.length) const layer = visualization.allLayers[layerId];
{
const layer = basicLayers[layerId];
if(layer) if(layer)
{
if((layer as IAssetPlaneVisualizationAnimatedLayer).items === undefined)
{ {
const basicLayer = (layer as IAssetPlaneVisualizationLayer);
let material: PlaneMaterial = null; let material: PlaneMaterial = null;
let align: number = PlaneVisualizationLayer.ALIGN_DEFAULT; let align: number = PlaneVisualizationLayer.ALIGN_DEFAULT;
let color: number = LandscapePlane.DEFAULT_COLOR; let color: number = LandscapePlane.DEFAULT_COLOR;
let offset: number = PlaneVisualizationLayer.DEFAULT_OFFSET; let offset: number = PlaneVisualizationLayer.DEFAULT_OFFSET;
if(layer.materialId) material = this.getMaterial(layer.materialId); if(basicLayer.materialId) material = this.getMaterial(basicLayer.materialId);
if(layer.color) color = layer.color; if(basicLayer.color) color = basicLayer.color;
if(layer.offset) offset = layer.offset; if(basicLayer.offset) offset = basicLayer.offset;
if(layer.align) if(basicLayer.align)
{ {
if(layer.align === 'bottom') if(basicLayer.align === 'bottom')
{ {
align = PlaneVisualizationLayer.ALIGN_BOTTOM; align = PlaneVisualizationLayer.ALIGN_BOTTOM;
} }
else if(layer.align === 'top') align = PlaneVisualizationLayer.ALIGN_TOP; else if(basicLayer.align === 'top') align = PlaneVisualizationLayer.ALIGN_TOP;
} }
planeVisualization.setLayer(layerId, material, color, align, offset); planeVisualization.setLayer(layerId, material, color, align, offset);
} }
else
layerId++;
}
}
layerId = 0;
if(totalAnimatedLayers)
{
const animationItems: {}[] = [];
while(layerId < animatedLayers.length)
{
const layer = animatedLayers[layerId];
if(layer)
{ {
const items = layer.animationItems; const animatedLayer = (layer as IAssetPlaneVisualizationAnimatedLayer);
const items = animatedLayer.items;
const animationItems: {}[] = [];
if(items && items.length) if(items && items.length)
{ {
@ -135,8 +126,8 @@ export class LandscapeRasterizer extends PlaneRasterizer
const assetId = item.assetId; const assetId = item.assetId;
const x = this.getCoordinateValue(item.x || '', item.randomX || ''); const x = this.getCoordinateValue(item.x || '', item.randomX || '');
const y = this.getCoordinateValue(item.y || '', item.randomY || ''); const y = this.getCoordinateValue(item.y || '', item.randomY || '');
const speedX = item.speedX ? item.speedX / NitroConfiguration.getValue<number>('system.animation.fps', 24) : 0; const speedX = item.speedX;
const speedY = item.speedY ? item.speedY / NitroConfiguration.getValue<number>('system.animation.fps', 24) : 0; const speedY = item.speedY;
animationItems.push({ animationItems.push({
asset: assetId, asset: assetId,
@ -148,12 +139,12 @@ export class LandscapeRasterizer extends PlaneRasterizer
} }
} }
} }
planeVisualization.setAnimationLayer(layerId, animationItems, this.assetCollection);
} }
layerId++; layerId++;
} }
planeVisualization.setAnimationLayer(layerId, animationItems, this.assetCollection);
} }
} }
} }
@ -162,38 +153,38 @@ export class LandscapeRasterizer extends PlaneRasterizer
} }
} }
private getCoordinateValue(k: string, _arg_2: string): number private getCoordinateValue(x: string, randomX: string): number
{ {
let _local_3 = 0; let _local_3 = 0;
if((k.length > 0)) if((x.length > 0))
{ {
if(k.charAt((k.length - 1)) === '%') if(x.charAt((x.length - 1)) === '%')
{ {
k = k.substr(0, (k.length - 1)); x = x.substr(0, (x.length - 1));
_local_3 = (parseFloat(k) / 100); _local_3 = (parseFloat(x) / 100);
} }
} }
if((_arg_2.length > 0)) if((randomX.length > 0))
{ {
const _local_4 = 10000; const _local_4 = 10000;
const _local_5 = Randomizer.getValues(1, 0, _local_4); const _local_5 = Randomizer.getValues(1, 0, _local_4);
const _local_6 = (_local_5[0] / _local_4); const _local_6 = (_local_5[0] / _local_4);
if(_arg_2.charAt((_arg_2.length - 1)) === '%') if(randomX.charAt((randomX.length - 1)) === '%')
{ {
_arg_2 = _arg_2.substr(0, (_arg_2.length - 1)); randomX = randomX.substr(0, (randomX.length - 1));
_local_3 = (_local_3 + ((_local_6 * parseFloat(_arg_2)) / 100)); _local_3 = (_local_3 + ((_local_6 * parseFloat(randomX)) / 100));
} }
} }
return _local_3; return _local_3;
} }
public render(canvas: Graphics, id: string, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number = 0, offsetY: number = 0, maxX: number = 0, maxY: number = 0, timeSinceStartMs: number = 0): PlaneBitmapData public render(planeId: string, canvas: RenderTexture, id: string, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number = 0, offsetY: number = 0, maxX: number = 0, maxY: number = 0, timeSinceStartMs: number = 0): PlaneBitmapData
{ {
let plane = this.getPlane(id) as LandscapePlane; let plane = this.getPlane(id) as LandscapePlane;
@ -201,16 +192,46 @@ export class LandscapeRasterizer extends PlaneRasterizer
if(!plane) return null; if(!plane) return null;
if(canvas) if(canvas) TextureUtils.clearRenderTexture(canvas);
if(!LandscapeRasterizer.LANDSCAPES_ENABLED)
{ {
canvas.clear(); const visualization = plane.getPlaneVisualization(scale);
if(!visualization || !visualization.geometry) return null;
const _local_13 = visualization.geometry.getScreenPoint(new Vector3d(0, 0, 0));
const _local_14 = visualization.geometry.getScreenPoint(new Vector3d(0, 0, 1));
const _local_15 = visualization.geometry.getScreenPoint(new Vector3d(0, 1, 0));
if(_local_13 && _local_14 && _local_15)
{
width = Math.round(Math.abs((((_local_13.x - _local_15.x) * width) / visualization.geometry.scale)));
height = Math.round(Math.abs((((_local_13.y - _local_14.y) * height) / visualization.geometry.scale)));
}
if(!this._cachedBitmap || (this._cachedBitmap.width !== width ) || (this._cachedBitmap.height !== height))
{
if(this._cachedBitmap)
{
this._cachedBitmap.destroy(true);
this._cachedBitmap = null;
}
this._cachedBitmap = RoomTextureUtils.createAndFillRenderTexture(width, height, LandscapeRasterizer.LANDSCAPE_DEFAULT_COLOR);
}
return new PlaneBitmapData(this._cachedBitmap, -1);
} }
let graphic = plane.render(canvas, width, height, scale, normal, useTexture, offsetX, offsetY, maxX, maxY, timeSinceStartMs); if(canvas) TextureUtils.clearRenderTexture(canvas);
let graphic = plane.render(planeId, canvas, width, height, scale, normal, useTexture, offsetX, offsetY, maxX, maxY, timeSinceStartMs);
if(graphic && (graphic !== canvas)) if(graphic && (graphic !== canvas))
{ {
graphic = graphic.clone(); graphic = new RenderTexture(graphic.baseTexture);
if(!graphic) return null; if(!graphic) return null;
} }

View File

@ -1,23 +1,24 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
import { Matrix } from '@pixi/math'; import { Sprite } from '@pixi/sprite';
import { IDisposable, IGraphicAssetCollection, IVector3D } from '../../../../../../../api'; import { IDisposable, IGraphicAssetCollection, IVector3D } from '../../../../../../../api';
import { RoomTextureUtils, TextureUtils } from '../../../../../../../pixi-proxy';
import { AnimationItem } from './AnimationItem'; import { AnimationItem } from './AnimationItem';
export class PlaneVisualizationAnimationLayer implements IDisposable export class PlaneVisualizationAnimationLayer implements IDisposable
{ {
private _color: number = 0; private _color: number = 0;
private _bitmapData: Graphics = null; private _bitmapData: RenderTexture = null;
private _isDisposed: boolean = false; private _isDisposed: boolean = false;
private _items: AnimationItem[]; private _items: AnimationItem[];
constructor(k: any, _arg_2: IGraphicAssetCollection) constructor(k: any, assets: IGraphicAssetCollection)
{ {
this._color = 0; this._color = 0;
this._bitmapData = null; this._bitmapData = null;
this._isDisposed = false; this._isDisposed = false;
this._items = []; this._items = [];
if(k && _arg_2) if(k && assets)
{ {
for(const item of k) for(const item of k)
{ {
@ -27,7 +28,7 @@ export class PlaneVisualizationAnimationLayer implements IDisposable
if(assetName) if(assetName)
{ {
const asset = _arg_2.getAsset(assetName); const asset = assets.getAsset(assetName);
if(asset) this._items.push(new AnimationItem(item.x, item.y, item.speedX, item.speedY, asset)); if(asset) this._items.push(new AnimationItem(item.x, item.y, item.speedX, item.speedY, asset));
} }
@ -63,33 +64,25 @@ export class PlaneVisualizationAnimationLayer implements IDisposable
{ {
if(this._bitmapData) if(this._bitmapData)
{ {
this._bitmapData.destroy(); this._bitmapData.destroy(true);
this._bitmapData = null; this._bitmapData = null;
} }
} }
public render(canvas: Graphics, width: number, height: number, normal: IVector3D, offsetX: number, offsetY: number, maxX: number, maxY: number, dimensionX: number, dimensionY: number, timeSinceStartMs: number): Graphics public render(canvas: RenderTexture, width: number, height: number, normal: IVector3D, offsetX: number, offsetY: number, maxX: number, maxY: number, dimensionX: number, dimensionY: number, timeSinceStartMs: number): RenderTexture
{ {
if((((canvas == null) || (!(canvas.width == width))) || (!(canvas.height == height)))) if(!canvas || (canvas.width !== width) || (canvas.height !== height))
{ {
if((((this._bitmapData == null) || (!(this._bitmapData.width == width))) || (!(this._bitmapData.height == height)))) if(!this._bitmapData || (this._bitmapData.width !== width) || (this._bitmapData.height !== height))
{ {
if(this._bitmapData != null) if(this._bitmapData) this._bitmapData.destroy(true);
{
this._bitmapData.destroy();
}
this._bitmapData = new Graphics() this._bitmapData = RoomTextureUtils.createRenderTexture(width, height);
.drawRect(0, 0, width, height);
} }
else else
{ {
this._bitmapData TextureUtils.clearRenderTexture(this._bitmapData);
.beginFill(0xFFFFFF)
.drawRect(0, 0, this._bitmapData.width, this._bitmapData.height)
.endFill();
//this._bitmapData.fillRect(this._bitmapData.rect, 0xFFFFFF);
} }
canvas = this._bitmapData; canvas = this._bitmapData;
@ -97,51 +90,60 @@ export class PlaneVisualizationAnimationLayer implements IDisposable
if(((maxX > 0) && (maxY > 0))) if(((maxX > 0) && (maxY > 0)))
{ {
let _local_12 = 0; let index = 0;
while(_local_12 < this._items.length) while(index < this._items.length)
{ {
const _local_13 = (this._items[_local_12] as AnimationItem); const item = (this._items[index] as AnimationItem);
if(_local_13 != null)
if(item)
{ {
const _local_14 = _local_13.getPosition(maxX, maxY, dimensionX, dimensionY, timeSinceStartMs); const point = item.getPosition(maxX, maxY, dimensionX, dimensionY, timeSinceStartMs);
_local_14.x = (_local_14.x - offsetX); point.x = Math.trunc(point.x - offsetX);
_local_14.y = (_local_14.y - offsetY); point.y = Math.trunc(point.y - offsetY);
if(_local_13.bitmapData) if(item.bitmapData)
{ {
if(_local_14.x > 0 && (_local_14.x + _local_13.bitmapData.width < canvas.width)) if((point.x > -(item.bitmapData.width)) && (point.x < canvas.width) && (point.y > -(item.bitmapData.height)) && (point.y < canvas.height))
{ {
canvas const sprite = new Sprite(item.bitmapData.texture);
.beginFill(0x00FF00)
.beginTextureFill({ texture: _local_13.bitmapData.texture, matrix: new Matrix(1, 0, 0, 1, _local_14.x, _local_14.y) }) sprite.position.set(point.x, point.y);
.drawRect(_local_14.x, _local_14.y, _local_13.bitmapData.width, _local_13.bitmapData.height)
.endFill(); TextureUtils.writeToRenderTexture(sprite, canvas, false);
} }
else if(_local_14.x > 0)
if(((point.x - maxX) > -(item.bitmapData.width)) && ((point.x - maxX) < canvas.width) && (point.y > -(item.bitmapData.height)) && (point.y < canvas.height))
{ {
const difference = canvas.width - _local_14.x; const sprite = new Sprite(item.bitmapData.texture);
canvas
.beginFill(0x00FF00) sprite.position.set((point.x - maxX), point.y);
.beginTextureFill({ texture: _local_13.bitmapData.texture, matrix: new Matrix(1, 0, 0, 1, _local_14.x, _local_14.y) })
.drawRect(_local_14.x, _local_14.y, difference, _local_13.bitmapData.height) TextureUtils.writeToRenderTexture(sprite, canvas, false);
.endFill();
} }
else
if((point.x > -(item.bitmapData.width)) && (point.x < canvas.width) && ((point.y - maxY) > -(item.bitmapData.height)) && ((point.y - maxY) < canvas.height))
{ {
//if(_local_14.x > -_local_13.bitmapData.width) const sprite = new Sprite(item.bitmapData.texture);
const difference = _local_13.bitmapData.width + _local_14.x;
canvas sprite.position.set(point.x, (point.y - maxY));
.beginFill(0x00FF00)
.beginTextureFill({ texture: _local_13.bitmapData.texture, matrix: new Matrix(1, 0, 0, 1, _local_14.x, _local_14.y) }) TextureUtils.writeToRenderTexture(sprite, canvas, false);
.drawRect(0, _local_14.y, difference, _local_13.bitmapData.height) }
.endFill();
if(((point.x - maxX) > -(item.bitmapData.width)) && ((point.x - maxX) < canvas.width) && ((point.y - maxY) > -(item.bitmapData.height)) && ((point.y - maxY) < canvas.height))
{
const sprite = new Sprite(item.bitmapData.texture);
sprite.position.set((point.x - maxX), (point.y - maxY));
TextureUtils.writeToRenderTexture(sprite, canvas, false);
} }
} }
} }
_local_12++; index++;
} }
} }

View File

@ -1,4 +1,4 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
import { IVector3D, Vector3d } from '../../../../../../../api'; import { IVector3D, Vector3d } from '../../../../../../../api';
import { Plane } from './Plane'; import { Plane } from './Plane';
@ -8,7 +8,7 @@ export class FloorPlane extends Plane
public static HORIZONTAL_ANGLE_DEFAULT: number = 45; public static HORIZONTAL_ANGLE_DEFAULT: number = 45;
public static VERTICAL_ANGLE_DEFAULT: number = 30; public static VERTICAL_ANGLE_DEFAULT: number = 30;
public render(canvas: Graphics, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number): Graphics public render(planeId: string, canvas: RenderTexture, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number): RenderTexture
{ {
const visualization = this.getPlaneVisualization(scale); const visualization = this.getPlaneVisualization(scale);
@ -32,6 +32,6 @@ export class FloorPlane extends Plane
y = (offsetY * Math.trunc(Math.abs(_local_15))); y = (offsetY * Math.trunc(Math.abs(_local_15)));
} }
return visualization.render(canvas, width, height, normal, useTexture, x, y); return visualization.render(planeId, canvas, width, height, normal, useTexture, x, y);
} }
} }

View File

@ -1,5 +1,6 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
import { IVector3D } from '../../../../../../../api'; import { IAssetPlane, IVector3D } from '../../../../../../../api';
import { TextureUtils } from '../../../../../../../pixi-proxy';
import { PlaneBitmapData } from '../../utils'; import { PlaneBitmapData } from '../../utils';
import { FloorPlane } from './FloorPlane'; import { FloorPlane } from './FloorPlane';
import { PlaneRasterizer } from './PlaneRasterizer'; import { PlaneRasterizer } from './PlaneRasterizer';
@ -10,12 +11,12 @@ export class FloorRasterizer extends PlaneRasterizer
{ {
if(!this.data) return; if(!this.data) return;
const floors = this.data.floors; const floors = this.data.planes;
if(floors && floors.length) this.parseFloors(floors); if(floors && floors.length) this.parseFloors(floors);
} }
private parseFloors(k: any): void private parseFloors(k: IAssetPlane[]): void
{ {
if(!k) return; if(!k) return;
@ -35,7 +36,7 @@ export class FloorRasterizer extends PlaneRasterizer
} }
} }
public render(canvas: Graphics, id: string, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number = 0, offsetY: number = 0, maxX: number = 0, maxY: number = 0, timeSinceStartMs: number = 0): PlaneBitmapData public render(planeId: string, canvas: RenderTexture, id: string, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number = 0, offsetY: number = 0, maxX: number = 0, maxY: number = 0, timeSinceStartMs: number = 0): PlaneBitmapData
{ {
let plane = this.getPlane(id) as FloorPlane; let plane = this.getPlane(id) as FloorPlane;
@ -43,13 +44,13 @@ export class FloorRasterizer extends PlaneRasterizer
if(!plane) return null; if(!plane) return null;
if(canvas) canvas.clear(); if(canvas) TextureUtils.clearAndFillRenderTexture(canvas);
let graphic = plane.render(canvas, width, height, scale, normal, useTexture, offsetX, offsetY); let graphic = plane.render(planeId, canvas, width, height, scale, normal, useTexture, offsetX, offsetY);
if(graphic && (graphic !== canvas)) if(graphic && (graphic !== canvas))
{ {
graphic = graphic.clone(); graphic = new RenderTexture(graphic.baseTexture);
if(!graphic) return null; if(!graphic) return null;
} }

View File

@ -85,7 +85,7 @@ export class Plane
return sizeIndex; return sizeIndex;
} }
protected getPlaneVisualization(size: number): PlaneVisualization public getPlaneVisualization(size: number): PlaneVisualization
{ {
if(size === this._lastSize) return this._lastPlaneVisualization; if(size === this._lastSize) return this._lastPlaneVisualization;

View File

@ -1,4 +1,4 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
import { IVector3D } from '../../../../../../../api'; import { IVector3D } from '../../../../../../../api';
import { PlaneMaterialCellMatrix } from './PlaneMaterialCellMatrix'; import { PlaneMaterialCellMatrix } from './PlaneMaterialCellMatrix';
@ -76,7 +76,7 @@ export class PlaneMaterial
return null; return null;
} }
public render(canvas: Graphics, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): Graphics public render(canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): RenderTexture
{ {
if(width < 1) width = 1; if(width < 1) width = 1;

View File

@ -1,12 +1,13 @@
import { Matrix, Point } from '@pixi/math'; import { Matrix, Point } from '@pixi/math';
import { Sprite } from '@pixi/sprite';
import { TilingSprite } from '@pixi/sprite-tiling';
import { IGraphicAsset, IVector3D } from '../../../../../../../api'; import { IGraphicAsset, IVector3D } from '../../../../../../../api';
import { NitroSprite } from '../../../../../../../pixi-proxy';
import { Randomizer } from '../../utils'; import { Randomizer } from '../../utils';
import { PlaneTexture } from './PlaneTexture'; import { PlaneTexture } from './PlaneTexture';
export class PlaneMaterialCell export class PlaneMaterialCell
{ {
private _cachedSprite: NitroSprite; private _cachedSprite: Sprite;
private _texture: PlaneTexture; private _texture: PlaneTexture;
private _extraItemOffsets: Point[]; private _extraItemOffsets: Point[];
private _extraItemAssets: IGraphicAsset[]; private _extraItemAssets: IGraphicAsset[];
@ -56,7 +57,7 @@ export class PlaneMaterialCell
public get isStatic(): boolean public get isStatic(): boolean
{ {
return this._extraItemCount == 0; return this._extraItemCount === 0;
} }
public dispose(): void public dispose(): void
@ -102,7 +103,7 @@ export class PlaneMaterialCell
return 0; return 0;
} }
public render(normal: IVector3D, textureOffsetX: number, textureOffsetY: number): NitroSprite public render(normal: IVector3D, textureOffsetX: number, textureOffsetY: number): Sprite
{ {
if(!this._texture) return null; if(!this._texture) return null;
@ -110,7 +111,7 @@ export class PlaneMaterialCell
if(!texture) return null; if(!texture) return null;
const bitmap = new NitroSprite(texture); const bitmap = new TilingSprite(texture, texture.width, texture.height);
if((textureOffsetX !== 0) || (textureOffsetY !== 0)) if((textureOffsetX !== 0) || (textureOffsetY !== 0))
{ {
@ -118,8 +119,9 @@ export class PlaneMaterialCell
while(textureOffsetY < 0) textureOffsetY += texture.height; while(textureOffsetY < 0) textureOffsetY += texture.height;
bitmap.x = (textureOffsetX % texture.width); bitmap.tilePosition.set((textureOffsetX % texture.width), (textureOffsetY % texture.height));
bitmap.y = (textureOffsetY % texture.height);
bitmap.uvRespectAnchor = true;
if(textureOffsetX) if(textureOffsetX)
{ {
@ -134,89 +136,75 @@ export class PlaneMaterialCell
} }
} }
if(bitmap) if(!this.isStatic)
{ {
if(!this.isStatic) if(this._cachedSprite) this._cachedSprite.destroy();
this._cachedSprite = bitmap;
const limitMin = Math.min(this._extraItemCount, this._extraItemOffsets.length);
const limitMax = Math.max(this._extraItemCount, this._extraItemOffsets.length);
const offsetIndexes = Randomizer.getArray(this._extraItemCount, limitMax);
let i = 0;
while(i < limitMin)
{ {
if(this._cachedSprite) const offset = this._extraItemOffsets[offsetIndexes[i]];
const item = this._extraItemAssets[(i % this._extraItemAssets.length)];
if(offset && item)
{ {
if((this._cachedSprite.width !== bitmap.width) || (this._cachedSprite.height !== bitmap.height)) const assetTexture = item.texture;
if(assetTexture)
{ {
this._cachedSprite.destroy(); let itemOffsetX = item.offsetX;
let itemOffsetY = item.offsetY;
this._cachedSprite = null; let x = 1;
} let y = 1;
} let translateX = 0;
let translateY = 0;
if(!this._cachedSprite) if(item.flipH)
{
this._cachedSprite = new NitroSprite(texture);
}
const limitMin = Math.min(this._extraItemCount, this._extraItemOffsets.length);
const limitMax = Math.max(this._extraItemCount, this._extraItemOffsets.length);
const offsetIndexes = Randomizer.getArray(this._extraItemCount, limitMax);
let i = 0;
while(i < limitMin)
{
const offset = this._extraItemOffsets[offsetIndexes[i]];
const item = this._extraItemAssets[(i % this._extraItemAssets.length)];
if(offset && item)
{
const assetTexture = item.texture;
if(assetTexture)
{ {
const offsetFinal = new Point((offset.x + item.offsetX), (offset.y + item.offsetY)); x = -1;
const flipMatrix = new Matrix(); translateX = assetTexture.width;
itemOffsetX = -(item.width + item.x);
let x = 1;
let y = 1;
let translateX = 0;
let translateY = 0;
if(item.flipH)
{
x = -1;
translateX = assetTexture.width;
}
if(item.flipV)
{
y = -1;
translateY = assetTexture.height;
}
let offsetX = (offsetFinal.x + translateX);
offsetX = ((offsetX >> 1) << 1);
flipMatrix.scale(x, y);
flipMatrix.translate(offsetX, (offsetFinal.y + translateY));
const sprite = new NitroSprite(assetTexture);
sprite.transform.setFromMatrix(flipMatrix);
sprite.x = flipMatrix.tx;
sprite.y = flipMatrix.ty;
this._cachedSprite.addChild(sprite);
} }
}
i++; if(item.flipV)
{
y = -1;
translateY = assetTexture.height;
itemOffsetY = -(item.height + item.y);
}
const offsetFinal = new Point((offset.x + itemOffsetX), (offset.y + itemOffsetY));
const flipMatrix = new Matrix();
let offsetX = (offsetFinal.x + translateX);
offsetX = ((offsetX >> 1) << 1);
flipMatrix.scale(x, y);
flipMatrix.translate(offsetX, (offsetFinal.y + translateY));
const sprite = new Sprite(assetTexture);
sprite.transform.setFromMatrix(flipMatrix);
this._cachedSprite.addChild(sprite);
}
} }
return this._cachedSprite; i++;
} }
return bitmap; return this._cachedSprite;
} }
return null; return bitmap;
} }
public getAssetName(normal: IVector3D): string public getAssetName(normal: IVector3D): string

View File

@ -1,6 +1,7 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture, Texture } from '@pixi/core';
import { IVector3D, NitroLogger, Vector3d } from '../../../../../../../api'; import { Sprite } from '@pixi/sprite';
import { NitroRenderTexture } from '../../../../../../../pixi-proxy'; import { IVector3D, Vector3d } from '../../../../../../../api';
import { RoomTextureUtils, TextureUtils } from '../../../../../../../pixi-proxy';
import { PlaneMaterialCell } from './PlaneMaterialCell'; import { PlaneMaterialCell } from './PlaneMaterialCell';
export class PlaneMaterialCellColumn export class PlaneMaterialCellColumn
@ -15,8 +16,7 @@ export class PlaneMaterialCellColumn
private _cells: PlaneMaterialCell[]; private _cells: PlaneMaterialCell[];
private _repeatMode: number; private _repeatMode: number;
private _width: number; private _width: number;
private _cachedTexture: NitroRenderTexture; private _cachedBitmapData: RenderTexture;
private _cachedBitmapData: Graphics;
private _cachedBitmapNormal: Vector3d; private _cachedBitmapNormal: Vector3d;
private _cachedBitmapDataOffsetX: number; private _cachedBitmapDataOffsetX: number;
private _cachedBitmapDataOffsetY: number; private _cachedBitmapDataOffsetY: number;
@ -86,7 +86,7 @@ export class PlaneMaterialCellColumn
if(this._cachedBitmapData) if(this._cachedBitmapData)
{ {
this._cachedBitmapData.destroy(); this._cachedBitmapData.destroy(true);
this._cachedBitmapData = null; this._cachedBitmapData = null;
} }
@ -100,7 +100,7 @@ export class PlaneMaterialCellColumn
if(this._cachedBitmapData) if(this._cachedBitmapData)
{ {
this._cachedBitmapData.destroy(); this._cachedBitmapData.destroy(true);
this._cachedBitmapData = null; this._cachedBitmapData = null;
} }
@ -125,15 +125,9 @@ export class PlaneMaterialCellColumn
this._isCached = false; this._isCached = false;
} }
public render(height: number, normal: IVector3D, offsetX: number, offsetY: number): Graphics public render(height: number, normal: IVector3D, offsetX: number, offsetY: number): RenderTexture
{ {
let ht = 0; if(this._repeatMode === PlaneMaterialCellColumn.REPEAT_MODE_NONE) height = this.getCellsHeight(this._cells, normal);
if(this._repeatMode == PlaneMaterialCellColumn.REPEAT_MODE_NONE)
{
ht = this.getCellsHeight(this._cells, normal);
height = ht;
}
if(!this._cachedBitmapNormal) this._cachedBitmapNormal = new Vector3d(); if(!this._cachedBitmapNormal) this._cachedBitmapNormal = new Vector3d();
@ -145,10 +139,19 @@ export class PlaneMaterialCellColumn
{ {
return this._cachedBitmapData; return this._cachedBitmapData;
} }
else
{
if(this._cachedBitmapData.height === height)
{
TextureUtils.clearRenderTexture(this._cachedBitmapData);
}
else
{
this._cachedBitmapData.destroy(true);
this._cachedBitmapData.destroy(); this._cachedBitmapData = null;
}
this._cachedBitmapData = null; }
} }
} }
else else
@ -157,14 +160,16 @@ export class PlaneMaterialCellColumn
{ {
if(this._cachedBitmapData.height === height) if(this._cachedBitmapData.height === height)
{ {
this._cachedBitmapData const sprite = new Sprite(Texture.EMPTY);
.beginFill(0xFFFFFF)
.drawRect(0, 0, this._cachedBitmapData.width, height) sprite.width = this._cachedBitmapData.width;
.endFill(); sprite.height = height;
TextureUtils.writeToRenderTexture(sprite, this._cachedBitmapData);
} }
else else
{ {
this._cachedBitmapData.destroy(); this._cachedBitmapData.destroy(true);
this._cachedBitmapData = null; this._cachedBitmapData = null;
} }
@ -175,10 +180,7 @@ export class PlaneMaterialCellColumn
if(!this._cachedBitmapData) if(!this._cachedBitmapData)
{ {
this._cachedBitmapData = new Graphics() this._cachedBitmapData = RoomTextureUtils.createRenderTexture(this._width, height);
.beginFill(0xFFFFFF)
.drawRect(0, 0, this._width, height)
.endFill();
} }
this._cachedBitmapNormal.assign(normal); this._cachedBitmapNormal.assign(normal);
@ -193,20 +195,16 @@ export class PlaneMaterialCellColumn
this.renderRepeatNone(normal); this.renderRepeatNone(normal);
break; break;
case PlaneMaterialCellColumn.REPEAT_MODE_BORDERS: case PlaneMaterialCellColumn.REPEAT_MODE_BORDERS:
NitroLogger.log('REPEAT_MODE_BORDERS'); this.renderRepeatBorders(normal);
// this.renderRepeatBorders(normal);
break; break;
case PlaneMaterialCellColumn.REPEAT_MODE_CENTER: case PlaneMaterialCellColumn.REPEAT_MODE_CENTER:
NitroLogger.log('REPEAT_MODE_CENTER'); this.renderRepeatCenter(normal);
// this.renderRepeatCenter(normal);
break; break;
case PlaneMaterialCellColumn.REPEAT_MODE_FIRST: case PlaneMaterialCellColumn.REPEAT_MODE_FIRST:
NitroLogger.log('REPEAT_MODE_FIRST'); this.renderRepeatFirst(normal);
// this.renderRepeatFirst(normal);
break; break;
case PlaneMaterialCellColumn.REPEAT_MODE_LAST: case PlaneMaterialCellColumn.REPEAT_MODE_LAST:
NitroLogger.log('REPEAT_MODE_LAST'); this.renderRepeatLast(normal);
// this.renderRepeatLast(normal);
break; break;
default: default:
this.renderRepeatAll(normal, offsetX, offsetY); this.renderRepeatAll(normal, offsetX, offsetY);
@ -264,7 +262,7 @@ export class PlaneMaterialCellColumn
graphic.y = index; graphic.y = index;
this._cachedBitmapData.addChild(graphic); TextureUtils.writeToRenderTexture(graphic, this._cachedBitmapData, false);
if(flag) index = (index + graphic.height); if(flag) index = (index + graphic.height);
@ -299,190 +297,195 @@ export class PlaneMaterialCellColumn
} }
} }
// private renderRepeatBorders(k:IVector3D): void private renderRepeatBorders(k:IVector3D): void
// { {
// if (((this._cells.length == 0) || (this._cachedBitmapData == null))) if(!this._cells.length || !this._cachedBitmapData) return;
// {
// return;
// }
// var _local_2:PlaneMaterialCell;
// var _local_3:BitmapData;
// var _local_4:Array = [];
// var _local_5: number;
// var _local_6: number;
// var _local_7: number;
// _local_7 = 1;
// while (_local_7 < (this._cells.length - 1))
// {
// _local_2 = (this._cells[_local_7] as PlaneMaterialCell);
// if (_local_2 != null)
// {
// _local_6 = _local_2.getHeight(k);
// if (_local_6 > 0)
// {
// _local_5 = (_local_5 + _local_6);
// _local_4.push(_local_2);
// }
// }
// _local_7++;
// }
// if (this._cells.length == 1)
// {
// _local_2 = (this._cells[0] as PlaneMaterialCell);
// if (_local_2 != null)
// {
// _local_6 = _local_2.getHeight(k);
// if (_local_6 > 0)
// {
// _local_5 = (_local_5 + _local_6);
// _local_4.push(_local_2);
// }
// }
// }
// var _local_8:* = ((this._cachedBitmapData.height - _local_5) >> 1);
// var _local_9: number = this.renderCells(_local_4, _local_8, true, k);
// _local_2 = (this._cells[0] as PlaneMaterialCell);
// if (_local_2 != null)
// {
// _local_4 = [_local_2];
// while (_local_8 >= 0)
// {
// _local_8 = this.renderCells(_local_4, _local_8, false, k);
// }
// }
// _local_2 = (this._cells[(this._cells.length - 1)] as PlaneMaterialCell);
// if (_local_2 != null)
// {
// _local_4 = [_local_2];
// while (_local_9 < this._cachedBitmapData.height)
// {
// _local_9 = this.renderCells(_local_4, _local_9, true, k);
// }
// }
// }
// private renderRepeatCenter(k:IVector3D): void const _local_4: PlaneMaterialCell[] = [];
// {
// var _local_13: number;
// var _local_14: number;
// var _local_15: number;
// var _local_16:Array;
// if (((this._cells.length == 0) || (this._cachedBitmapData == null)))
// {
// return;
// }
// var _local_2:PlaneMaterialCell;
// var _local_3:BitmapData;
// var _local_4:Array = [];
// var _local_5:Array = [];
// var _local_6: number;
// var _local_7: number;
// var _local_8: number;
// var _local_9: number;
// _local_9 = 0;
// while (_local_9 < (this._cells.length >> 1))
// {
// _local_2 = (this._cells[_local_9] as PlaneMaterialCell);
// if (_local_2 != null)
// {
// _local_8 = _local_2.getHeight(k);
// if (_local_8 > 0)
// {
// _local_6 = (_local_6 + _local_8);
// _local_4.push(_local_2);
// }
// }
// _local_9++;
// }
// _local_9 = ((this._cells.length >> 1) + 1);
// while (_local_9 < this._cells.length)
// {
// _local_2 = (this._cells[_local_9] as PlaneMaterialCell);
// if (_local_2 != null)
// {
// _local_8 = _local_2.getHeight(k);
// if (_local_8 > 0)
// {
// _local_7 = (_local_7 + _local_8);
// _local_5.push(_local_2);
// }
// }
// _local_9++;
// }
// var _local_10: number;
// var _local_11: number;
// var _local_12: number = this._cachedBitmapData.height;
// if ((_local_6 + _local_7) > this._cachedBitmapData.height)
// {
// _local_10 = ((_local_6 + _local_7) - this._cachedBitmapData.height);
// _local_11 = (_local_11 - (_local_10 >> 1));
// _local_12 = (_local_12 + (_local_10 - (_local_10 >> 1)));
// }
// if (_local_10 == 0)
// {
// _local_2 = (this._cells[(this._cells.length >> 1)] as PlaneMaterialCell);
// if (_local_2 != null)
// {
// _local_8 = _local_2.getHeight(k);
// if (_local_8 > 0)
// {
// _local_13 = (this._cachedBitmapData.height - (_local_6 + _local_7));
// _local_14 = (Math.ceil((_local_13 / _local_8)) * _local_8);
// _local_11 = (_local_6 - ((_local_14 - _local_13) >> 1));
// _local_15 = (_local_11 + _local_14);
// _local_16 = [_local_2];
// while (_local_11 < _local_15)
// {
// _local_11 = this.renderCells(_local_16, _local_11, true, k);
// }
// }
// }
// }
// _local_11 = 0;
// this.renderCells(_local_4, _local_11, true, k);
// this.renderCells(_local_5, _local_12, false, k);
// }
// private renderRepeatFirst(k:IVector3D): void let _local_5 = 0;
// { let _local_7 = 1;
// var _local_4:Array;
// if (((this._cells.length == 0) || (this._cachedBitmapData == null)))
// {
// return;
// }
// var _local_2:PlaneMaterialCell;
// var _local_3: number = this._cachedBitmapData.height;
// _local_3 = this.renderCells(this._cells, _local_3, false, k);
// _local_2 = (this._cells[0] as PlaneMaterialCell);
// if (_local_2 != null)
// {
// _local_4 = [_local_2];
// while (_local_3 >= 0)
// {
// _local_3 = this.renderCells(_local_4, _local_3, false, k);
// }
// }
// }
// private renderRepeatLast(k: IVector3D): void while(_local_7 < (this._cells.length - 1))
// { {
// if(!this._cells.length || !this._cachedBitmapData) return; const cell = (this._cells[_local_7] as PlaneMaterialCell);
if(cell)
{
const height = cell.getHeight(k);
// var _local_4:Array; if(height > 0)
// var _local_2:PlaneMaterialCell; {
// var _local_3: number; _local_5 = (_local_5 + height);
// _local_3 = this.renderCells(this._cells, _local_3, true, k);
// _local_2 = (this._cells[(this._cells.length - 1)] as PlaneMaterialCell); _local_4.push(cell);
// if (_local_2 != null) }
// { }
// _local_4 = [_local_2];
// while (_local_3 < this._cachedBitmapData.height) _local_7++;
// { }
// _local_3 = this.renderCells(_local_4, _local_3, true, k);
// } if(this._cells.length == 1)
// } {
// } const cell = this._cells[0];
if(cell)
{
const height = cell.getHeight(k);
if(height > 0)
{
_local_5 = (_local_5 + height);
_local_4.push(cell);
}
}
}
let _local_8 = ((this._cachedBitmapData.height - _local_5) >> 1);
let index: number = this.renderCells(_local_4, _local_8, true, k);
let cell = this._cells[0];
if(cell)
{
const cells = [cell];
while(_local_8 >= 0) _local_8 = this.renderCells(cells, _local_8, false, k);
}
cell = this._cells[(this._cells.length - 1)];
if(cell)
{
const cells = [cell];
while(index < this._cachedBitmapData.height) index = this.renderCells(cells, index, true, k);
}
}
private renderRepeatCenter(k:IVector3D): void
{
if(!this._cells.length || !this._cachedBitmapData) return;
const _local_4: PlaneMaterialCell[] = [];
const _local_5: PlaneMaterialCell[] = [];
let _local_6 = 0;
let _local_7 = 0;
let _local_9 = 0;
while(_local_9 < (this._cells.length >> 1))
{
const cell = this._cells[_local_9];
if(cell)
{
const height = cell.getHeight(k);
if(height > 0)
{
_local_6 = (_local_6 + height);
_local_4.push(cell);
}
}
_local_9++;
}
_local_9 = ((this._cells.length >> 1) + 1);
while(_local_9 < this._cells.length)
{
const cell = this._cells[_local_9];
if(cell)
{
const height = cell.getHeight(k);
if(height > 0)
{
_local_7 = (_local_7 + height);
_local_5.push(cell);
}
}
_local_9++;
}
let _local_10 = 0;
let _local_11: number;
let _local_12 = this._cachedBitmapData.height;
if((_local_6 + _local_7) > this._cachedBitmapData.height)
{
_local_10 = ((_local_6 + _local_7) - this._cachedBitmapData.height);
_local_11 = (_local_11 - (_local_10 >> 1));
_local_12 = (_local_12 + (_local_10 - (_local_10 >> 1)));
}
if(_local_10 == 0)
{
const cell = this._cells[(this._cells.length >> 1)];
if(cell)
{
const height = cell.getHeight(k);
if(height > 0)
{
const _local_13 = (this._cachedBitmapData.height - (_local_6 + _local_7));
const _local_14 = (Math.ceil((_local_13 / height)) * height);
let _local_11 = (_local_6 - ((_local_14 - _local_13) >> 1));
const _local_15 = (_local_11 + _local_14);
const _local_16 = [cell];
while(_local_11 < _local_15) _local_11 = this.renderCells(_local_16, _local_11, true, k);
}
}
}
this.renderCells(_local_4, 0, true, k);
this.renderCells(_local_5, _local_12, false, k);
}
private renderRepeatFirst(k:IVector3D): void
{
if(!this._cells.length || !this._cachedBitmapData) return;
let index = this.renderCells(this._cells, this._cachedBitmapData.height, false, k);
const cell = (this._cells[0] as PlaneMaterialCell);
if(!cell) return;
const cells = [ cell ];
while(index >= 0) index = this.renderCells(cells, index, false, k);
}
private renderRepeatLast(normal: IVector3D): void
{
if(!this._cells.length || !this._cachedBitmapData) return;
let index = this.renderCells(this._cells, 0, true, normal);
const cell = (this._cells[(this._cells.length - 1)] as PlaneMaterialCell);
if(!cell) return;
const cells = [cell];
while(index < this._cachedBitmapData.height)
{
index = this.renderCells(cells, index, true, normal);
}
}
public getCells(): PlaneMaterialCell[] public getCells(): PlaneMaterialCell[]
{ {

View File

@ -1,8 +1,8 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture, Texture } from '@pixi/core';
import { Point, Rectangle } from '@pixi/math'; import { Point, Rectangle } from '@pixi/math';
import { IVector3D, Vector3d } from '../../../../../../../api'; import { Sprite } from '@pixi/sprite';
import { TextureUtils } from '../../../../../../../pixi-proxy'; import { IVector3D, NitroLogger, Vector3d } from '../../../../../../../api';
import { RoomVisualization } from '../../RoomVisualization'; import { RoomTextureUtils, TextureUtils } from '../../../../../../../pixi-proxy';
import { Randomizer } from '../../utils'; import { Randomizer } from '../../utils';
import { PlaneMaterialCell } from './PlaneMaterialCell'; import { PlaneMaterialCell } from './PlaneMaterialCell';
import { PlaneMaterialCellColumn } from './PlaneMaterialCellColumn'; import { PlaneMaterialCellColumn } from './PlaneMaterialCellColumn';
@ -25,7 +25,7 @@ export class PlaneMaterialCellMatrix
private _columns: PlaneMaterialCellColumn[]; private _columns: PlaneMaterialCellColumn[];
private _repeatMode: number = 1; private _repeatMode: number = 1;
private _align: number = 1; private _align: number = 1;
private _cachedBitmapData: Graphics; private _cachedBitmapData: RenderTexture;
private _cachedBitmapNormal: Vector3d = null; private _cachedBitmapNormal: Vector3d = null;
private _cachedBitmapHeight: number = 0; private _cachedBitmapHeight: number = 0;
private _isCached: boolean = false; private _isCached: boolean = false;
@ -34,35 +34,39 @@ export class PlaneMaterialCellMatrix
private _normalMaxX: number = 1; private _normalMaxX: number = 1;
private _normalMinY: number = -1; private _normalMinY: number = -1;
private _normalMaxY: number = 1; private _normalMaxY: number = 1;
private _texturePool: Map<string, RenderTexture>;
constructor(totalColumns: number, repeatMode: number = 1, align: number = 1, normalMinX: number = -1, normalMaxX: number = 1, normalMinY: number = -1, normalMaxY: number = 1) constructor(totalColumns: number, repeatMode: number = 1, align: number = 1, normalMinX: number = -1, normalMaxX: number = 1, normalMinY: number = -1, normalMaxY: number = 1)
{ {
this._columns = []; this._columns = [];
if(totalColumns < 1)
{ if(totalColumns < 1) totalColumns = 1;
totalColumns = 1;
}
let _local_8 = 0; let _local_8 = 0;
while(_local_8 < totalColumns) while(_local_8 < totalColumns)
{ {
this._columns.push(null); this._columns.push(null);
_local_8++; _local_8++;
} }
this._repeatMode = repeatMode; this._repeatMode = repeatMode;
this._align = align; this._align = align;
this._normalMinX = normalMinX; this._normalMinX = normalMinX;
this._normalMaxX = normalMaxX; this._normalMaxX = normalMaxX;
this._normalMinY = normalMinY; this._normalMinY = normalMinY;
this._normalMaxY = normalMaxY; this._normalMaxY = normalMaxY;
if(this._repeatMode == PlaneMaterialCellMatrix.REPEAT_MODE_RANDOM) this._texturePool = new Map();
{
this._isStatic = false; if(this._repeatMode === PlaneMaterialCellMatrix.REPEAT_MODE_RANDOM) this._isStatic = false;
}
} }
private static nextRandomColumnIndex(totalColumns: number): number private static nextRandomColumnIndex(totalColumns: number): number
{ {
return ((Randomizer.getValues(1, 0, (totalColumns * 17631))[0]) % totalColumns); const _local_2 = Randomizer.getValues(1, 0, (totalColumns * 17631));
return _local_2[0] % totalColumns;
} }
public get normalMinX(): number public get normalMinX(): number
@ -99,7 +103,7 @@ export class PlaneMaterialCellMatrix
{ {
if(this._cachedBitmapData) if(this._cachedBitmapData)
{ {
this._cachedBitmapData.destroy(); this._cachedBitmapData.destroy(true);
this._cachedBitmapData = null; this._cachedBitmapData = null;
} }
@ -135,6 +139,13 @@ export class PlaneMaterialCellMatrix
} }
} }
if(this._texturePool && this._texturePool.size)
{
this._texturePool.forEach(texture => texture.destroy(true));
this._texturePool.clear();
}
this._isCached = false; this._isCached = false;
} }
@ -154,7 +165,7 @@ export class PlaneMaterialCellMatrix
return true; return true;
} }
public render(canvas: Graphics, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): Graphics public render(canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): RenderTexture
{ {
if(width < 1) width = 1; if(width < 1) width = 1;
@ -168,7 +179,7 @@ export class PlaneMaterialCellMatrix
{ {
if(this._cachedBitmapData) if(this._cachedBitmapData)
{ {
if(((this._cachedBitmapData.width === width) && (this._cachedBitmapData.height == height)) && Vector3d.isEqual(this._cachedBitmapNormal, normal)) if((this._cachedBitmapData.width === width) && (this._cachedBitmapData.height === height) && Vector3d.isEqual(this._cachedBitmapNormal, normal))
{ {
if(canvas) if(canvas)
{ {
@ -180,29 +191,12 @@ export class PlaneMaterialCellMatrix
return this._cachedBitmapData; return this._cachedBitmapData;
} }
this._cachedBitmapData.destroy();
this._cachedBitmapData = null; this._cachedBitmapData = null;
} }
} }
else else
{ {
if(this._cachedBitmapData) this._cachedBitmapData = null;
{
if((this._cachedBitmapData.width === width) && (this._cachedBitmapData.height === height))
{
this._cachedBitmapData
.beginFill(0xFFFFFF)
.drawRect(0, 0, width, height)
.endFill();
}
else
{
this._cachedBitmapData.destroy();
this._cachedBitmapData = null;
}
}
} }
this._isCached = true; this._isCached = true;
@ -214,19 +208,22 @@ export class PlaneMaterialCellMatrix
if(!this._cachedBitmapData) if(!this._cachedBitmapData)
{ {
const graphic = new Graphics() this._cachedBitmapData = this._texturePool.get(`${width}:${height}`);
.beginFill(0xFFFFFF)
.drawRect(0, 0, width, height)
.endFill();
this._cachedBitmapData = graphic; if(!this._cachedBitmapData)
{
this._cachedBitmapData = RoomTextureUtils.createAndFillRenderTexture(width, height);
this._texturePool.set(`${width}:${height}`, this._cachedBitmapData);
}
else
{
TextureUtils.clearAndFillRenderTexture(this._cachedBitmapData);
}
} }
else else
{ {
this._cachedBitmapData TextureUtils.clearAndFillRenderTexture(this._cachedBitmapData);
.beginFill(0xFFFFFF)
.drawRect(0, 0, width, height)
.endFill();
} }
if(canvas) if(canvas)
@ -243,15 +240,21 @@ export class PlaneMaterialCellMatrix
{ {
this._cachedBitmapHeight = height; this._cachedBitmapHeight = height;
const graphic = new Graphics() this._cachedBitmapData = this._texturePool.get(`${width}:${height}`);
.beginFill(0xFFFFFF)
.drawRect(0, 0, width, height)
.endFill();
this._cachedBitmapData = graphic; if(!this._cachedBitmapData)
{
this._cachedBitmapData = RoomTextureUtils.createRenderTexture(width, height);
this._texturePool.set(`${width}:${height}`, this._cachedBitmapData);
}
else
{
TextureUtils.clearRenderTexture(this._cachedBitmapData);
}
} }
const columns: Graphics[] = []; const columns: RenderTexture[] = [];
let columnIndex = 0; let columnIndex = 0;
@ -281,19 +284,23 @@ export class PlaneMaterialCellMatrix
switch(this._repeatMode) switch(this._repeatMode)
{ {
case PlaneMaterialCellMatrix.REPEAT_MODE_BORDERS: case PlaneMaterialCellMatrix.REPEAT_MODE_BORDERS:
NitroLogger.log('REPEAT_MODE_BORDERS');
// maxColumnHeight = this.renderRepeatBorders(this._cachedBitmapData, columns); // maxColumnHeight = this.renderRepeatBorders(this._cachedBitmapData, columns);
break; break;
case PlaneMaterialCellMatrix.REPEAT_MODE_CENTER: case PlaneMaterialCellMatrix.REPEAT_MODE_CENTER:
NitroLogger.log('REPEAT_MODE_CENTER');
// maxColumnHeight = this.renderRepeatCenter(this._cachedBitmapData, columns); // maxColumnHeight = this.renderRepeatCenter(this._cachedBitmapData, columns);
break; break;
case PlaneMaterialCellMatrix.REPEAT_MODE_FIRST: case PlaneMaterialCellMatrix.REPEAT_MODE_FIRST:
NitroLogger.log('REPEAT_MODE_FIRST');
// maxColumnHeight = this.renderRepeatFirst(this._cachedBitmapData, columns); // maxColumnHeight = this.renderRepeatFirst(this._cachedBitmapData, columns);
break; break;
case PlaneMaterialCellMatrix.REPEAT_MODE_LAST: case PlaneMaterialCellMatrix.REPEAT_MODE_LAST:
NitroLogger.log('REPEAT_MODE_LAST');
// maxColumnHeight = this.renderRepeatLast(this._cachedBitmapData, columns); // maxColumnHeight = this.renderRepeatLast(this._cachedBitmapData, columns);
break; break;
case PlaneMaterialCellMatrix.REPEAT_MODE_RANDOM: case PlaneMaterialCellMatrix.REPEAT_MODE_RANDOM:
// maxColumnHeight = this.renderRepeatRandom(this._cachedBitmapData, columns); maxColumnHeight = this.renderRepeatRandom(this._cachedBitmapData, columns);
break; break;
default: default:
maxColumnHeight = this.renderRepeatAll(this._cachedBitmapData, columns); maxColumnHeight = this.renderRepeatAll(this._cachedBitmapData, columns);
@ -312,51 +319,48 @@ export class PlaneMaterialCellMatrix
return this._cachedBitmapData; return this._cachedBitmapData;
} }
private copyCachedBitmapOnCanvas(canvas: Graphics, height: number, offsetY: number, topAlign: boolean): void private copyCachedBitmapOnCanvas(canvas: RenderTexture, height: number, offsetY: number, topAlign: boolean): void
{ {
if(!canvas || !this._cachedBitmapData || (canvas === this._cachedBitmapData)) return; if(!canvas || !this._cachedBitmapData || (canvas === this._cachedBitmapData)) return;
if(!topAlign) offsetY = ((canvas.height - height) - offsetY); if(!topAlign) offsetY = ((canvas.height - height) - offsetY);
let _local_5: Rectangle; let bounds: Rectangle = null;
if(this._align == PlaneMaterialCellMatrix.ALIGN_TOP) if(this._align === PlaneMaterialCellMatrix.ALIGN_TOP)
{ {
_local_5 = new Rectangle(0, 0, this._cachedBitmapData.width, this._cachedBitmapHeight); bounds = new Rectangle(0, 0, this._cachedBitmapData.width, this._cachedBitmapHeight);
} }
else else
{ {
_local_5 = new Rectangle(0, (this._cachedBitmapData.height - this._cachedBitmapHeight), this._cachedBitmapData.width, this._cachedBitmapHeight); bounds = new Rectangle(0, (this._cachedBitmapData.height - this._cachedBitmapHeight), this._cachedBitmapData.width, this._cachedBitmapHeight);
} }
const texture = TextureUtils.generateTexture(this._cachedBitmapData, _local_5); const texture = new Texture(this._cachedBitmapData.baseTexture, bounds);
const sprite = new Sprite(texture);
if(texture) sprite.position.set(0, offsetY);
{
canvas TextureUtils.writeToRenderTexture(sprite, canvas, false);
.beginTextureFill({ texture })
.drawRect(0, offsetY, _local_5.width, _local_5.height)
.endFill();
}
} }
private getColumnsWidth(columns: Graphics[]): number private getColumnsWidth(columns: RenderTexture[]): number
{ {
if(!columns || !columns.length) return 0; if(!columns || !columns.length) return 0;
let width = 0; let width = 0;
for(const graphic of columns) for(const texture of columns)
{ {
if(!graphic) continue; if(!texture) continue;
width += graphic.width; width += texture.width;
} }
return width; return width;
} }
private renderColumns(canvas: Graphics, columns: Graphics[], x: number, flag: boolean): Point private renderColumns(canvas: RenderTexture, columns: RenderTexture[], x: number, flag: boolean): Point
{ {
if(!canvas || !columns || !columns.length) return new Point(x, 0); if(!canvas || !columns || !columns.length) return new Point(x, 0);
@ -375,18 +379,11 @@ export class PlaneMaterialCellMatrix
if(this._align == PlaneMaterialCellMatrix.ALIGN_BOTTOM) y = (canvas.height - column.height); if(this._align == PlaneMaterialCellMatrix.ALIGN_BOTTOM) y = (canvas.height - column.height);
let texture = RoomVisualization.getTextureCache(column); const sprite = new Sprite(column);
if(!texture) sprite.position.set(x, y);
{
texture = TextureUtils.generateTexture(column, new Rectangle(0, 0, column.width, column.height));
RoomVisualization.addTextureCache(column, texture); TextureUtils.writeToRenderTexture(sprite, canvas, false);
}
canvas.beginTextureFill({ texture });
canvas.drawRect(x, y, texture.width, texture.height);
canvas.endFill();
if(column.height > height) height = column.height; if(column.height > height) height = column.height;
@ -401,7 +398,7 @@ export class PlaneMaterialCellMatrix
return new Point(x, height); return new Point(x, height);
} }
private renderRepeatAll(canvas: Graphics, columns: Graphics[]): number private renderRepeatAll(canvas: RenderTexture, columns: RenderTexture[]): number
{ {
if(!canvas || !columns || !columns.length) return 0; if(!canvas || !columns || !columns.length) return 0;
@ -646,37 +643,37 @@ export class PlaneMaterialCellMatrix
// return _local_3; // return _local_3;
// } // }
// private renderRepeatRandom(k:BitmapData, _arg_2:Array): number private renderRepeatRandom(canvas: RenderTexture, columns: RenderTexture[]): number
// { {
// var _local_6:Array; if(!canvas || !columns || !columns.length) return 0;
// var _local_7:Point;
// if ((((_arg_2 == null) || (_arg_2.length == 0)) || (k == null))) let height = 0;
// { let width = 0;
// return 0;
// } while(width < canvas.width)
// var _local_3: number; {
// var _local_4:BitmapData; const column = columns[PlaneMaterialCellMatrix.nextRandomColumnIndex(columns.length)];
// var _local_5: number;
// while (_local_5 < k.width) if(column != null)
// { {
// _local_4 = (_arg_2[nextRandomColumnIndex(_arg_2.length)] as BitmapData); const point = this.renderColumns(canvas, [ column ], width, true);
// if (_local_4 != null)
// { width = point.x;
// _local_6 = [_local_4];
// _local_7 = this.renderColumns(k, _local_6, _local_5, true); if(point.y > height)
// _local_5 = _local_7.x; {
// if (_local_7.y > _local_3) height = point.y;
// { }
// _local_3 = _local_7.y; }
// } else
// } {
// else return height;
// {
// return _local_3; }
// } }
// }
// return _local_3; return height;
// } }
public getColumns(width: number): PlaneMaterialCellColumn[] public getColumns(width: number): PlaneMaterialCellColumn[]
{ {
@ -697,6 +694,7 @@ export class PlaneMaterialCellMatrix
if(column.width > 1) columnIndex += column.width; if(column.width > 1) columnIndex += column.width;
else break; else break;
} }
else break;
} }
return columns; return columns;

View File

@ -1,7 +1,6 @@
import { Resource, Texture } from '@pixi/core'; import { RenderTexture, Resource, Texture } from '@pixi/core';
import { Graphics } from '@pixi/graphics';
import { Point } from '@pixi/math'; import { Point } from '@pixi/math';
import { IGraphicAsset, IGraphicAssetCollection, IRoomGeometry, IVector3D, Vector3d } from '../../../../../../../api'; import { IAssetPlaneMaterial, IAssetPlaneMaterialCellColumn, IAssetPlaneTexture, IAssetPlaneVisualization, IAssetPlaneVisualizationData, IAssetPlaneVisualizationLayer, IGraphicAsset, IGraphicAssetCollection, IRoomGeometry, IVector3D, Vector3d } from '../../../../../../../api';
import { Rasterizer, RoomGeometry } from '../../../../../../../room'; import { Rasterizer, RoomGeometry } from '../../../../../../../room';
import { PlaneBitmapData } from '../../utils'; import { PlaneBitmapData } from '../../utils';
import { IPlaneRasterizer } from '../IPlaneRasterizer'; import { IPlaneRasterizer } from '../IPlaneRasterizer';
@ -23,7 +22,7 @@ export class PlaneRasterizer implements IPlaneRasterizer
private _textures: Map<string, PlaneTexture>; private _textures: Map<string, PlaneTexture>;
private _planes: Map<string, Plane>; private _planes: Map<string, Plane>;
private _geometries: Map<string, RoomGeometry>; private _geometries: Map<string, RoomGeometry>;
private _data: any; private _data: IAssetPlaneVisualizationData;
constructor() constructor()
{ {
@ -35,7 +34,7 @@ export class PlaneRasterizer implements IPlaneRasterizer
this._data = null; this._data = null;
} }
protected get data(): any protected get data(): IAssetPlaneVisualizationData
{ {
return this._data; return this._data;
} }
@ -111,7 +110,7 @@ export class PlaneRasterizer implements IPlaneRasterizer
} }
} }
public initialize(data: any): void public initialize(data: IAssetPlaneVisualizationData): void
{ {
this._data = data; this._data = data;
} }
@ -199,7 +198,6 @@ export class PlaneRasterizer implements IPlaneRasterizer
private initializeTexturesAndMaterials(): void private initializeTexturesAndMaterials(): void
{ {
if(this._data.textures && this._data.textures.length) this.parseTextures(this._data.textures, this.assetCollection); if(this._data.textures && this._data.textures.length) this.parseTextures(this._data.textures, this.assetCollection);
if(this._data.materials && this._data.materials.length) this.parsePlaneMaterials(this._data.materials); if(this._data.materials && this._data.materials.length) this.parsePlaneMaterials(this._data.materials);
} }
@ -207,7 +205,7 @@ export class PlaneRasterizer implements IPlaneRasterizer
{ {
} }
private parseTextures(textures: any, collection: IGraphicAssetCollection): void private parseTextures(textures: IAssetPlaneTexture[], collection: IGraphicAssetCollection): void
{ {
if(!textures || !collection) return; if(!textures || !collection) return;
@ -255,6 +253,10 @@ export class PlaneRasterizer implements IPlaneRasterizer
{ {
newTexture = Rasterizer.getFlipHBitmapData(texture); newTexture = Rasterizer.getFlipHBitmapData(texture);
} }
else
{
newTexture = newTexture.clone();
}
plane.addBitmap(newTexture, normalMinX, normalMaxX, normalMinY, normalMaxY, assetName); plane.addBitmap(newTexture, normalMinX, normalMaxX, normalMinY, normalMaxY, assetName);
} }
@ -268,7 +270,7 @@ export class PlaneRasterizer implements IPlaneRasterizer
} }
} }
private parsePlaneMaterials(materials: any): void private parsePlaneMaterials(materials: IAssetPlaneMaterial[]): void
{ {
if(!materials || !materials.length) return; if(!materials || !materials.length) return;
@ -285,14 +287,20 @@ export class PlaneRasterizer implements IPlaneRasterizer
{ {
if(!matrix) continue; if(!matrix) continue;
let repeatMode = matrix.repeatMode; let repeatMode = PlaneMaterialCellMatrix.REPEAT_MODE_DEFAULT;
let align = matrix.align; let align = PlaneMaterialCellMatrix.ALIGN_DEFAULT;
const normalMinX = PlaneMaterialCellMatrix.MIN_NORMAL_COORDINATE_VALUE;
const normalMaxX = PlaneMaterialCellMatrix.MAX_NORMAL_COORDINATE_VALUE;
const normalMinY = PlaneMaterialCellMatrix.MIN_NORMAL_COORDINATE_VALUE;
const normalMaxY = PlaneMaterialCellMatrix.MAX_NORMAL_COORDINATE_VALUE;
switch(repeatMode) let normalMinX = PlaneMaterialCellMatrix.MIN_NORMAL_COORDINATE_VALUE;
let normalMaxX = PlaneMaterialCellMatrix.MAX_NORMAL_COORDINATE_VALUE;
let normalMinY = PlaneMaterialCellMatrix.MIN_NORMAL_COORDINATE_VALUE;
let normalMaxY = PlaneMaterialCellMatrix.MAX_NORMAL_COORDINATE_VALUE;
if(matrix.normalMinX !== undefined) normalMinX = matrix.normalMinX;
if(matrix.normalMaxX !== undefined) normalMaxX = matrix.normalMaxX;
if(matrix.normalMinY !== undefined) normalMinY = matrix.normalMinY;
if(matrix.normalMaxY !== undefined) normalMaxY = matrix.normalMaxY;
switch(matrix.repeatMode)
{ {
case 'borders': case 'borders':
repeatMode = PlaneMaterialCellMatrix.REPEAT_MODE_BORDERS; repeatMode = PlaneMaterialCellMatrix.REPEAT_MODE_BORDERS;
@ -314,7 +322,7 @@ export class PlaneRasterizer implements IPlaneRasterizer
break; break;
} }
switch(align) switch(matrix.align)
{ {
case 'top': case 'top':
align = PlaneMaterialCellMatrix.ALIGN_TOP; align = PlaneMaterialCellMatrix.ALIGN_TOP;
@ -349,7 +357,7 @@ export class PlaneRasterizer implements IPlaneRasterizer
} }
} }
private parsePlaneMaterialCellColumn(column: { repeatMode: string, width: number }, cellMatrix: PlaneMaterialCellMatrix, index: number): void private parsePlaneMaterialCellColumn(column: IAssetPlaneMaterialCellColumn, cellMatrix: PlaneMaterialCellMatrix, index: number): void
{ {
if(!column || !cellMatrix) return; if(!column || !cellMatrix) return;
@ -384,7 +392,7 @@ export class PlaneRasterizer implements IPlaneRasterizer
cellMatrix.createColumn(index, width, cells, repeatMode); cellMatrix.createColumn(index, width, cells, repeatMode);
} }
private parsePlaneMaterialCells(column: any): PlaneMaterialCell[] private parsePlaneMaterialCells(column: IAssetPlaneMaterialCellColumn): PlaneMaterialCell[]
{ {
if(!column || !column.cells || !column.cells.length) return null; if(!column || !column.cells || !column.cells.length) return null;
@ -405,24 +413,20 @@ export class PlaneRasterizer implements IPlaneRasterizer
let graphics: IGraphicAsset[] = null; let graphics: IGraphicAsset[] = null;
let limit = 0; let limit = 0;
if(cell.extras && cell.extras.length) if(cell.extraData)
{ {
const extra = cell.extras[0]; const types = cell.extraData.extraItemTypes;
const types = extra.types; const offsets = cell.extraData.offsets;
const offsets = extra.offsets;
if(types && offsets) if(types && offsets)
{ {
if(types.length && offsets.length) if(types.length && offsets.length)
{ {
const type = types[0]; assetNames = this.parseExtraItemTypes(types);
const offset = offsets[0]; offsetPoints = this.parseExtraItemOffsets(offsets);
assetNames = this.parseExtraItemTypes(type);
offsetPoints = this.parseExtraItemOffsets(offset);
limit = offsetPoints.length; limit = offsetPoints.length;
if(extra.limitMax) limit = extra.limitMax; if(cell.extraData.limitMax !== undefined) limit = cell.extraData.limitMax;
} }
} }
} }
@ -457,21 +461,19 @@ export class PlaneRasterizer implements IPlaneRasterizer
return cells; return cells;
} }
private parseExtraItemTypes(k: any): string[] private parseExtraItemTypes(k: string[]): string[]
{ {
const assetNames: string[] = []; const assetNames: string[] = [];
if(k && k.types && k.types.length) if(k && k.length)
{ {
let index = 0; let index = 0;
while(index < k.types.length) while(index < k.length)
{ {
const type = k.types[index]; const type = k[index];
const assetName = type.assetName; if(type) assetNames.push(type);
if(assetName) assetNames.push(assetName);
index++; index++;
} }
@ -480,20 +482,17 @@ export class PlaneRasterizer implements IPlaneRasterizer
return assetNames; return assetNames;
} }
private parseExtraItemOffsets(k: any): Point[] private parseExtraItemOffsets(k: [ number, number][]): Point[]
{ {
const offsets: Point[] = []; const offsets: Point[] = [];
if(k && k.offsets && k.offsets.length) if(k && k.length)
{ {
let index = 0; let index = 0;
while(index < k.offsets.length) while(index < k.length)
{ {
const offset = k.offsets[index]; const [ x, y ] = k[index];
const x = offset.x;
const y = offset.y;
offsets.push(new Point(x, y)); offsets.push(new Point(x, y));
@ -525,7 +524,7 @@ export class PlaneRasterizer implements IPlaneRasterizer
return geometry; return geometry;
} }
protected parseVisualizations(plane: Plane, visualizations: any): void protected parseVisualizations(plane: Plane, visualizations: IAssetPlaneVisualization[]): void
{ {
if(!plane || !visualizations) return; if(!plane || !visualizations) return;
@ -540,10 +539,10 @@ export class PlaneRasterizer implements IPlaneRasterizer
let horizontalAngle = FloorPlane.HORIZONTAL_ANGLE_DEFAULT; let horizontalAngle = FloorPlane.HORIZONTAL_ANGLE_DEFAULT;
let verticalAngle = FloorPlane.VERTICAL_ANGLE_DEFAULT; let verticalAngle = FloorPlane.VERTICAL_ANGLE_DEFAULT;
if(visualization.horizontalAngle) horizontalAngle = visualization.horizontalAngle; if(visualization.horizontalAngle !== undefined) horizontalAngle = visualization.horizontalAngle;
if(visualization.verticalAngle) verticalAngle = visualization.verticalAngle; if(visualization.verticalAngle !== undefined) verticalAngle = visualization.verticalAngle;
const layers = visualization.layers; const layers = visualization.allLayers as IAssetPlaneVisualizationLayer[];
const planeVisualization = plane.createPlaneVisualization(size, ((layers && layers.length) || 0), this.getGeometry(size, horizontalAngle, verticalAngle)); const planeVisualization = plane.createPlaneVisualization(size, ((layers && layers.length) || 0), this.getGeometry(size, horizontalAngle, verticalAngle));
@ -585,7 +584,7 @@ export class PlaneRasterizer implements IPlaneRasterizer
} }
} }
public render(canvas: Graphics, id: string, width: number, height: number, size: number, normal: IVector3D, useTexture: boolean, offsetX: number = 0, offsetY: number = 0, maxX: number = 0, maxY: number = 0, timeSinceStartMs: number = 0): PlaneBitmapData public render(planeId: string, canvas: RenderTexture, id: string, width: number, height: number, size: number, normal: IVector3D, useTexture: boolean, offsetX: number = 0, offsetY: number = 0, maxX: number = 0, maxY: number = 0, timeSinceStartMs: number = 0): PlaneBitmapData
{ {
return null; return null;
} }

View File

@ -29,9 +29,9 @@ export class PlaneTexture
} }
} }
public addBitmap(texture: Texture<Resource>, normalMinX: number = -1, normalMaxX: number = 1, normalMinY: number = -1, normalMaxY: number = 1, assetName: string = null): void public addBitmap(bitmap: Texture<Resource>, normalMinX: number = -1, normalMaxX: number = 1, normalMinY: number = -1, normalMaxY: number = 1, assetName: string = null): void
{ {
this._bitmaps.push(new PlaneTextureBitmap(texture, normalMinX, normalMaxX, normalMinY, normalMaxY, assetName)); this._bitmaps.push(new PlaneTextureBitmap(bitmap, normalMinX, normalMaxX, normalMinY, normalMaxY, assetName));
} }
public getBitmap(k: IVector3D): Texture<Resource> public getBitmap(k: IVector3D): Texture<Resource>

View File

@ -12,14 +12,14 @@ export class PlaneTextureBitmap
private _normalMaxY: number; private _normalMaxY: number;
private _assetName: string; private _assetName: string;
constructor(texture: Texture<Resource>, normalMinX: number = -1, normalMaxX: number = 1, normalMinY: number = -1, normalMaxY: number = 1, assetName: string = null) constructor(bitmap: Texture<Resource>, normalMinX: number = -1, normalMaxX: number = 1, normalMinY: number = -1, normalMaxY: number = 1, assetName: string = null)
{ {
this._bitmap = bitmap;
this._normalMinX = normalMinX; this._normalMinX = normalMinX;
this._normalMaxX = normalMaxX; this._normalMaxX = normalMaxX;
this._normalMinY = normalMinY; this._normalMinY = normalMinY;
this._normalMaxY = normalMaxY; this._normalMaxY = normalMaxY;
this._assetName = assetName; this._assetName = assetName;
this._bitmap = texture;
} }
public get bitmap(): Texture<Resource> public get bitmap(): Texture<Resource>

View File

@ -1,5 +1,7 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
import { Sprite } from '@pixi/sprite';
import { IDisposable, IGraphicAssetCollection, IRoomGeometry, IVector3D, Vector3d } from '../../../../../../../api'; import { IDisposable, IGraphicAssetCollection, IRoomGeometry, IVector3D, Vector3d } from '../../../../../../../api';
import { RoomTextureUtils, TextureUtils } from '../../../../../../../pixi-proxy';
import { PlaneVisualizationAnimationLayer } from '../animated'; import { PlaneVisualizationAnimationLayer } from '../animated';
import { PlaneMaterial } from './PlaneMaterial'; import { PlaneMaterial } from './PlaneMaterial';
import { PlaneVisualizationLayer } from './PlaneVisualizationLayer'; import { PlaneVisualizationLayer } from './PlaneVisualizationLayer';
@ -8,10 +10,11 @@ export class PlaneVisualization
{ {
private _layers: IDisposable[]; private _layers: IDisposable[];
private _geometry: IRoomGeometry; private _geometry: IRoomGeometry;
private _cachedBitmapData: Graphics; private _cachedBitmapData: RenderTexture;
private _cachedBitmapNormal: Vector3d; private _cachedBitmapNormal: Vector3d;
private _isCached: boolean; private _isCached: boolean;
private _hasAnimationLayers: boolean; private _hasAnimationLayers: boolean;
private _texturePool: Map<string, RenderTexture>;
constructor(size: number, totalLayers: number, geometry: IRoomGeometry) constructor(size: number, totalLayers: number, geometry: IRoomGeometry)
{ {
@ -21,6 +24,7 @@ export class PlaneVisualization
this._cachedBitmapNormal = new Vector3d(); this._cachedBitmapNormal = new Vector3d();
this._isCached = false; this._isCached = false;
this._hasAnimationLayers = false; this._hasAnimationLayers = false;
this._texturePool = new Map();
if(totalLayers < 0) totalLayers = 0; if(totalLayers < 0) totalLayers = 0;
@ -98,6 +102,13 @@ export class PlaneVisualization
} }
} }
if(this._texturePool && this._texturePool.size)
{
this._texturePool.forEach(texture => texture.destroy(true));
this._texturePool.clear();
}
this._isCached = false; this._isCached = false;
} }
@ -137,7 +148,7 @@ export class PlaneVisualization
return this._layers as PlaneVisualizationLayer[]; return this._layers as PlaneVisualizationLayer[];
} }
public render(canvas: Graphics, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number = 0, offsetY: number = 0, maxX: number = 0, maxY: number = 0, dimensionX: number = 0, dimensionY: number = 0, timeSinceStartMs: number = 0): Graphics public render(planeId: string, canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number = 0, offsetY: number = 0, maxX: number = 0, maxY: number = 0, dimensionX: number = 0, dimensionY: number = 0, timeSinceStartMs: number = 0): RenderTexture
{ {
if(width < 1) width = 1; if(width < 1) width = 1;
@ -147,26 +158,15 @@ export class PlaneVisualization
if(this._cachedBitmapData) if(this._cachedBitmapData)
{ {
if(((this._cachedBitmapData.width === width) && (this._cachedBitmapData.height === height)) && (Vector3d.isEqual(this._cachedBitmapNormal, normal))) if((this._cachedBitmapData.width === width) && (this._cachedBitmapData.height === height) && (Vector3d.isEqual(this._cachedBitmapNormal, normal)))
{ {
if(!this.hasAnimationLayers) if(!this.hasAnimationLayers)
{ {
if(canvas) if(canvas)
{ {
canvas.addChild(this._cachedBitmapData); TextureUtils.writeToRenderTexture(new Sprite(this._cachedBitmapData), canvas, true);
return canvas; return canvas;
// const texture = TextureUtils.generateTexture(this._cachedBitmapData, new Rectangle(0, 0, width, height));
// if(texture)
// {
// canvas
// .beginTextureFill({ texture })
// .drawRect(0, 0, texture.width, texture.height)
// .endFill();
// return canvas;
// }
} }
return this._cachedBitmapData; return this._cachedBitmapData;
@ -174,8 +174,6 @@ export class PlaneVisualization
} }
else else
{ {
this._cachedBitmapData.destroy();
this._cachedBitmapData = null; this._cachedBitmapData = null;
} }
} }
@ -184,17 +182,37 @@ export class PlaneVisualization
if(!this._cachedBitmapData) if(!this._cachedBitmapData)
{ {
this._cachedBitmapData = new Graphics() let cache = this._texturePool.get(planeId);
.beginFill(0xFFFFFF) let swapCache = this._texturePool.get(planeId + '-swap');
.drawRect(0, 0, width, height)
.endFill(); if(!swapCache)
{
swapCache = RoomTextureUtils.createAndFillRenderTexture(width, height);
this._texturePool.set(planeId + '-swap', swapCache);
}
else
{
if(cache)
{
[ cache, swapCache ] = [ swapCache, cache ];
}
}
if(!cache)
{
cache = RoomTextureUtils.createAndFillRenderTexture(width, height);
this._texturePool.set(planeId, cache);
}
this._cachedBitmapData = swapCache;
TextureUtils.clearAndFillRenderTexture(this._cachedBitmapData);
} }
else else
{ {
this._cachedBitmapData TextureUtils.clearAndFillRenderTexture(this._cachedBitmapData);
.beginFill(0xFFFFFF)
.drawRect(0, 0, width, height)
.endFill();
} }
if(!canvas) canvas = this._cachedBitmapData; if(!canvas) canvas = this._cachedBitmapData;
@ -221,13 +239,7 @@ export class PlaneVisualization
if(canvas && (canvas !== this._cachedBitmapData)) if(canvas && (canvas !== this._cachedBitmapData))
{ {
this._cachedBitmapData.addChild(canvas.clone()); TextureUtils.writeToRenderTexture(new Sprite(canvas), this._cachedBitmapData, false);
// const texture = TextureUtils.generateTexture(canvas, new Rectangle(0, 0, canvas.width, canvas.height));
// this._cachedBitmapData
// .beginTextureFill({ texture })
// .drawRect(0, 0, canvas.width, canvas.height)
// .endFill();
return canvas; return canvas;
} }

View File

@ -1,8 +1,7 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
import { Rectangle } from '@pixi/math'; import { Sprite } from '@pixi/sprite';
import { IVector3D } from '../../../../../../../api'; import { IVector3D } from '../../../../../../../api';
import { TextureUtils } from '../../../../../../../pixi-proxy'; import { RoomTextureUtils, TextureUtils } from '../../../../../../../pixi-proxy';
import { RoomVisualization } from '../../RoomVisualization';
import { PlaneMaterial } from './PlaneMaterial'; import { PlaneMaterial } from './PlaneMaterial';
export class PlaneVisualizationLayer export class PlaneVisualizationLayer
@ -16,7 +15,7 @@ export class PlaneVisualizationLayer
private _color: number; private _color: number;
private _offset: number; private _offset: number;
private _align: number; private _align: number;
private _bitmapData: Graphics; private _bitmapData: RenderTexture;
private _isDisposed: boolean; private _isDisposed: boolean;
constructor(material: PlaneMaterial, color: number, align: number, offset: number = 0) constructor(material: PlaneMaterial, color: number, align: number, offset: number = 0)
@ -56,30 +55,49 @@ export class PlaneVisualizationLayer
{ {
if(this._bitmapData) if(this._bitmapData)
{ {
this._bitmapData.destroy(); this._bitmapData.destroy(true);
this._bitmapData = null; this._bitmapData = null;
} }
} }
public render(canvas: Graphics, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number): Graphics public render(canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number): RenderTexture
{ {
if(!canvas || (canvas.width !== width) || (canvas.height !== height)) canvas = null; if(!canvas || (canvas.width !== width) || (canvas.height !== height)) canvas = null;
let bitmapData: Graphics = null; const r = (this._color >> 16);
const g = ((this._color >> 8) & 0xFF);
const b = (this._color & 0xFF);
let hasColor = false;
if(((r < 0xFF) || (g < 0xFF))|| (b < 0xFF)) hasColor = true;
let bitmapData: RenderTexture = null;
if(this._material) if(this._material)
{ {
bitmapData = this._material.render(null, width, height, normal, useTexture, offsetX, (offsetY + this.offset), (this.align === PlaneVisualizationLayer.ALIGN_TOP)); bitmapData = this._material.render(hasColor ? null : canvas, width, height, normal, useTexture, offsetX, (offsetY + this.offset), (this.align === PlaneVisualizationLayer.ALIGN_TOP));
if(bitmapData && (bitmapData !== canvas)) if(bitmapData && (bitmapData !== canvas))
{ {
if(this._bitmapData) this._bitmapData.destroy(); if(this._bitmapData) this._bitmapData.destroy();
this._bitmapData = bitmapData.clone(); this._bitmapData = new RenderTexture(bitmapData.baseTexture);
bitmapData = this._bitmapData; bitmapData = this._bitmapData;
} }
if(bitmapData && hasColor)
{
const sprite = new Sprite(bitmapData);
sprite.tint = this._color;
TextureUtils.writeToRenderTexture(sprite, canvas, false);
bitmapData = canvas;
}
} }
else else
{ {
@ -89,45 +107,13 @@ export class PlaneVisualizationLayer
if(this._bitmapData) this._bitmapData.destroy(); if(this._bitmapData) this._bitmapData.destroy();
const graphic = new Graphics() this._bitmapData = RoomTextureUtils.createAndFillRenderTexture(width, height, this._color);
.beginFill(0xFFFFFF)
.drawRect(0, 0, width, height)
.endFill();
this._bitmapData = graphic;
bitmapData = this._bitmapData; bitmapData = this._bitmapData;
} }
else else
{ {
canvas TextureUtils.clearAndFillRenderTexture(canvas, this._color);
.beginFill(0xFFFFFF)
.drawRect(0, 0, width, height)
.endFill();
bitmapData = canvas;
}
}
if(bitmapData)
{
bitmapData.tint = this._color;
if(canvas && (bitmapData !== canvas))
{
let texture = RoomVisualization.getTextureCache(bitmapData);
if(!texture)
{
texture = TextureUtils.generateTexture(bitmapData, new Rectangle(0, 0, width, height));
RoomVisualization.addTextureCache(bitmapData, texture);
}
canvas
.beginTextureFill({ texture })
.drawRect(0, 0, width, height)
.endFill();
bitmapData = canvas; bitmapData = canvas;
} }

View File

@ -1,4 +1,4 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
import { IVector3D, Vector3d } from '../../../../../../../api'; import { IVector3D, Vector3d } from '../../../../../../../api';
import { Plane } from './Plane'; import { Plane } from './Plane';
@ -8,7 +8,7 @@ export class WallPlane extends Plane
public static HORIZONTAL_ANGLE_DEFAULT: number = 45; public static HORIZONTAL_ANGLE_DEFAULT: number = 45;
public static VERTICAL_ANGLE_DEFAULT: number = 30; public static VERTICAL_ANGLE_DEFAULT: number = 30;
public render(canvas: Graphics, width: number, height: number, size: number, normal: IVector3D, useTexture: boolean): Graphics public render(planeId: string, canvas: RenderTexture, width: number, height: number, size: number, normal: IVector3D, useTexture: boolean): RenderTexture
{ {
const visualization = this.getPlaneVisualization(size); const visualization = this.getPlaneVisualization(size);
@ -24,6 +24,6 @@ export class WallPlane extends Plane
height = Math.round(Math.abs((_local_8.y - _local_9.y))); height = Math.round(Math.abs((_local_8.y - _local_9.y)));
} }
return visualization.render(canvas, width, height, normal, useTexture); return visualization.render(planeId, canvas, width, height, normal, useTexture);
} }
} }

View File

@ -1,5 +1,6 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
import { IVector3D } from '../../../../../../../api'; import { IAssetPlane, IVector3D } from '../../../../../../../api';
import { TextureUtils } from '../../../../../../../pixi-proxy';
import { PlaneBitmapData } from '../../utils'; import { PlaneBitmapData } from '../../utils';
import { PlaneRasterizer } from './PlaneRasterizer'; import { PlaneRasterizer } from './PlaneRasterizer';
import { WallPlane } from './WallPlane'; import { WallPlane } from './WallPlane';
@ -10,12 +11,12 @@ export class WallRasterizer extends PlaneRasterizer
{ {
if(!this.data) return; if(!this.data) return;
const walls = this.data.walls; const walls = this.data.planes;
if(walls && walls.length) this.parseWalls(walls); if(walls && walls.length) this.parseWalls(walls);
} }
private parseWalls(k: any): void private parseWalls(k: IAssetPlane[]): void
{ {
if(!k) return; if(!k) return;
@ -35,7 +36,7 @@ export class WallRasterizer extends PlaneRasterizer
} }
} }
public render(canvas: Graphics, id: string, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number = 0, offsetY: number = 0, maxX: number = 0, maxY: number = 0, timeSinceStartMs: number = 0): PlaneBitmapData public render(planeId: string, canvas: RenderTexture, id: string, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number = 0, offsetY: number = 0, maxX: number = 0, maxY: number = 0, timeSinceStartMs: number = 0): PlaneBitmapData
{ {
let plane = this.getPlane(id) as WallPlane; let plane = this.getPlane(id) as WallPlane;
@ -43,20 +44,13 @@ export class WallRasterizer extends PlaneRasterizer
if(!plane) return null; if(!plane) return null;
if(canvas) if(canvas) TextureUtils.clearAndFillRenderTexture(canvas);
{
const rectangle = canvas.getBounds();
canvas.clear(); let graphic = plane.render(planeId, canvas, width, height, scale, normal, useTexture);
canvas.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
}
let graphic = plane.render(canvas, width, height, scale, normal, useTexture);
if(graphic && (graphic !== canvas)) if(graphic && (graphic !== canvas))
{ {
graphic = graphic.clone(); graphic = new RenderTexture(graphic.baseTexture);
if(!graphic) return null; if(!graphic) return null;
} }

View File

@ -1,24 +1,24 @@
import { Graphics } from '@pixi/graphics'; import { RenderTexture } from '@pixi/core';
export class PlaneBitmapData export class PlaneBitmapData
{ {
private _bitmap: Graphics; private _texture: RenderTexture;
private _timeStamp: number; private _timeStamp: number;
constructor(k: Graphics, _arg_2: number) constructor(texture: RenderTexture, timestamp: number)
{ {
this._bitmap = k; this._texture = texture;
this._timeStamp = _arg_2; this._timeStamp = timestamp;
} }
public dispose(): void public dispose(): void
{ {
this._bitmap = null; this._texture = null;
} }
public get bitmap(): Graphics public get texture(): RenderTexture
{ {
return this._bitmap; return this._texture;
} }
public get timeStamp(): number public get timeStamp(): number

View File

@ -1,4 +1,6 @@
export class Randomizer import { ToInt32 } from '../../../../../utils';
export class Randomizer
{ {
public static DEFAULT_SEED: number = 1; public static DEFAULT_SEED: number = 1;
public static DEFAULT_MODULUS: number = 16777216; public static DEFAULT_MODULUS: number = 16777216;
@ -102,7 +104,7 @@
private iterate(): number private iterate(): number
{ {
let k: number = ((this._multiplier * this._seed) + this._increment); let k: number = ToInt32(Math.trunc(this._multiplier * this._seed) + this._increment);
if(k < 0) k = -(k); if(k < 0) k = -(k);
@ -119,7 +121,7 @@
if(_arg_2 < 1) return k; if(_arg_2 < 1) return k;
_local_3 = (k + ((_local_3 / this._modulus) * _arg_2)); _local_3 = Math.trunc(k + ((_local_3 / this._modulus) * _arg_2));
return _local_3; return _local_3;
} }

13
src/nitro/utils/Int32.ts Normal file
View File

@ -0,0 +1,13 @@
const toUint32 = (x: number) => x >>> 0;
export const ToInt32 = (x: number) =>
{
const uint32 = toUint32(x);
if(uint32 >= Math.pow(2, 31))
{
return uint32 - Math.pow(2, 32);
}
return uint32;
};

View File

@ -1,8 +0,0 @@
import { isWebGLSupported } from '@pixi/utils';
export class WebGL
{
public static isWebGLAvailable(): boolean
{
return isWebGLSupported();
}
}

View File

@ -3,4 +3,4 @@ export * from './FixedSizeStack';
export * from './FriendlyTime'; export * from './FriendlyTime';
export * from './FurniId'; export * from './FurniId';
export * from './HabboWebTools'; export * from './HabboWebTools';
export * from './WebGL'; export * from './Int32';

View File

@ -0,0 +1,49 @@
import { Filter, RenderTexture } from '@pixi/core';
const vertex = `
attribute vec2 aVertexPosition;
attribute vec2 aTextureCoord;
uniform mat3 projectionMatrix;
varying vec2 vTextureCoord;
void main(void)
{
gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);
vTextureCoord = aTextureCoord;
}`;
const fragment = `
varying vec2 vTextureCoord;
uniform sampler2D uSampler;
uniform sampler2D mask;
uniform int fromChannel;
uniform int toChannel;
void main(void) {
vec4 maskColor = texture2D(mask, vTextureCoord);
vec4 currentColor = texture2D(uSampler, vTextureCoord);
vec4 adjusted = currentColor;
if(maskColor.r == 0.0 && maskColor.g == 0.0 && maskColor.b == 0.0)
{
adjusted.a = 0.0;
}
gl_FragColor = vec4(adjusted.r, adjusted.g, adjusted.b, adjusted.a);
}`;
export class CopyChannelFilter extends Filter
{
public static readonly CHANNEL_RED = 0;
public static readonly CHANNEL_GREEN = 1;
public static readonly CHANNEL_BLUE = 2;
public static readonly CHANNEL_ALPHA = 3;
constructor(mask: RenderTexture, fromChannel: number, toChannel: number)
{
super(vertex, fragment, {
mask: mask.castToBaseTexture(),
fromChannel,
toChannel
});
}
}

View File

@ -1,4 +0,0 @@
import { AdjustmentFilter } from '@pixi/filter-adjustment';
export class NitroAdjustmentFilter extends AdjustmentFilter
{}

View File

@ -0,0 +1,99 @@
import { AbstractRenderer, Renderer, RenderTexture, Texture } from '@pixi/core';
import { DisplayObject } from '@pixi/display';
import { Extract } from '@pixi/extract';
import { Matrix, Rectangle } from '@pixi/math';
import { Sprite } from '@pixi/sprite';
import { PixiApplicationProxy } from './PixiApplicationProxy';
export class RoomTextureUtils
{
public static RENDER_TEXTURE_CACHE: RenderTexture[] = [];
public static clearCache(): void
{
this.RENDER_TEXTURE_CACHE.forEach(renderTexture => renderTexture?.destroy(true));
this.RENDER_TEXTURE_CACHE = [];
}
public static clearRenderTexture(renderTexture: RenderTexture): RenderTexture
{
if(!renderTexture) return null;
return this.writeToRenderTexture(new Sprite(Texture.EMPTY), renderTexture);
}
public static createRenderTexture(width: number, height: number): RenderTexture
{
if((width < 0) || (height < 0)) return null;
const renderTexture = RenderTexture.create({
width,
height
});
this.RENDER_TEXTURE_CACHE.push(renderTexture);
return renderTexture;
}
public static createAndFillRenderTexture(width: number, height: number, color: number = 16777215): RenderTexture
{
if((width < 0) || (height < 0)) return null;
const renderTexture = this.createRenderTexture(width, height);
return this.clearAndFillRenderTexture(renderTexture, color);
}
public static createAndWriteRenderTexture(width: number, height: number, displayObject: DisplayObject, transform: Matrix = null): RenderTexture
{
if((width < 0) || (height < 0)) return null;
const renderTexture = this.createRenderTexture(width, height);
return this.writeToRenderTexture(displayObject, renderTexture, true, transform);
}
public static clearAndFillRenderTexture(renderTexture: RenderTexture, color: number = 16777215): RenderTexture
{
if(!renderTexture) return null;
const sprite = new Sprite(Texture.WHITE);
sprite.tint = color;
sprite.width = renderTexture.width;
sprite.height = renderTexture.height;
return this.writeToRenderTexture(sprite, renderTexture);
}
public static writeToRenderTexture(displayObject: DisplayObject, renderTexture: RenderTexture, clear: boolean = true, transform: Matrix = null): RenderTexture
{
if(!displayObject || !renderTexture) return null;
this.getRenderer().render(displayObject, {
renderTexture,
clear,
transform
});
return renderTexture;
}
public static getPixels(displayObject: DisplayObject | RenderTexture, frame: Rectangle = null): Uint8Array
{
return this.getExtractor().pixels(displayObject);
}
public static getRenderer(): Renderer | AbstractRenderer
{
return PixiApplicationProxy.instance.renderer;
}
public static getExtractor(): Extract
{
return (this.getRenderer().plugins.extract as Extract);
}
}

View File

@ -1,16 +1,19 @@
import { SCALE_MODES } from '@pixi/constants';
import { AbstractRenderer, Renderer, RenderTexture, Resource, Texture } from '@pixi/core'; import { AbstractRenderer, Renderer, RenderTexture, Resource, Texture } from '@pixi/core';
import { DisplayObject } from '@pixi/display'; import { DisplayObject } from '@pixi/display';
import { Extract } from '@pixi/extract'; import { Extract } from '@pixi/extract';
import { Rectangle } from '@pixi/math'; import { Matrix, Rectangle } from '@pixi/math';
import { settings } from '@pixi/settings';
import { Sprite } from '@pixi/sprite';
import { PixiApplicationProxy } from './PixiApplicationProxy'; import { PixiApplicationProxy } from './PixiApplicationProxy';
export class TextureUtils export class TextureUtils
{ {
public static generateTexture(displayObject: DisplayObject, region: Rectangle = null, scaleMode: number = SCALE_MODES.NEAREST, resolution: number = 1): RenderTexture public static generateTexture(displayObject: DisplayObject, region: Rectangle = null, scaleMode: number = null, resolution: number = 1): RenderTexture
{ {
if(!displayObject) return null; if(!displayObject) return null;
if(scaleMode === null) scaleMode = settings.SCALE_MODE;
return this.getRenderer().generateTexture(displayObject, { return this.getRenderer().generateTexture(displayObject, {
scaleMode, scaleMode,
resolution, resolution,
@ -46,6 +49,73 @@ export class TextureUtils
return this.getExtractor().canvas(target); return this.getExtractor().canvas(target);
} }
public static clearRenderTexture(renderTexture: RenderTexture): RenderTexture
{
if(!renderTexture) return null;
return this.writeToRenderTexture(new Sprite(Texture.EMPTY), renderTexture);
}
public static createRenderTexture(width: number, height: number): RenderTexture
{
if((width < 0) || (height < 0)) return null;
return RenderTexture.create({
width,
height
});
}
public static createAndFillRenderTexture(width: number, height: number, color: number = 16777215): RenderTexture
{
if((width < 0) || (height < 0)) return null;
const renderTexture = this.createRenderTexture(width, height);
return this.clearAndFillRenderTexture(renderTexture, color);
}
public static createAndWriteRenderTexture(width: number, height: number, displayObject: DisplayObject, transform: Matrix = null): RenderTexture
{
if((width < 0) || (height < 0)) return null;
const renderTexture = this.createRenderTexture(width, height);
return this.writeToRenderTexture(displayObject, renderTexture, true, transform);
}
public static clearAndFillRenderTexture(renderTexture: RenderTexture, color: number = 16777215): RenderTexture
{
if(!renderTexture) return null;
const sprite = new Sprite(Texture.WHITE);
sprite.tint = color;
sprite.width = renderTexture.width;
sprite.height = renderTexture.height;
return this.writeToRenderTexture(sprite, renderTexture);
}
public static writeToRenderTexture(displayObject: DisplayObject, renderTexture: RenderTexture, clear: boolean = true, transform: Matrix = null): RenderTexture
{
if(!displayObject || !renderTexture) return null;
this.getRenderer().render(displayObject, {
renderTexture,
clear,
transform
});
return renderTexture;
}
public static getPixels(displayObject: DisplayObject | RenderTexture, frame: Rectangle = null): Uint8Array
{
return this.getExtractor().pixels(displayObject);
}
public static getRenderer(): Renderer | AbstractRenderer public static getRenderer(): Renderer | AbstractRenderer
{ {
return PixiApplicationProxy.instance.renderer; return PixiApplicationProxy.instance.renderer;

View File

@ -0,0 +1,120 @@
import { CLEAR_MODES } from '@pixi/constants';
import { Filter, FilterSystem, RenderTexture } from '@pixi/core';
interface AdjustmentFilterOptions
{
gamma: number;
saturation: number;
contrast: number;
brightness: number;
red: number;
green: number;
blue: number;
alpha: number;
}
export class AdjustmentFilter extends Filter
{
/** The amount of luminance */
public gamma = 1;
/** The amount of saturation */
public saturation = 1;
/** The amount of contrast */
public contrast = 1;
/** The amount of brightness */
public brightness = 1;
/** The amount of red channel */
public red = 1;
/** The amount of green channel */
public green = 1;
/** The amount of blue channel */
public blue = 1;
/** The amount of alpha channel */
public alpha = 1;
/**
* @param {object|number} [options] - The optional parameters of the filter.
* @param {number} [options.gamma=1] - The amount of luminance
* @param {number} [options.saturation=1] - The amount of color saturation
* @param {number} [options.contrast=1] - The amount of contrast
* @param {number} [options.brightness=1] - The overall brightness
* @param {number} [options.red=1] - The multipled red channel
* @param {number} [options.green=1] - The multipled green channel
* @param {number} [options.blue=1] - The multipled blue channel
* @param {number} [options.alpha=1] - The overall alpha amount
*/
constructor(options?: Partial<AdjustmentFilterOptions>)
{
super(
`attribute vec2 aVertexPosition;
attribute vec2 aTextureCoord;
uniform mat3 projectionMatrix;
varying vec2 vTextureCoord;
void main(void)
{
gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);
vTextureCoord = aTextureCoord;
}`,
`varying vec2 vTextureCoord;
uniform sampler2D uSampler;
uniform float gamma;
uniform float contrast;
uniform float saturation;
uniform float brightness;
uniform float red;
uniform float green;
uniform float blue;
uniform float alpha;
void main(void)
{
vec4 c = texture2D(uSampler, vTextureCoord);
if (c.a > 0.0) {
c.rgb /= c.a;
vec3 rgb = pow(c.rgb, vec3(1. / gamma));
rgb = mix(vec3(.5), mix(vec3(dot(vec3(.2125, .7154, .0721), rgb)), rgb, saturation), contrast);
rgb.r *= red;
rgb.g *= green;
rgb.b *= blue;
c.rgb = rgb * brightness;
c.rgb *= c.a;
}
gl_FragColor = c * alpha;
}`);
Object.assign(this, options);
}
/**
* Override existing apply method in PIXI.Filter
* @ignore
*/
apply(filterManager: FilterSystem, input: RenderTexture, output: RenderTexture, clear: CLEAR_MODES): void
{
this.uniforms.gamma = Math.max(this.gamma, 0.0001);
this.uniforms.saturation = this.saturation;
this.uniforms.contrast = this.contrast;
this.uniforms.brightness = this.brightness;
this.uniforms.red = this.red;
this.uniforms.green = this.green;
this.uniforms.blue = this.blue;
this.uniforms.alpha = this.alpha;
filterManager.applyFilter(this, input, output, clear);
}
}

View File

@ -0,0 +1 @@
export * from './AdjustmentFilter';

View File

@ -1,8 +1,10 @@
export { POINT_STRUCT_SIZE } from '@pixi/tilemap';
export * from './adjustment-filter';
export * from './CopyChannelFilter';
export * from './GetTicker'; export * from './GetTicker';
export * from './GetTickerFPS'; export * from './GetTickerFPS';
export * from './GetTickerTime'; export * from './GetTickerTime';
export * from './INitroPoint'; export * from './INitroPoint';
export * from './NitroAdjustmentFilter';
export * from './NitroAlphaFilter'; export * from './NitroAlphaFilter';
export * from './NitroBaseTexture'; export * from './NitroBaseTexture';
export * from './NitroContainer'; export * from './NitroContainer';
@ -14,8 +16,9 @@ export * from './NitroRenderTexture';
export * from './NitroSprite'; export * from './NitroSprite';
export * from './NitroSpritesheet'; export * from './NitroSpritesheet';
export * from './NitroTexture'; export * from './NitroTexture';
export * from './NitroTilemap';
export * from './PaletteMapFilter'; export * from './PaletteMapFilter';
export * from './PixiApplicationProxy'; export * from './PixiApplicationProxy';
export * from './PixiInteractionEventProxy'; export * from './PixiInteractionEventProxy';
export * from './RoomTextureUtils';
export * from './TextureUtils'; export * from './TextureUtils';
export * from './tilemap';

View File

@ -1,2 +0,0 @@
export { POINT_STRUCT_SIZE } from '@pixi/tilemap';
export * from './NitroTilemap';

View File

@ -73,7 +73,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
this._container = container; this._container = container;
this._geometry = new RoomGeometry(scale, new Vector3d(-135, 30, 0), new Vector3d(11, 11, 5), new Vector3d(-135, 0.5, 0)); this._geometry = new RoomGeometry(scale, new Vector3d(-135, 30, 0), new Vector3d(11, 11, 5), new Vector3d(-135, 0.5, 0));
this._animationFPS = Nitro.instance.getConfiguration<number>('system.animation.fps', 24); this._animationFPS = Nitro.instance.getConfiguration<number>('system.fps.animation', 24);
this._renderTimestamp = 0; this._renderTimestamp = 0;
this._totalTimeRunning = 0; this._totalTimeRunning = 0;
this._lastFrame = 0; this._lastFrame = 0;

View File

@ -1,8 +1,9 @@
import { BLEND_MODES } from '@pixi/constants'; import { BLEND_MODES } from '@pixi/constants';
import { BaseTexture, RenderTexture, Resource, Texture } from '@pixi/core'; import { BaseTexture, Resource, Texture } from '@pixi/core';
import { Point } from '@pixi/math'; import { Point } from '@pixi/math';
import { Sprite } from '@pixi/sprite'; import { Sprite } from '@pixi/sprite';
import { NitroSprite, TextureUtils } from '../../../pixi-proxy'; import { AlphaTolerance } from '../../../api';
import { TextureUtils } from '../../../pixi-proxy';
export class ExtendedSprite extends Sprite export class ExtendedSprite extends Sprite
{ {
@ -16,8 +17,6 @@ export class ExtendedSprite extends Sprite
private _pairedSpriteId: number; private _pairedSpriteId: number;
private _pairedSpriteUpdateCounter: number; private _pairedSpriteUpdateCounter: number;
public name: string;
constructor(texture: Texture<Resource> = null) constructor(texture: Texture<Resource> = null)
{ {
super(texture); super(texture);
@ -91,26 +90,7 @@ export class ExtendedSprite extends Sprite
//@ts-ignore //@ts-ignore
if(!baseTexture.hitMap) if(!baseTexture.hitMap)
{ {
let canvas: HTMLCanvasElement = null; if(!ExtendedSprite.generateHitMap(baseTexture)) return false;
if(!baseTexture.resource)
{
//@ts-ignore
if(!texture.getLocalBounds)
{
const tempSprite = new NitroSprite(texture);
canvas = TextureUtils.generateCanvas(tempSprite);
tempSprite.destroy();
}
else
{
canvas = TextureUtils.generateCanvas(texture as RenderTexture);
}
}
if(!ExtendedSprite.generateHitMap(baseTexture, canvas)) return false;
} }
//@ts-ignore //@ts-ignore
@ -135,65 +115,32 @@ export class ExtendedSprite extends Sprite
return (hitMap[ind2] & (1 << ind1)) !== 0; return (hitMap[ind2] & (1 << ind1)) !== 0;
} }
private static generateHitMap(baseTexture: BaseTexture, tempCanvas: HTMLCanvasElement = null): boolean private static generateHitMap(baseTexture: BaseTexture): boolean
{ {
let canvas: HTMLCanvasElement = null; if(!baseTexture) return false;
let context: CanvasRenderingContext2D = null;
if(tempCanvas)
{
canvas = tempCanvas;
context = canvas.getContext('2d');
}
else
{
if(!baseTexture.resource) return false;
//@ts-ignore
const source = baseTexture.resource.source as HTMLCanvasElement;
if(!source) return false;
if(source.getContext)
{
canvas = source;
context = canvas.getContext('2d');
}
else if(source instanceof Image)
{
canvas = document.createElement('canvas');
canvas.width = source.width;
canvas.height = source.height;
context = canvas.getContext('2d');
context.drawImage(source, 0, 0);
}
else return false;
}
const width = canvas.width;
const height = canvas.height;
const imageData = context.getImageData(0, 0, width, height);
const texture = new Texture(baseTexture);
const sprite = new Sprite(texture);
const pixels = TextureUtils.getPixels(sprite);
const width = baseTexture.width;
const height = baseTexture.height;
const hitmap = new Uint32Array(Math.ceil(width * height / 32)); const hitmap = new Uint32Array(Math.ceil(width * height / 32));
const threshold = 128; const threshold = AlphaTolerance.MATCH_OPAQUE_PIXELS;
for(let i = 0; i < width * height; i++) for(let i = 0; i < width * height; i++)
{ {
const ind1 = i % 32; const ind1 = i % 32;
const ind2 = i / 32 | 0; const ind2 = i / 32 | 0;
if(imageData.data[i * 4 + 3] >= threshold) if(pixels[i * 4 + 3] >= threshold) hitmap[ind2] = hitmap[ind2] | (1 << ind1);
{
hitmap[ind2] = hitmap[ind2] | (1 << ind1);
}
} }
//@ts-ignore //@ts-ignore
baseTexture.hitMap = hitmap; baseTexture.hitMap = hitmap;
sprite.destroy();
texture.destroy();
return true; return true;
} }

View File

@ -335,4 +335,19 @@ export class ColorConverter
{ {
return ColorConverter.xyz2CieLab(ColorConverter.rgb2xyz(k)); return ColorConverter.xyz2CieLab(ColorConverter.rgb2xyz(k));
} }
public static colorize(colorA: number, colorB: number): number
{
if(colorB === 0xFFFFFFFF) return colorA;
let r = ((colorB >> 16) & 0xFF);
let g = ((colorB >> 8) & 0xFF);
let b = (colorB & 0xFF);
r = ((((colorA >> 16) & 0xFF) * r) / 0xFF);
g = ((((colorA >> 8) & 0xFF) * g) / 0xFF);
b = (((colorA & 0xFF) * b) / 0xFF);
return ((colorA && 0xFF000000) | (r << 16) | (g << 8) | b);
}
} }

View File

@ -1,7 +1,8 @@
import { Resource, Texture } from '@pixi/core'; import { Resource, Texture } from '@pixi/core';
import { Graphics } from '@pixi/graphics'; import { Graphics } from '@pixi/graphics';
import { Matrix } from '@pixi/math'; import { Matrix } from '@pixi/math';
import { TextureUtils } from '../../pixi-proxy'; import { Sprite } from '@pixi/sprite';
import { PixiApplicationProxy, TextureUtils } from '../../pixi-proxy';
export class Rasterizer export class Rasterizer
{ {
@ -67,22 +68,20 @@ export class Rasterizer
{ {
if(!k) return null; if(!k) return null;
const renderTexture = TextureUtils.createRenderTexture(k.width, k.height);
const matrix = new Matrix(); const matrix = new Matrix();
matrix.scale(-1, 1); matrix.scale(-1, 1);
matrix.translate(k.width, 0); matrix.translate(k.width, 0);
const graphic = new Graphics(); PixiApplicationProxy.instance.renderer.render(new Sprite(k), {
renderTexture,
clear: true,
transform: matrix
});
graphic return renderTexture;
.beginTextureFill({
texture: k,
matrix
})
.drawRect(0, 0, k.width, k.height)
.endFill();
return TextureUtils.generateTexture(graphic);
} }
public static getFlipVBitmapData(k: Texture<Resource>): Texture<Resource> public static getFlipVBitmapData(k: Texture<Resource>): Texture<Resource>

View File

@ -6,7 +6,7 @@
"sourceMap": false, "sourceMap": false,
"declaration": true, "declaration": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"moduleResolution": "node", "moduleResolution": "Node",
"esModuleInterop": true, "esModuleInterop": true,
"importHelpers": true, "importHelpers": true,
"isolatedModules": true, "isolatedModules": true,
@ -16,13 +16,13 @@
"allowJs": true, "allowJs": true,
"skipLibCheck": true, "skipLibCheck": true,
"noEmit": true, "noEmit": true,
"target": "es5", "target": "ES6",
"lib": [ "lib": [
"dom", "DOM",
"dom.iterable", "DOM.Iterable",
"esnext" "ESNext"
], ],
"module": "esnext", "module": "ES6",
"paths": { "paths": {
"mini-signals": [ "mini-signals": [
"node_modules/mini-signals/index.js" "node_modules/mini-signals/index.js"

36
vite.config.js Normal file
View File

@ -0,0 +1,36 @@
// vite.config.js
import typescript from '@rollup/plugin-typescript';
import { resolve } from 'path';
import { defineConfig } from 'vite';
import { ViteMinifyPlugin } from 'vite-plugin-minify';
const resolvePath = str => resolve(__dirname, str);
export default defineConfig({
plugins: [
typescript({
'target': 'es6',
'rootDir': resolvePath('./src'),
'declaration': true,
exclude: resolvePath('./node_modules/**'),
allowSyntheticDefaultImports: true
}),
ViteMinifyPlugin()
],
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'nitro-renderer',
fileName: 'nitro-renderer'
}
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
'~': resolve(__dirname, 'node_modules')
}
},
server: {
host: '127.0.0.1'
}
});

1235
yarn.lock

File diff suppressed because it is too large Load Diff