diff --git a/src/nitro/room/object/visualization/room/RoomPlane.ts b/src/nitro/room/object/visualization/room/RoomPlane.ts index 9656954a..04659f03 100644 --- a/src/nitro/room/object/visualization/room/RoomPlane.ts +++ b/src/nitro/room/object/visualization/room/RoomPlane.ts @@ -2,7 +2,7 @@ import { Renderer, RenderTexture, Resource, Texture } from '@pixi/core'; import { Matrix, Point } from '@pixi/math'; import { Sprite } from '@pixi/sprite'; import { IRoomGeometry, IRoomPlane, IVector3D, Vector3d } from '../../../../../api'; -import { PixiApplicationProxy, RoomTextureUtils, TextureUtils } from '../../../../../pixi-proxy'; +import { PixiApplicationProxy, RoomTextureCache } from '../../../../../pixi-proxy'; import { ColorConverter } from '../../../../../room'; import { PlaneMaskManager } from './mask'; import { PlaneDrawingData } from './PlaneDrawingData'; @@ -20,6 +20,7 @@ export class RoomPlane implements IRoomPlane public static TYPE_LANDSCAPE: number = 3; private static _uniqueIdCounter: number = 1; + private _textureCache: RoomTextureCache; private _disposed: boolean; private _randomSeed: number; private _origin: Vector3d; @@ -62,8 +63,9 @@ export class RoomPlane implements IRoomPlane private _height: number = 0; private _canBeVisible: boolean; - constructor(origin: IVector3D, location: IVector3D, leftSide: IVector3D, rightSide: IVector3D, type: number, usesMask: boolean, secondaryNormals: IVector3D[], randomSeed: number, textureOffsetX: number = 0, textureOffsetY: number = 0, textureMaxX: number = 0, textureMaxY: number = 0) + constructor(textureCache: RoomTextureCache, origin: IVector3D, location: IVector3D, leftSide: IVector3D, rightSide: IVector3D, type: number, usesMask: boolean, secondaryNormals: IVector3D[], randomSeed: number, textureOffsetX: number = 0, textureOffsetY: number = 0, textureMaxX: number = 0, textureMaxY: number = 0) { + this._textureCache = textureCache; this._secondaryNormals = []; this._bitmapMasks = []; this._rectangleMasks = []; @@ -390,13 +392,13 @@ export class RoomPlane implements IRoomPlane if(this._rasterizer) { - 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); + bitmapData = this._rasterizer.render(this._uniqueId.toString(), this._textureCache, texture, this._id, width, height, geometry.scale, normal, this._hasTexture, this._textureOffsetX, this._textureOffsetY, this._textureMaxX, this._textureMaxY, timeSinceStartMs); if(bitmapData && texture && (bitmapData?.texture !== texture)) texture.destroy(true); } else { - const renderTexture = RoomTextureUtils.createAndFillRenderTexture(width, height); + const renderTexture = this._textureCache.createAndFillRenderTexture(width, height); bitmapData = new PlaneBitmapData(renderTexture, -1); } @@ -623,7 +625,7 @@ export class RoomPlane implements IRoomPlane if((this._width < 1) || (this._height < 1)) return true; - this._bitmapData = RoomTextureUtils.createAndFillRenderTexture(this._width, this._height); + this._bitmapData = this._textureCache.createAndFillRenderTexture(this._width, this._height); } else { @@ -636,21 +638,21 @@ export class RoomPlane implements IRoomPlane return true; } - TextureUtils.clearAndFillRenderTexture(this._bitmapData); + this._textureCache.clearAndFillRenderTexture(this._bitmapData); } } else { if((this._width < 1) || (this._height < 1)) return false; - this._bitmapData = RoomTextureUtils.createAndFillRenderTexture(this._width, this._height); + this._bitmapData = this._textureCache.createAndFillRenderTexture(this._width, this._height); } if(!this._bitmapData) return false; } else { - TextureUtils.clearAndFillRenderTexture(this._bitmapData); + this._textureCache.clearAndFillRenderTexture(this._bitmapData); } Randomizer.setSeed(this._randomSeed); @@ -758,7 +760,7 @@ export class RoomPlane implements IRoomPlane //k.baseTexture.mipmap = MIPMAP_MODES.OFF; //k.baseTexture.scaleMode = SCALE_MODES.LINEAR; - TextureUtils.writeToRenderTexture(new Sprite(k), this._bitmapData, true, matrix); + this._textureCache.writeToRenderTexture(new Sprite(k), this._bitmapData, true, matrix); } public resetBitmapMasks(): void @@ -881,7 +883,7 @@ export class RoomPlane implements IRoomPlane this._maskBitmapData = null; } - this._maskBitmapData = RoomTextureUtils.createAndFillRenderTexture(width, height); + this._maskBitmapData = this._textureCache.createAndFillRenderTexture(width, height); this._maskChanged = true; } @@ -890,7 +892,7 @@ export class RoomPlane implements IRoomPlane this._bitmapMasksOld = []; this._rectangleMasksOld = []; - if(this._maskBitmapData) TextureUtils.clearAndFillRenderTexture(this._maskBitmapData); + if(this._maskBitmapData) this._textureCache.clearAndFillRenderTexture(this._maskBitmapData); this.resetTextureCache(canvas); @@ -943,7 +945,7 @@ export class RoomPlane implements IRoomPlane i++; } - this._maskPixels = TextureUtils.getPixels(this._maskBitmapData); + this._maskPixels = this._textureCache.getPixels(this._maskBitmapData); this._maskChanged = false; } @@ -955,7 +957,7 @@ export class RoomPlane implements IRoomPlane { if(!canvas || !maskPixels) return; - const canvasPixels = TextureUtils.getPixels(canvas); + const canvasPixels = this._textureCache.getPixels(canvas); for(let i = 0; i < canvasPixels.length; i += 4) { diff --git a/src/nitro/room/object/visualization/room/RoomVisualization.ts b/src/nitro/room/object/visualization/room/RoomVisualization.ts index 992939a3..8a294267 100644 --- a/src/nitro/room/object/visualization/room/RoomVisualization.ts +++ b/src/nitro/room/object/visualization/room/RoomVisualization.ts @@ -1,6 +1,6 @@ import { Rectangle } from '@pixi/math'; import { AlphaTolerance, IObjectVisualizationData, IPlaneVisualization, IRoomGeometry, IRoomObjectModel, IRoomObjectSprite, IRoomPlane, RoomObjectSpriteType, RoomObjectVariable, Vector3d } from '../../../../../api'; -import { RoomTextureUtils } from '../../../../../pixi-proxy'; +import { RoomTextureCache } from '../../../../../pixi-proxy'; import { RoomObjectSpriteVisualization } from '../../../../../room'; import { ToInt32 } from '../../../../utils'; import { RoomMapData } from '../../RoomMapData'; @@ -57,6 +57,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements private _assetUpdateCounter: number; private _maskData: RoomMapMaskData; private _isPlaneSet: boolean; + private _textureCache: RoomTextureCache; constructor() { @@ -92,6 +93,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements this._assetUpdateCounter = 0; this._maskData = null; this._isPlaneSet = false; + this._textureCache = new RoomTextureCache(); this._typeVisibility[RoomPlane.TYPE_UNDEFINED] = false; this._typeVisibility[RoomPlane.TYPE_FLOOR] = true; @@ -143,7 +145,11 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements this._data = null; } - RoomTextureUtils.clearCache(); + if(this._textureCache) + { + console.log('clear it'); + this._textureCache.clearCache(); + } } protected reset(): void @@ -409,7 +415,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements const textureOffsetX = (Math.trunc(_local_15) - _local_15); const textureOffsetY = (Math.trunc(_local_16) - _local_16); - plane = new RoomPlane(this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_FLOOR, true, secondaryNormals, randomSeed, -(textureOffsetX), -(textureOffsetY)); + plane = new RoomPlane(this._textureCache, this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_FLOOR, true, secondaryNormals, randomSeed, -(textureOffsetX), -(textureOffsetY)); if(_local_14.z !== 0) { @@ -425,7 +431,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements else if(planeType === RoomPlaneData.PLANE_WALL) { - plane = new RoomPlane(this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_WALL, true, secondaryNormals, randomSeed); + plane = new RoomPlane(this._textureCache, this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_WALL, true, secondaryNormals, randomSeed); if((leftSide.length < 1) || (rightSide.length < 1)) { @@ -460,7 +466,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements else if(planeType === RoomPlaneData.PLANE_LANDSCAPE) { - plane = new RoomPlane(this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_LANDSCAPE, true, secondaryNormals, randomSeed, _local_5, 0, maxX, maxY); + plane = new RoomPlane(this._textureCache, this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_LANDSCAPE, true, secondaryNormals, randomSeed, _local_5, 0, maxX, maxY); if(_local_14.y > 0) { @@ -485,7 +491,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements else if(planeType == RoomPlaneData.PLANE_BILLBOARD) { - plane = new RoomPlane(this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_WALL, true, secondaryNormals, randomSeed); + plane = new RoomPlane(this._textureCache, this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_WALL, true, secondaryNormals, randomSeed); if(((leftSide.length < 1) || (rightSide.length < 1))) { plane.hasTexture = false; diff --git a/src/nitro/room/object/visualization/room/rasterizer/IPlaneRasterizer.ts b/src/nitro/room/object/visualization/room/rasterizer/IPlaneRasterizer.ts index 1abb0b2f..34c30b85 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/IPlaneRasterizer.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/IPlaneRasterizer.ts @@ -1,12 +1,13 @@ import { RenderTexture } from '@pixi/core'; import { IVector3D } from '../../../../../../api'; +import { RoomTextureCache } from '../../../../../../pixi-proxy'; import { PlaneBitmapData } from '../utils'; import { PlaneVisualizationLayer } from './basic'; export interface IPlaneRasterizer { initializeDimensions(_arg_1: number, _arg_2: number): boolean; - 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; + render(planeId: string, textureCache: RoomTextureCache, 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; getLayers(_arg_1: string): PlaneVisualizationLayer[]; reinitialize(): void; diff --git a/src/nitro/room/object/visualization/room/rasterizer/animated/LandscapePlane.ts b/src/nitro/room/object/visualization/room/rasterizer/animated/LandscapePlane.ts index 9686ffa1..6f459f0b 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/animated/LandscapePlane.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/animated/LandscapePlane.ts @@ -1,5 +1,6 @@ import { RenderTexture } from '@pixi/core'; import { IVector3D, Vector3d } from '../../../../../../../api'; +import { RoomTextureCache } from '../../../../../../../pixi-proxy'; import { Plane } from '../basic'; export class LandscapePlane extends Plane @@ -33,7 +34,7 @@ export class LandscapePlane extends Plane } } - 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 + public render(planeId: string, textureCache: RoomTextureCache, 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(scale); @@ -53,7 +54,7 @@ export class LandscapePlane extends Plane const renderMaxX = Math.trunc(maxX * Math.abs((_local_13.x - _local_15.x))); const renderMaxY = Math.trunc(maxY * Math.abs((_local_13.y - _local_14.y))); - return visualization.render(planeId, canvas, width, height, normal, useTexture, renderOffsetX, renderOffsetY, renderMaxX, renderMaxY, maxX, maxY, timeSinceStartMs); + return visualization.render(planeId, textureCache, canvas, width, height, normal, useTexture, renderOffsetX, renderOffsetY, renderMaxX, renderMaxY, maxX, maxY, timeSinceStartMs); } return null; diff --git a/src/nitro/room/object/visualization/room/rasterizer/animated/LandscapeRasterizer.ts b/src/nitro/room/object/visualization/room/rasterizer/animated/LandscapeRasterizer.ts index 7d3c8623..c0b0d9fa 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/animated/LandscapeRasterizer.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/animated/LandscapeRasterizer.ts @@ -1,6 +1,6 @@ import { RenderTexture } from '@pixi/core'; import { IAssetPlane, IAssetPlaneVisualizationAnimatedLayer, IAssetPlaneVisualizationLayer, IVector3D, Vector3d } from '../../../../../../../api'; -import { RoomTextureUtils, TextureUtils } from '../../../../../../../pixi-proxy'; +import { RoomTextureCache } from '../../../../../../../pixi-proxy'; import { PlaneBitmapData, Randomizer } from '../../utils'; import { PlaneMaterial, PlaneRasterizer, PlaneVisualizationLayer } from '../basic'; import { LandscapePlane } from './LandscapePlane'; @@ -184,7 +184,7 @@ export class LandscapeRasterizer extends PlaneRasterizer return _local_3; } - 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 + public render(planeId: string, textureCache: RoomTextureCache, 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; @@ -192,7 +192,7 @@ export class LandscapeRasterizer extends PlaneRasterizer if(!plane) return null; - if(canvas) TextureUtils.clearRenderTexture(canvas); + if(canvas) textureCache.clearRenderTexture(canvas); if(!LandscapeRasterizer.LANDSCAPES_ENABLED) { @@ -219,15 +219,15 @@ export class LandscapeRasterizer extends PlaneRasterizer this._cachedBitmap = null; } - this._cachedBitmap = RoomTextureUtils.createAndFillRenderTexture(width, height, LandscapeRasterizer.LANDSCAPE_DEFAULT_COLOR); + this._cachedBitmap = textureCache.createAndFillRenderTexture(width, height, LandscapeRasterizer.LANDSCAPE_DEFAULT_COLOR); } return new PlaneBitmapData(this._cachedBitmap, -1); } - if(canvas) TextureUtils.clearRenderTexture(canvas); + if(canvas) textureCache.clearRenderTexture(canvas); - let graphic = plane.render(planeId, canvas, width, height, scale, normal, useTexture, offsetX, offsetY, maxX, maxY, timeSinceStartMs); + let graphic = plane.render(planeId,textureCache, canvas, width, height, scale, normal, useTexture, offsetX, offsetY, maxX, maxY, timeSinceStartMs); if(graphic && (graphic !== canvas)) { diff --git a/src/nitro/room/object/visualization/room/rasterizer/animated/PlaneVisualizationAnimationLayer.ts b/src/nitro/room/object/visualization/room/rasterizer/animated/PlaneVisualizationAnimationLayer.ts index 40d45626..e2d8b0de 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/animated/PlaneVisualizationAnimationLayer.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/animated/PlaneVisualizationAnimationLayer.ts @@ -1,7 +1,7 @@ import { RenderTexture } from '@pixi/core'; import { Sprite } from '@pixi/sprite'; import { IDisposable, IGraphicAssetCollection, IVector3D } from '../../../../../../../api'; -import { RoomTextureUtils, TextureUtils } from '../../../../../../../pixi-proxy'; +import { RoomTextureCache } from '../../../../../../../pixi-proxy'; import { AnimationItem } from './AnimationItem'; export class PlaneVisualizationAnimationLayer implements IDisposable @@ -70,7 +70,7 @@ export class PlaneVisualizationAnimationLayer implements IDisposable } } - 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 + public render(textureCache: RoomTextureCache, 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 || (canvas.width !== width) || (canvas.height !== height)) { @@ -78,11 +78,11 @@ export class PlaneVisualizationAnimationLayer implements IDisposable { if(this._bitmapData) this._bitmapData.destroy(true); - this._bitmapData = RoomTextureUtils.createRenderTexture(width, height); + this._bitmapData = textureCache.createRenderTexture(width, height); } else { - TextureUtils.clearRenderTexture(this._bitmapData); + textureCache.clearRenderTexture(this._bitmapData); } canvas = this._bitmapData; @@ -111,7 +111,7 @@ export class PlaneVisualizationAnimationLayer implements IDisposable sprite.position.set(point.x, point.y); - TextureUtils.writeToRenderTexture(sprite, canvas, false); + textureCache.writeToRenderTexture(sprite, canvas, false); } if(((point.x - maxX) > -(item.bitmapData.width)) && ((point.x - maxX) < canvas.width) && (point.y > -(item.bitmapData.height)) && (point.y < canvas.height)) @@ -120,7 +120,7 @@ export class PlaneVisualizationAnimationLayer implements IDisposable sprite.position.set((point.x - maxX), point.y); - TextureUtils.writeToRenderTexture(sprite, canvas, false); + textureCache.writeToRenderTexture(sprite, canvas, false); } if((point.x > -(item.bitmapData.width)) && (point.x < canvas.width) && ((point.y - maxY) > -(item.bitmapData.height)) && ((point.y - maxY) < canvas.height)) @@ -129,7 +129,7 @@ export class PlaneVisualizationAnimationLayer implements IDisposable sprite.position.set(point.x, (point.y - maxY)); - TextureUtils.writeToRenderTexture(sprite, canvas, false); + textureCache.writeToRenderTexture(sprite, canvas, false); } if(((point.x - maxX) > -(item.bitmapData.width)) && ((point.x - maxX) < canvas.width) && ((point.y - maxY) > -(item.bitmapData.height)) && ((point.y - maxY) < canvas.height)) @@ -138,7 +138,7 @@ export class PlaneVisualizationAnimationLayer implements IDisposable sprite.position.set((point.x - maxX), (point.y - maxY)); - TextureUtils.writeToRenderTexture(sprite, canvas, false); + textureCache.writeToRenderTexture(sprite, canvas, false); } } } diff --git a/src/nitro/room/object/visualization/room/rasterizer/basic/FloorPlane.ts b/src/nitro/room/object/visualization/room/rasterizer/basic/FloorPlane.ts index 278d0dd1..9bba0030 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/basic/FloorPlane.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/basic/FloorPlane.ts @@ -1,5 +1,6 @@ import { RenderTexture } from '@pixi/core'; import { IVector3D, Vector3d } from '../../../../../../../api'; +import { RoomTextureCache } from '../../../../../../../pixi-proxy'; import { Plane } from './Plane'; export class FloorPlane extends Plane @@ -8,7 +9,7 @@ export class FloorPlane extends Plane public static HORIZONTAL_ANGLE_DEFAULT: number = 45; public static VERTICAL_ANGLE_DEFAULT: number = 30; - public render(planeId: string, canvas: RenderTexture, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number): RenderTexture + public render(planeId: string, textureCache: RoomTextureCache, canvas: RenderTexture, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number): RenderTexture { const visualization = this.getPlaneVisualization(scale); @@ -32,6 +33,6 @@ export class FloorPlane extends Plane y = (offsetY * Math.trunc(Math.abs(_local_15))); } - return visualization.render(planeId, canvas, width, height, normal, useTexture, x, y); + return visualization.render(planeId, textureCache, canvas, width, height, normal, useTexture, x, y); } } diff --git a/src/nitro/room/object/visualization/room/rasterizer/basic/FloorRasterizer.ts b/src/nitro/room/object/visualization/room/rasterizer/basic/FloorRasterizer.ts index 32840b5c..5f8e00fa 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/basic/FloorRasterizer.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/basic/FloorRasterizer.ts @@ -1,6 +1,6 @@ import { RenderTexture } from '@pixi/core'; import { IAssetPlane, IVector3D } from '../../../../../../../api'; -import { TextureUtils } from '../../../../../../../pixi-proxy'; +import { RoomTextureCache } from '../../../../../../../pixi-proxy'; import { PlaneBitmapData } from '../../utils'; import { FloorPlane } from './FloorPlane'; import { PlaneRasterizer } from './PlaneRasterizer'; @@ -36,7 +36,7 @@ export class FloorRasterizer extends PlaneRasterizer } } - 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 + public render(planeId: string, textureCache: RoomTextureCache, 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; @@ -44,9 +44,9 @@ export class FloorRasterizer extends PlaneRasterizer if(!plane) return null; - if(canvas) TextureUtils.clearAndFillRenderTexture(canvas); + if(canvas) textureCache.clearAndFillRenderTexture(canvas); - let graphic = plane.render(planeId, canvas, width, height, scale, normal, useTexture, offsetX, offsetY); + let graphic = plane.render(planeId, textureCache, canvas, width, height, scale, normal, useTexture, offsetX, offsetY); if(graphic && (graphic !== canvas)) { diff --git a/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneMaterial.ts b/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneMaterial.ts index 844c5c3f..756412a3 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneMaterial.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneMaterial.ts @@ -1,5 +1,6 @@ import { RenderTexture } from '@pixi/core'; import { IVector3D } from '../../../../../../../api'; +import { RoomTextureCache } from '../../../../../../../pixi-proxy'; import { PlaneMaterialCellMatrix } from './PlaneMaterialCellMatrix'; export class PlaneMaterial @@ -76,7 +77,7 @@ export class PlaneMaterial return null; } - public render(canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): RenderTexture + public render(textureCache: RoomTextureCache, canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): RenderTexture { if(width < 1) width = 1; @@ -88,6 +89,6 @@ export class PlaneMaterial this._isCached = true; - return cellMatrix.render(canvas, width, height, normal, useTexture, offsetX, offsetY, topAlign); + return cellMatrix.render(textureCache, canvas, width, height, normal, useTexture, offsetX, offsetY, topAlign); } } diff --git a/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneMaterialCellColumn.ts b/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneMaterialCellColumn.ts index 0ed98f69..16971933 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneMaterialCellColumn.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneMaterialCellColumn.ts @@ -1,7 +1,7 @@ import { RenderTexture, Texture } from '@pixi/core'; import { Sprite } from '@pixi/sprite'; import { IVector3D, Vector3d } from '../../../../../../../api'; -import { RoomTextureUtils, TextureUtils } from '../../../../../../../pixi-proxy'; +import { RoomTextureCache, TextureUtils } from '../../../../../../../pixi-proxy'; import { PlaneMaterialCell } from './PlaneMaterialCell'; export class PlaneMaterialCellColumn @@ -125,7 +125,7 @@ export class PlaneMaterialCellColumn this._isCached = false; } - public render(height: number, normal: IVector3D, offsetX: number, offsetY: number): RenderTexture + public render(textureCache: RoomTextureCache, height: number, normal: IVector3D, offsetX: number, offsetY: number): RenderTexture { if(this._repeatMode === PlaneMaterialCellColumn.REPEAT_MODE_NONE) height = this.getCellsHeight(this._cells, normal); @@ -143,7 +143,7 @@ export class PlaneMaterialCellColumn { if(this._cachedBitmapData.height === height) { - TextureUtils.clearRenderTexture(this._cachedBitmapData); + textureCache.clearRenderTexture(this._cachedBitmapData); } else { @@ -165,7 +165,7 @@ export class PlaneMaterialCellColumn sprite.width = this._cachedBitmapData.width; sprite.height = height; - TextureUtils.writeToRenderTexture(sprite, this._cachedBitmapData); + textureCache.writeToRenderTexture(sprite, this._cachedBitmapData); } else { @@ -180,7 +180,7 @@ export class PlaneMaterialCellColumn if(!this._cachedBitmapData) { - this._cachedBitmapData = RoomTextureUtils.createRenderTexture(this._width, height); + this._cachedBitmapData = textureCache.createRenderTexture(this._width, height); } this._cachedBitmapNormal.assign(normal); diff --git a/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneMaterialCellMatrix.ts b/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneMaterialCellMatrix.ts index 04618ebc..38ac9342 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneMaterialCellMatrix.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneMaterialCellMatrix.ts @@ -2,7 +2,7 @@ import { Point, Rectangle } from '@pixi/math'; import { Sprite } from '@pixi/sprite'; import { IVector3D, NitroLogger, Vector3d } from '../../../../../../../api'; -import { RoomTextureUtils, TextureUtils } from '../../../../../../../pixi-proxy'; +import { RoomTextureCache, TextureUtils } from '../../../../../../../pixi-proxy'; import { Randomizer } from '../../utils'; import { PlaneMaterialCell } from './PlaneMaterialCell'; import { PlaneMaterialCellColumn } from './PlaneMaterialCellColumn'; @@ -165,7 +165,7 @@ export class PlaneMaterialCellMatrix return true; } - public render(canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): RenderTexture + public render(textureCache: RoomTextureCache, canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): RenderTexture { if(width < 1) width = 1; @@ -212,18 +212,18 @@ export class PlaneMaterialCellMatrix if(!this._cachedBitmapData) { - this._cachedBitmapData = RoomTextureUtils.createAndFillRenderTexture(width, height); + this._cachedBitmapData = textureCache.createAndFillRenderTexture(width, height); this._texturePool.set(`${width}:${height}`, this._cachedBitmapData); } else { - TextureUtils.clearAndFillRenderTexture(this._cachedBitmapData); + textureCache.clearAndFillRenderTexture(this._cachedBitmapData); } } else { - TextureUtils.clearAndFillRenderTexture(this._cachedBitmapData); + textureCache.clearAndFillRenderTexture(this._cachedBitmapData); } if(canvas) @@ -244,13 +244,13 @@ export class PlaneMaterialCellMatrix if(!this._cachedBitmapData) { - this._cachedBitmapData = RoomTextureUtils.createRenderTexture(width, height); + this._cachedBitmapData = textureCache.createRenderTexture(width, height); this._texturePool.set(`${width}:${height}`, this._cachedBitmapData); } else { - TextureUtils.clearRenderTexture(this._cachedBitmapData); + textureCache.clearRenderTexture(this._cachedBitmapData); } } @@ -264,7 +264,7 @@ export class PlaneMaterialCellMatrix if(column) { - const columnBitmapData = column.render(height, normal, offsetX, offsetY); + const columnBitmapData = column.render(textureCache, height, normal, offsetX, offsetY); if(columnBitmapData) columns.push(columnBitmapData); } diff --git a/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneRasterizer.ts b/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneRasterizer.ts index ff351b32..50b9e2b4 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneRasterizer.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneRasterizer.ts @@ -1,6 +1,7 @@ import { RenderTexture, Resource, Texture } from '@pixi/core'; import { Point } from '@pixi/math'; import { IAssetPlaneMaterial, IAssetPlaneMaterialCellColumn, IAssetPlaneTexture, IAssetPlaneVisualization, IAssetPlaneVisualizationData, IAssetPlaneVisualizationLayer, IGraphicAsset, IGraphicAssetCollection, IRoomGeometry, IVector3D, Vector3d } from '../../../../../../../api'; +import { RoomTextureCache } from '../../../../../../../pixi-proxy'; import { Rasterizer, RoomGeometry } from '../../../../../../../room'; import { PlaneBitmapData } from '../../utils'; import { IPlaneRasterizer } from '../IPlaneRasterizer'; @@ -584,7 +585,7 @@ export class PlaneRasterizer implements IPlaneRasterizer } } - 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 + public render(planeId: string, textureCache: RoomTextureCache, 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; } diff --git a/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneVisualization.ts b/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneVisualization.ts index 2e327666..37b84bef 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneVisualization.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneVisualization.ts @@ -1,7 +1,7 @@ import { RenderTexture } from '@pixi/core'; import { Sprite } from '@pixi/sprite'; import { IDisposable, IGraphicAssetCollection, IRoomGeometry, IVector3D, Vector3d } from '../../../../../../../api'; -import { RoomTextureUtils, TextureUtils } from '../../../../../../../pixi-proxy'; +import { RoomTextureCache } from '../../../../../../../pixi-proxy'; import { PlaneVisualizationAnimationLayer } from '../animated'; import { PlaneMaterial } from './PlaneMaterial'; import { PlaneVisualizationLayer } from './PlaneVisualizationLayer'; @@ -148,7 +148,7 @@ export class PlaneVisualization return this._layers as PlaneVisualizationLayer[]; } - 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 + public render(planeId: string, textureCache: RoomTextureCache, 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; @@ -164,7 +164,7 @@ export class PlaneVisualization { if(canvas) { - TextureUtils.writeToRenderTexture(new Sprite(this._cachedBitmapData), canvas, true); + textureCache.writeToRenderTexture(new Sprite(this._cachedBitmapData), canvas, true); return canvas; } @@ -187,7 +187,7 @@ export class PlaneVisualization if(!swapCache) { - swapCache = RoomTextureUtils.createAndFillRenderTexture(width, height); + swapCache = textureCache.createAndFillRenderTexture(width, height); this._texturePool.set(planeId + '-swap', swapCache); } @@ -201,18 +201,18 @@ export class PlaneVisualization if(!cache) { - cache = RoomTextureUtils.createAndFillRenderTexture(width, height); + cache = textureCache.createAndFillRenderTexture(width, height); this._texturePool.set(planeId, cache); } this._cachedBitmapData = swapCache; - TextureUtils.clearAndFillRenderTexture(this._cachedBitmapData); + textureCache.clearAndFillRenderTexture(this._cachedBitmapData); } else { - TextureUtils.clearAndFillRenderTexture(this._cachedBitmapData); + textureCache.clearAndFillRenderTexture(this._cachedBitmapData); } if(!canvas) canvas = this._cachedBitmapData; @@ -227,19 +227,19 @@ export class PlaneVisualization if(layer instanceof PlaneVisualizationLayer) { - layer.render(canvas, width, height, normal, useTexture, offsetX, offsetY); + layer.render(textureCache, canvas, width, height, normal, useTexture, offsetX, offsetY); } else if(layer instanceof PlaneVisualizationAnimationLayer) { - layer.render(canvas, width, height, normal, offsetX, offsetY, maxX, maxY, dimensionX, dimensionY, timeSinceStartMs); + layer.render(textureCache, canvas, width, height, normal, offsetX, offsetY, maxX, maxY, dimensionX, dimensionY, timeSinceStartMs); } } } if(canvas && (canvas !== this._cachedBitmapData)) { - TextureUtils.writeToRenderTexture(new Sprite(canvas), this._cachedBitmapData, false); + textureCache.writeToRenderTexture(new Sprite(canvas), this._cachedBitmapData, false); return canvas; } diff --git a/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneVisualizationLayer.ts b/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneVisualizationLayer.ts index f5bec4bc..e7214647 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneVisualizationLayer.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/basic/PlaneVisualizationLayer.ts @@ -1,7 +1,7 @@ import { RenderTexture } from '@pixi/core'; import { Sprite } from '@pixi/sprite'; import { IVector3D } from '../../../../../../../api'; -import { RoomTextureUtils, TextureUtils } from '../../../../../../../pixi-proxy'; +import { RoomTextureCache } from '../../../../../../../pixi-proxy'; import { PlaneMaterial } from './PlaneMaterial'; export class PlaneVisualizationLayer @@ -61,7 +61,7 @@ export class PlaneVisualizationLayer } } - public render(canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number): RenderTexture + public render(textureCache: RoomTextureCache, 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; @@ -77,7 +77,7 @@ export class PlaneVisualizationLayer if(this._material) { - bitmapData = this._material.render(hasColor ? null : canvas, width, height, normal, useTexture, offsetX, (offsetY + this.offset), (this.align === PlaneVisualizationLayer.ALIGN_TOP)); + bitmapData = this._material.render(textureCache, hasColor ? null : canvas, width, height, normal, useTexture, offsetX, (offsetY + this.offset), (this.align === PlaneVisualizationLayer.ALIGN_TOP)); if(bitmapData && (bitmapData !== canvas)) { @@ -94,7 +94,7 @@ export class PlaneVisualizationLayer sprite.tint = this._color; - TextureUtils.writeToRenderTexture(sprite, canvas, false); + textureCache.writeToRenderTexture(sprite, canvas, false); bitmapData = canvas; } @@ -107,13 +107,13 @@ export class PlaneVisualizationLayer if(this._bitmapData) this._bitmapData.destroy(); - this._bitmapData = RoomTextureUtils.createAndFillRenderTexture(width, height, this._color); + this._bitmapData = textureCache.createAndFillRenderTexture(width, height, this._color); bitmapData = this._bitmapData; } else { - TextureUtils.clearAndFillRenderTexture(canvas, this._color); + textureCache.clearAndFillRenderTexture(canvas, this._color); bitmapData = canvas; } diff --git a/src/nitro/room/object/visualization/room/rasterizer/basic/WallPlane.ts b/src/nitro/room/object/visualization/room/rasterizer/basic/WallPlane.ts index 74776468..932410ee 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/basic/WallPlane.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/basic/WallPlane.ts @@ -1,5 +1,6 @@ import { RenderTexture } from '@pixi/core'; import { IVector3D, Vector3d } from '../../../../../../../api'; +import { RoomTextureCache } from '../../../../../../../pixi-proxy'; import { Plane } from './Plane'; export class WallPlane extends Plane @@ -8,7 +9,7 @@ export class WallPlane extends Plane public static HORIZONTAL_ANGLE_DEFAULT: number = 45; public static VERTICAL_ANGLE_DEFAULT: number = 30; - public render(planeId: string, canvas: RenderTexture, width: number, height: number, size: number, normal: IVector3D, useTexture: boolean): RenderTexture + public render(planeId: string, textureCache: RoomTextureCache, canvas: RenderTexture, width: number, height: number, size: number, normal: IVector3D, useTexture: boolean): RenderTexture { const visualization = this.getPlaneVisualization(size); @@ -24,6 +25,6 @@ export class WallPlane extends Plane height = Math.round(Math.abs((_local_8.y - _local_9.y))); } - return visualization.render(planeId, canvas, width, height, normal, useTexture); + return visualization.render(planeId, textureCache, canvas, width, height, normal, useTexture); } } diff --git a/src/nitro/room/object/visualization/room/rasterizer/basic/WallRasterizer.ts b/src/nitro/room/object/visualization/room/rasterizer/basic/WallRasterizer.ts index c46ba849..7836c982 100644 --- a/src/nitro/room/object/visualization/room/rasterizer/basic/WallRasterizer.ts +++ b/src/nitro/room/object/visualization/room/rasterizer/basic/WallRasterizer.ts @@ -1,6 +1,6 @@ import { RenderTexture } from '@pixi/core'; import { IAssetPlane, IVector3D } from '../../../../../../../api'; -import { TextureUtils } from '../../../../../../../pixi-proxy'; +import { RoomTextureCache } from '../../../../../../../pixi-proxy'; import { PlaneBitmapData } from '../../utils'; import { PlaneRasterizer } from './PlaneRasterizer'; import { WallPlane } from './WallPlane'; @@ -36,7 +36,7 @@ export class WallRasterizer extends PlaneRasterizer } } - 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 + public render(planeId: string, textureCache: RoomTextureCache, 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; @@ -44,9 +44,9 @@ export class WallRasterizer extends PlaneRasterizer if(!plane) return null; - if(canvas) TextureUtils.clearAndFillRenderTexture(canvas); + if(canvas) textureCache.clearAndFillRenderTexture(canvas); - let graphic = plane.render(planeId, canvas, width, height, scale, normal, useTexture); + let graphic = plane.render(planeId, textureCache, canvas, width, height, scale, normal, useTexture); if(graphic && (graphic !== canvas)) { diff --git a/src/pixi-proxy/RoomTextureUtils.ts b/src/pixi-proxy/RoomTextureUtils.ts index 90cdf5ef..c65ebe8f 100644 --- a/src/pixi-proxy/RoomTextureUtils.ts +++ b/src/pixi-proxy/RoomTextureUtils.ts @@ -5,25 +5,25 @@ import { Matrix, Rectangle } from '@pixi/math'; import { Sprite } from '@pixi/sprite'; import { PixiApplicationProxy } from './PixiApplicationProxy'; -export class RoomTextureUtils +export class RoomTextureCache { - public static RENDER_TEXTURE_CACHE: RenderTexture[] = []; + public RENDER_TEXTURE_CACHE: RenderTexture[] = []; - public static clearCache(): void + public clearCache(): void { this.RENDER_TEXTURE_CACHE.forEach(renderTexture => renderTexture?.destroy(true)); this.RENDER_TEXTURE_CACHE = []; } - public static clearRenderTexture(renderTexture: RenderTexture): RenderTexture + public clearRenderTexture(renderTexture: RenderTexture): RenderTexture { if(!renderTexture) return null; return this.writeToRenderTexture(new Sprite(Texture.EMPTY), renderTexture); } - public static createRenderTexture(width: number, height: number): RenderTexture + public createRenderTexture(width: number, height: number): RenderTexture { if((width < 0) || (height < 0)) return null; @@ -37,7 +37,7 @@ export class RoomTextureUtils return renderTexture; } - public static createAndFillRenderTexture(width: number, height: number, color: number = 16777215): RenderTexture + public createAndFillRenderTexture(width: number, height: number, color: number = 16777215): RenderTexture { if((width < 0) || (height < 0)) return null; @@ -46,7 +46,7 @@ export class RoomTextureUtils return this.clearAndFillRenderTexture(renderTexture, color); } - public static createAndWriteRenderTexture(width: number, height: number, displayObject: DisplayObject, transform: Matrix = null): RenderTexture + public createAndWriteRenderTexture(width: number, height: number, displayObject: DisplayObject, transform: Matrix = null): RenderTexture { if((width < 0) || (height < 0)) return null; @@ -55,7 +55,7 @@ export class RoomTextureUtils return this.writeToRenderTexture(displayObject, renderTexture, true, transform); } - public static clearAndFillRenderTexture(renderTexture: RenderTexture, color: number = 16777215): RenderTexture + public clearAndFillRenderTexture(renderTexture: RenderTexture, color: number = 16777215): RenderTexture { if(!renderTexture) return null; @@ -69,7 +69,7 @@ export class RoomTextureUtils return this.writeToRenderTexture(sprite, renderTexture); } - public static writeToRenderTexture(displayObject: DisplayObject, renderTexture: RenderTexture, clear: boolean = true, transform: Matrix = null): RenderTexture + public writeToRenderTexture(displayObject: DisplayObject, renderTexture: RenderTexture, clear: boolean = true, transform: Matrix = null): RenderTexture { if(!displayObject || !renderTexture) return null; @@ -82,17 +82,17 @@ export class RoomTextureUtils return renderTexture; } - public static getPixels(displayObject: DisplayObject | RenderTexture, frame: Rectangle = null): Uint8Array + public getPixels(displayObject: DisplayObject | RenderTexture, frame: Rectangle = null): Uint8Array { return this.getExtractor().pixels(displayObject); } - public static getRenderer(): Renderer | AbstractRenderer + public getRenderer(): Renderer | AbstractRenderer { return PixiApplicationProxy.instance.renderer; } - public static getExtractor(): Extract + public getExtractor(): Extract { return (this.getRenderer().plugins.extract as Extract); }