Still buggy but better landscapes

This commit is contained in:
Bill 2023-01-13 02:48:35 -05:00
parent 103a128508
commit ce82ff9930
18 changed files with 168 additions and 386 deletions

View File

@ -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, RoomTextureCache } from '../../../../../pixi-proxy';
import { PixiApplicationProxy, PlaneTextureCache } from '../../../../../pixi-proxy';
import { ColorConverter } from '../../../../../room';
import { PlaneMaskManager } from './mask';
import { PlaneDrawingData } from './PlaneDrawingData';
@ -20,7 +20,7 @@ export class RoomPlane implements IRoomPlane
public static TYPE_LANDSCAPE: number = 3;
private static _uniqueIdCounter: number = 1;
private _textureCache: RoomTextureCache;
private _textureCache: PlaneTextureCache;
private _disposed: boolean;
private _randomSeed: number;
private _origin: Vector3d;
@ -45,7 +45,6 @@ export class RoomPlane implements IRoomPlane
private _textureOffsetY: number;
private _textureMaxX: number;
private _textureMaxY: number;
private _textures: Map<string, PlaneBitmapData>;
private _activeTexture: PlaneBitmapData;
private _useMask: boolean;
private _bitmapMasks: RoomPlaneBitmapMask[];
@ -63,7 +62,7 @@ export class RoomPlane implements IRoomPlane
private _height: number = 0;
private _canBeVisible: boolean;
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)
constructor(textureCache: PlaneTextureCache, 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 = [];
@ -115,7 +114,6 @@ export class RoomPlane implements IRoomPlane
this._color = 0;
this._rasterizer = null;
this._canBeVisible = true;
this._textures = new Map();
this._cornerA = new Vector3d();
this._cornerB = new Vector3d();
this._cornerC = new Vector3d();
@ -256,20 +254,6 @@ export class RoomPlane implements IRoomPlane
this._bitmapData = null;
}
if(this._textures)
{
for(const bitmap of this._textures.values())
{
if(!bitmap) continue;
if(bitmap.texture) bitmap.texture.destroy();
bitmap.dispose();
}
this._textures = null;
}
this._activeTexture = null;
this._location = null;
this._origin = null;
@ -305,37 +289,8 @@ export class RoomPlane implements IRoomPlane
return k;
}
private cacheTexture(k: string, _arg_2: PlaneBitmapData): boolean
{
const existing = this._textures.get(k);
if(existing)
{
this._textures.delete(k);
existing.dispose();
}
this._activeTexture = _arg_2;
this._textures.set(k, _arg_2);
return true;
}
private resetTextureCache(k: RenderTexture = null): void
{
if(this._textures && this._textures.size)
{
for(const bitmap of this._textures.values())
{
if(!bitmap) continue;
bitmap.dispose();
}
this._textures.clear();
}
this._activeTexture = null;
}
@ -350,12 +305,7 @@ export class RoomPlane implements IRoomPlane
{
if(!k) return false;
let planeBitmap = this._activeTexture;
if(!planeBitmap)
{
planeBitmap = this._textures.get(this.getTextureIdentifier(k.scale));
}
const planeBitmap = this._activeTexture;
this.updateMaskChangeStatus();
@ -377,48 +327,16 @@ export class RoomPlane implements IRoomPlane
const height = this._rightSide.length * geometry.scale;
const normal = geometry.getCoordinatePosition(this._normal);
if(this._activeTexture)
{
bitmapData = this._activeTexture;
}
else
{
bitmapData = this._textures.get(identifier);
}
let texture: RenderTexture = null;
if(bitmapData) texture = bitmapData.texture;
if(this._rasterizer)
{
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 = this._textureCache.createAndFillRenderTexture(width, height);
bitmapData = new PlaneBitmapData(renderTexture, -1);
}
bitmapData = this._rasterizer.render(this._uniqueId.toString(), this._textureCache, null, this._id, width, height, geometry.scale, normal, this._hasTexture, this._textureOffsetX, this._textureOffsetY, this._textureMaxX, this._textureMaxY, timeSinceStartMs);
if(bitmapData)
{
this.updateMask(bitmapData.texture, geometry);
this.cacheTexture(identifier, bitmapData);
}
}
else
{
if(this._activeTexture)
{
bitmapData = this._activeTexture;
}
else
{
bitmapData = this._textures.get(this.getTextureIdentifier(geometry.scale));
}
if(this._activeTexture) bitmapData = this._activeTexture;
}
if(bitmapData)
@ -976,5 +894,6 @@ export class RoomPlane implements IRoomPlane
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);
gl.bindTexture(gl.TEXTURE_2D, null);
}
}

View File

@ -1,6 +1,6 @@
import { Rectangle } from '@pixi/math';
import { AlphaTolerance, IObjectVisualizationData, IPlaneVisualization, IRoomGeometry, IRoomObjectModel, IRoomObjectSprite, IRoomPlane, RoomObjectSpriteType, RoomObjectVariable, Vector3d } from '../../../../../api';
import { RoomTextureCache } from '../../../../../pixi-proxy';
import { PlaneTextureCache } from '../../../../../pixi-proxy';
import { RoomObjectSpriteVisualization } from '../../../../../room';
import { ToInt32 } from '../../../../utils';
import { RoomMapData } from '../../RoomMapData';
@ -57,7 +57,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
private _assetUpdateCounter: number;
private _maskData: RoomMapMaskData;
private _isPlaneSet: boolean;
private _textureCache: RoomTextureCache;
private _textureCache: PlaneTextureCache;
constructor()
{
@ -93,7 +93,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
this._assetUpdateCounter = 0;
this._maskData = null;
this._isPlaneSet = false;
this._textureCache = new RoomTextureCache();
this._textureCache = new PlaneTextureCache();
this._typeVisibility[RoomPlane.TYPE_UNDEFINED] = false;
this._typeVisibility[RoomPlane.TYPE_FLOOR] = true;
@ -147,7 +147,6 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
if(this._textureCache)
{
console.log('clear it');
this._textureCache.clearCache();
}
}
@ -183,7 +182,10 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
if(((time < (this._lastUpdateTime + this._updateIntervalTime)) && (!geometryUpdate)) && (!needsUpdate)) return;
if(this.updatePlaneTexturesAndVisibilities(objectModel)) needsUpdate = true;
if(this.updatePlaneTexturesAndVisibilities(objectModel))
{
needsUpdate = true;
}
if(this.updatePlanes(geometry, geometryUpdate, time)) needsUpdate = true;
@ -339,15 +341,11 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
const wallType = model.getValue<string>(RoomObjectVariable.ROOM_WALL_TYPE);
const landscapeType = model.getValue<string>(RoomObjectVariable.ROOM_LANDSCAPE_TYPE);
this.updatePlaneTypes(floorType, wallType, landscapeType);
const floorVisibility = (model.getValue<number>(RoomObjectVariable.ROOM_FLOOR_VISIBILITY) === 1);
const wallVisibility = (model.getValue<number>(RoomObjectVariable.ROOM_WALL_VISIBILITY) === 1);
const landscapeVisibility = (model.getValue<number>(RoomObjectVariable.ROOM_LANDSCAPE_VISIBILITY) === 1);
this.updatePlaneVisibility(floorVisibility, wallVisibility, landscapeVisibility);
return true;
return (this.updatePlaneTypes(floorType, wallType, landscapeType) || this.updatePlaneVisibility(floorVisibility, wallVisibility, landscapeVisibility));
}
private clearPlanes(): void
@ -691,9 +689,9 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
return true;
}
private updatePlaneVisibility(k: boolean, _arg_2: boolean, _arg_3: boolean): void
private updatePlaneVisibility(k: boolean, _arg_2: boolean, _arg_3: boolean): boolean
{
if((k === this._typeVisibility[RoomPlane.TYPE_FLOOR]) && (_arg_2 === this._typeVisibility[RoomPlane.TYPE_WALL]) && (_arg_3 === this._typeVisibility[RoomPlane.TYPE_LANDSCAPE])) return;
if((k === this._typeVisibility[RoomPlane.TYPE_FLOOR]) && (_arg_2 === this._typeVisibility[RoomPlane.TYPE_WALL]) && (_arg_3 === this._typeVisibility[RoomPlane.TYPE_LANDSCAPE])) return false;
this._typeVisibility[RoomPlane.TYPE_FLOOR] = k;
this._typeVisibility[RoomPlane.TYPE_WALL] = _arg_2;
@ -701,11 +699,13 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
this._visiblePlanes = [];
this._visiblePlaneSpriteNumbers = [];
return true;
}
protected updatePlanes(geometry: IRoomGeometry, geometryUpdate: boolean, timeSinceStartMs: number): boolean
{
if(!geometry || !this.object) return;
if(!geometry || !this.object) return false;
this._assetUpdateCounter++;

View File

@ -1,13 +1,13 @@
import { RenderTexture } from '@pixi/core';
import { IVector3D } from '../../../../../../api';
import { RoomTextureCache } from '../../../../../../pixi-proxy';
import { PlaneTextureCache } 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, 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;
render(planeId: string, textureCache: PlaneTextureCache, 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;

View File

@ -1,6 +1,6 @@
import { RenderTexture } from '@pixi/core';
import { IVector3D, Vector3d } from '../../../../../../../api';
import { RoomTextureCache } from '../../../../../../../pixi-proxy';
import { PlaneTextureCache } from '../../../../../../../pixi-proxy';
import { Plane } from '../basic';
export class LandscapePlane extends Plane
@ -34,7 +34,7 @@ export class LandscapePlane extends Plane
}
}
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
public render(planeId: string, textureCache: PlaneTextureCache, 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);

View File

@ -1,6 +1,6 @@
import { RenderTexture } from '@pixi/core';
import { IAssetPlane, IAssetPlaneVisualizationAnimatedLayer, IAssetPlaneVisualizationLayer, IVector3D, Vector3d } from '../../../../../../../api';
import { RoomTextureCache } from '../../../../../../../pixi-proxy';
import { IAssetPlane, IAssetPlaneVisualizationAnimatedLayer, IAssetPlaneVisualizationLayer, IVector3D } from '../../../../../../../api';
import { PlaneTextureCache } 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, 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
public render(planeId: string, textureCache: PlaneTextureCache, 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;
@ -194,39 +194,6 @@ export class LandscapeRasterizer extends PlaneRasterizer
if(canvas) textureCache.clearRenderTexture(canvas);
if(!LandscapeRasterizer.LANDSCAPES_ENABLED)
{
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 = textureCache.createAndFillRenderTexture(width, height, LandscapeRasterizer.LANDSCAPE_DEFAULT_COLOR);
}
return new PlaneBitmapData(this._cachedBitmap, -1);
}
if(canvas) textureCache.clearRenderTexture(canvas);
let graphic = plane.render(planeId,textureCache, canvas, width, height, scale, normal, useTexture, offsetX, offsetY, maxX, maxY, timeSinceStartMs);
if(graphic && (graphic !== canvas))

View File

@ -1,7 +1,7 @@
import { RenderTexture } from '@pixi/core';
import { Sprite } from '@pixi/sprite';
import { IDisposable, IGraphicAssetCollection, IVector3D } from '../../../../../../../api';
import { RoomTextureCache } from '../../../../../../../pixi-proxy';
import { PlaneTextureCache } from '../../../../../../../pixi-proxy';
import { AnimationItem } from './AnimationItem';
export class PlaneVisualizationAnimationLayer implements IDisposable
@ -70,9 +70,9 @@ export class PlaneVisualizationAnimationLayer implements IDisposable
}
}
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
public render(textureCache: PlaneTextureCache, 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))
/* if(!canvas || (canvas.width !== width) || (canvas.height !== height))
{
if(!this._bitmapData || (this._bitmapData.width !== width) || (this._bitmapData.height !== height))
{
@ -86,7 +86,7 @@ export class PlaneVisualizationAnimationLayer implements IDisposable
}
canvas = this._bitmapData;
}
} */
if(((maxX > 0) && (maxY > 0)))
{

View File

@ -1,6 +1,6 @@
import { RenderTexture } from '@pixi/core';
import { IVector3D, Vector3d } from '../../../../../../../api';
import { RoomTextureCache } from '../../../../../../../pixi-proxy';
import { PlaneTextureCache } from '../../../../../../../pixi-proxy';
import { Plane } from './Plane';
export class FloorPlane extends Plane
@ -9,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, textureCache: RoomTextureCache, canvas: RenderTexture, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number): RenderTexture
public render(planeId: string, textureCache: PlaneTextureCache, canvas: RenderTexture, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number): RenderTexture
{
const visualization = this.getPlaneVisualization(scale);

View File

@ -1,6 +1,6 @@
import { RenderTexture } from '@pixi/core';
import { IAssetPlane, IVector3D } from '../../../../../../../api';
import { RoomTextureCache } from '../../../../../../../pixi-proxy';
import { PlaneTextureCache } 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, 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
public render(planeId: string, textureCache: PlaneTextureCache, 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;

View File

@ -1,6 +1,6 @@
import { RenderTexture } from '@pixi/core';
import { IVector3D } from '../../../../../../../api';
import { RoomTextureCache } from '../../../../../../../pixi-proxy';
import { PlaneTextureCache } from '../../../../../../../pixi-proxy';
import { PlaneMaterialCellMatrix } from './PlaneMaterialCellMatrix';
export class PlaneMaterial
@ -77,7 +77,7 @@ export class PlaneMaterial
return null;
}
public render(textureCache: RoomTextureCache, canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): RenderTexture
public render(planeId: string, textureCache: PlaneTextureCache, canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): RenderTexture
{
if(width < 1) width = 1;
@ -89,6 +89,6 @@ export class PlaneMaterial
this._isCached = true;
return cellMatrix.render(textureCache, canvas, width, height, normal, useTexture, offsetX, offsetY, topAlign);
return cellMatrix.render(planeId, textureCache, canvas, width, height, normal, useTexture, offsetX, offsetY, topAlign);
}
}

View File

@ -1,7 +1,6 @@
import { RenderTexture, Texture } from '@pixi/core';
import { Sprite } from '@pixi/sprite';
import { RenderTexture } from '@pixi/core';
import { IVector3D, Vector3d } from '../../../../../../../api';
import { RoomTextureCache, TextureUtils } from '../../../../../../../pixi-proxy';
import { PlaneTextureCache, TextureUtils } from '../../../../../../../pixi-proxy';
import { PlaneMaterialCell } from './PlaneMaterialCell';
export class PlaneMaterialCellColumn
@ -125,7 +124,7 @@ export class PlaneMaterialCellColumn
this._isCached = false;
}
public render(textureCache: RoomTextureCache, height: number, normal: IVector3D, offsetX: number, offsetY: number): RenderTexture
public render(planeId: string, textureCache: PlaneTextureCache, height: number, normal: IVector3D, offsetX: number, offsetY: number): RenderTexture
{
if(this._repeatMode === PlaneMaterialCellColumn.REPEAT_MODE_NONE) height = this.getCellsHeight(this._cells, normal);
@ -141,46 +140,20 @@ export class PlaneMaterialCellColumn
}
else
{
if(this._cachedBitmapData.height === height)
{
textureCache.clearRenderTexture(this._cachedBitmapData);
}
else
{
this._cachedBitmapData.destroy(true);
this._cachedBitmapData = null;
}
}
}
}
else
{
if(this._cachedBitmapData)
{
if(this._cachedBitmapData.height === height)
{
const sprite = new Sprite(Texture.EMPTY);
sprite.width = this._cachedBitmapData.width;
sprite.height = height;
textureCache.writeToRenderTexture(sprite, this._cachedBitmapData);
}
else
{
this._cachedBitmapData.destroy(true);
this._cachedBitmapData = null;
}
}
}
this._isCached = true;
if(!this._cachedBitmapData)
{
this._cachedBitmapData = textureCache.createRenderTexture(this._width, height);
this._cachedBitmapData = textureCache.createRenderTexture(this._width, height, `${ planeId }:column`);
}
this._cachedBitmapNormal.assign(normal);

View File

@ -1,8 +1,8 @@
import { RenderTexture, Texture } from '@pixi/core';
import { RenderTexture } from '@pixi/core';
import { Point, Rectangle } from '@pixi/math';
import { Sprite } from '@pixi/sprite';
import { IVector3D, NitroLogger, Vector3d } from '../../../../../../../api';
import { RoomTextureCache, TextureUtils } from '../../../../../../../pixi-proxy';
import { PlaneTextureCache, TextureUtils } from '../../../../../../../pixi-proxy';
import { Randomizer } from '../../utils';
import { PlaneMaterialCell } from './PlaneMaterialCell';
import { PlaneMaterialCellColumn } from './PlaneMaterialCellColumn';
@ -34,7 +34,6 @@ export class PlaneMaterialCellMatrix
private _normalMaxX: number = 1;
private _normalMinY: 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)
{
@ -57,7 +56,6 @@ export class PlaneMaterialCellMatrix
this._normalMaxX = normalMaxX;
this._normalMinY = normalMinY;
this._normalMaxY = normalMaxY;
this._texturePool = new Map();
if(this._repeatMode === PlaneMaterialCellMatrix.REPEAT_MODE_RANDOM) this._isStatic = false;
}
@ -139,13 +137,6 @@ export class PlaneMaterialCellMatrix
}
}
if(this._texturePool && this._texturePool.size)
{
this._texturePool.forEach(texture => texture.destroy(true));
this._texturePool.clear();
}
this._isCached = false;
}
@ -165,14 +156,12 @@ export class PlaneMaterialCellMatrix
return true;
}
public render(textureCache: RoomTextureCache, canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): RenderTexture
public render(planeId: string, textureCache: PlaneTextureCache, canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): RenderTexture
{
if(width < 1) width = 1;
if(height < 1) height = 1;
if(!canvas || (canvas.width !== width) || (canvas.height !== height)) canvas = null;
if(!this._cachedBitmapNormal) this._cachedBitmapNormal = new Vector3d();
if(this.isStatic)
@ -208,30 +197,13 @@ export class PlaneMaterialCellMatrix
if(!this._cachedBitmapData)
{
this._cachedBitmapData = this._texturePool.get(`${width}:${height}`);
if(!this._cachedBitmapData)
{
this._cachedBitmapData = textureCache.createAndFillRenderTexture(width, height);
this._texturePool.set(`${width}:${height}`, this._cachedBitmapData);
}
else
{
textureCache.clearAndFillRenderTexture(this._cachedBitmapData);
}
this._cachedBitmapData = textureCache.createAndFillRenderTexture(width, height, `${ planeId }:matrix`);
}
else
{
textureCache.clearAndFillRenderTexture(this._cachedBitmapData);
}
if(canvas)
{
this.copyCachedBitmapOnCanvas(canvas, height, offsetY, topAlign);
return canvas;
}
return this._cachedBitmapData;
}
@ -240,19 +212,10 @@ export class PlaneMaterialCellMatrix
{
this._cachedBitmapHeight = height;
this._cachedBitmapData = this._texturePool.get(`${width}:${height}`);
this._cachedBitmapData = textureCache.createRenderTexture(width, height, `${ planeId }:matrix`);
if(!this._cachedBitmapData)
{
this._cachedBitmapData = textureCache.createRenderTexture(width, height);
this._texturePool.set(`${width}:${height}`, this._cachedBitmapData);
}
else
{
textureCache.clearRenderTexture(this._cachedBitmapData);
}
}
const columns: RenderTexture[] = [];
@ -264,7 +227,7 @@ export class PlaneMaterialCellMatrix
if(column)
{
const columnBitmapData = column.render(textureCache, height, normal, offsetX, offsetY);
const columnBitmapData = column.render(planeId, textureCache, height, normal, offsetX, offsetY);
if(columnBitmapData) columns.push(columnBitmapData);
}
@ -336,7 +299,7 @@ export class PlaneMaterialCellMatrix
bounds = new Rectangle(0, (this._cachedBitmapData.height - this._cachedBitmapHeight), this._cachedBitmapData.width, this._cachedBitmapHeight);
}
const texture = new Texture(this._cachedBitmapData.baseTexture, bounds);
const texture = new RenderTexture(this._cachedBitmapData.baseTexture, bounds);
const sprite = new Sprite(texture);
sprite.position.set(0, offsetY);

View File

@ -1,7 +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 { PlaneTextureCache } from '../../../../../../../pixi-proxy';
import { Rasterizer, RoomGeometry } from '../../../../../../../room';
import { PlaneBitmapData } from '../../utils';
import { IPlaneRasterizer } from '../IPlaneRasterizer';
@ -585,7 +585,7 @@ export class PlaneRasterizer implements IPlaneRasterizer
}
}
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
public render(planeId: string, textureCache: PlaneTextureCache, 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;
}

View File

@ -1,7 +1,6 @@
import { RenderTexture } from '@pixi/core';
import { Sprite } from '@pixi/sprite';
import { IDisposable, IGraphicAssetCollection, IRoomGeometry, IVector3D, Vector3d } from '../../../../../../../api';
import { RoomTextureCache } from '../../../../../../../pixi-proxy';
import { PlaneTextureCache } from '../../../../../../../pixi-proxy';
import { PlaneVisualizationAnimationLayer } from '../animated';
import { PlaneMaterial } from './PlaneMaterial';
import { PlaneVisualizationLayer } from './PlaneVisualizationLayer';
@ -14,7 +13,6 @@ export class PlaneVisualization
private _cachedBitmapNormal: Vector3d;
private _isCached: boolean;
private _hasAnimationLayers: boolean;
private _texturePool: Map<string, RenderTexture>;
constructor(size: number, totalLayers: number, geometry: IRoomGeometry)
{
@ -24,7 +22,6 @@ export class PlaneVisualization
this._cachedBitmapNormal = new Vector3d();
this._isCached = false;
this._hasAnimationLayers = false;
this._texturePool = new Map();
if(totalLayers < 0) totalLayers = 0;
@ -102,13 +99,6 @@ export class PlaneVisualization
}
}
if(this._texturePool && this._texturePool.size)
{
this._texturePool.forEach(texture => texture.destroy(true));
this._texturePool.clear();
}
this._isCached = false;
}
@ -148,7 +138,7 @@ export class PlaneVisualization
return this._layers as PlaneVisualizationLayer[];
}
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
public render(planeId: string, textureCache: PlaneTextureCache, 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;
@ -156,7 +146,7 @@ export class PlaneVisualization
if((!canvas || (canvas.width !== width)) || (canvas.height !== height)) canvas = null;
if(this._cachedBitmapData)
/* if(this._cachedBitmapData)
{
if((this._cachedBitmapData.width === width) && (this._cachedBitmapData.height === height) && (Vector3d.isEqual(this._cachedBitmapNormal, normal)))
{
@ -176,46 +166,11 @@ export class PlaneVisualization
{
this._cachedBitmapData = null;
}
}
} */
this._isCached = true;
if(!this._cachedBitmapData)
{
let cache = this._texturePool.get(planeId);
let swapCache = this._texturePool.get(planeId + '-swap');
if(!swapCache)
{
swapCache = textureCache.createAndFillRenderTexture(width, height);
this._texturePool.set(planeId + '-swap', swapCache);
}
else
{
if(cache)
{
[ cache, swapCache ] = [ swapCache, cache ];
}
}
if(!cache)
{
cache = textureCache.createAndFillRenderTexture(width, height);
this._texturePool.set(planeId, cache);
}
this._cachedBitmapData = swapCache;
textureCache.clearAndFillRenderTexture(this._cachedBitmapData);
}
else
{
textureCache.clearAndFillRenderTexture(this._cachedBitmapData);
}
if(!canvas) canvas = this._cachedBitmapData;
this._cachedBitmapData = textureCache.createAndFillRenderTexture(width, height, planeId);
this._cachedBitmapNormal.assign(normal);
@ -227,23 +182,16 @@ export class PlaneVisualization
if(layer instanceof PlaneVisualizationLayer)
{
layer.render(textureCache, canvas, width, height, normal, useTexture, offsetX, offsetY);
layer.render(planeId, textureCache, this._cachedBitmapData, width, height, normal, useTexture, offsetX, offsetY);
}
else if(layer instanceof PlaneVisualizationAnimationLayer)
{
layer.render(textureCache, canvas, width, height, normal, offsetX, offsetY, maxX, maxY, dimensionX, dimensionY, timeSinceStartMs);
layer.render(textureCache, this._cachedBitmapData, width, height, normal, offsetX, offsetY, maxX, maxY, dimensionX, dimensionY, timeSinceStartMs);
}
}
}
if(canvas && (canvas !== this._cachedBitmapData))
{
textureCache.writeToRenderTexture(new Sprite(canvas), this._cachedBitmapData, false);
return canvas;
}
return this._cachedBitmapData;
}
}

View File

@ -1,7 +1,7 @@
import { RenderTexture } from '@pixi/core';
import { Sprite } from '@pixi/sprite';
import { IVector3D } from '../../../../../../../api';
import { RoomTextureCache } from '../../../../../../../pixi-proxy';
import { PlaneTextureCache } from '../../../../../../../pixi-proxy';
import { PlaneMaterial } from './PlaneMaterial';
export class PlaneVisualizationLayer
@ -61,65 +61,25 @@ export class PlaneVisualizationLayer
}
}
public render(textureCache: RoomTextureCache, canvas: RenderTexture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number): RenderTexture
public render(planeId: string, textureCache: PlaneTextureCache, 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;
const r = (this._color >> 16);
const g = ((this._color >> 8) & 0xFF);
const b = (this._color & 0xFF);
const hasColor = ((r < 0xFF) || (g < 0xFF) || (b < 0xFF));
let hasColor = false;
if(((r < 0xFF) || (g < 0xFF))|| (b < 0xFF)) hasColor = true;
let bitmapData: RenderTexture = null;
if(this._material)
{
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))
{
if(this._bitmapData) this._bitmapData.destroy();
this._bitmapData = new RenderTexture(bitmapData.baseTexture);
bitmapData = this._bitmapData;
}
const bitmapData = this._material.render(planeId, textureCache, hasColor ? null : canvas, width, height, normal, useTexture, offsetX, (offsetY + this.offset), (this.align === PlaneVisualizationLayer.ALIGN_TOP));
if(bitmapData && hasColor)
{
const sprite = new Sprite(bitmapData);
sprite.tint = this._color;
if(hasColor) sprite.tint = this._color;
textureCache.writeToRenderTexture(sprite, canvas, false);
bitmapData = canvas;
}
}
else
{
if(!canvas)
{
if(this._bitmapData && (this._bitmapData.width === width) && (this._bitmapData.height === height)) return this._bitmapData;
if(this._bitmapData) this._bitmapData.destroy();
this._bitmapData = textureCache.createAndFillRenderTexture(width, height, this._color);
bitmapData = this._bitmapData;
}
else
{
textureCache.clearAndFillRenderTexture(canvas, this._color);
bitmapData = canvas;
}
}
return bitmapData;
return canvas;
}
public getMaterial(): PlaneMaterial

View File

@ -1,6 +1,6 @@
import { RenderTexture } from '@pixi/core';
import { IVector3D, Vector3d } from '../../../../../../../api';
import { RoomTextureCache } from '../../../../../../../pixi-proxy';
import { PlaneTextureCache } from '../../../../../../../pixi-proxy';
import { Plane } from './Plane';
export class WallPlane extends Plane
@ -9,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, textureCache: RoomTextureCache, canvas: RenderTexture, width: number, height: number, size: number, normal: IVector3D, useTexture: boolean): RenderTexture
public render(planeId: string, textureCache: PlaneTextureCache, canvas: RenderTexture, width: number, height: number, size: number, normal: IVector3D, useTexture: boolean): RenderTexture
{
const visualization = this.getPlaneVisualization(size);

View File

@ -1,6 +1,6 @@
import { RenderTexture } from '@pixi/core';
import { IAssetPlane, IVector3D } from '../../../../../../../api';
import { RoomTextureCache } from '../../../../../../../pixi-proxy';
import { PlaneTextureCache } 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, 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
public render(planeId: string, textureCache: PlaneTextureCache, 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;

View File

@ -112,30 +112,28 @@ export class LegacyWallGeometry implements ILegacyWallGeometry
return heightMap[x];
}
public getLocation(k: number, _arg_2: number, _arg_3: number, _arg_4: number, _arg_5: string): IVector3D
public getLocation(width: number, height: number, localX: number, localY: number, direction: string): IVector3D
{
let _local_12: number;
let _local_6: number;
let _local_7: number;
if(((k == 0) && (_arg_2 == 0)))
if(((width == 0) && (height == 0)))
{
k = this._width;
_arg_2 = this._height;
_local_12 = Math.round((this.scale / 10));
if(_arg_5 == LegacyWallGeometry.R)
width = this._width;
height = this._height;
const _local_12 = Math.round((this.scale / 10));
if(direction == LegacyWallGeometry.R)
{
_local_7 = (this._width - 1);
let _local_7 = (this._width - 1);
while(_local_7 >= 0)
{
_local_6 = 1;
let _local_6 = 1;
while(_local_6 < this._height)
{
if(this.getHeight(_local_7, _local_6) <= this._floorHeight)
{
if((_local_6 - 1) < _arg_2)
if((_local_6 - 1) < height)
{
k = _local_7;
_arg_2 = (_local_6 - 1);
width = _local_7;
height = (_local_6 - 1);
}
break;
}
@ -143,23 +141,23 @@ export class LegacyWallGeometry implements ILegacyWallGeometry
}
_local_7--;
}
_arg_4 = (_arg_4 + ((this.scale / 4) - (_local_12 / 2)));
_arg_3 = (_arg_3 + (this.scale / 2));
localY = (localY + ((this.scale / 4) - (_local_12 / 2)));
localX = (localX + (this.scale / 2));
}
else
{
_local_6 = (this._height - 1);
let _local_6 = (this._height - 1);
while(_local_6 >= 0)
{
_local_7 = 1;
let _local_7 = 1;
while(_local_7 < this._width)
{
if(this.getHeight(_local_7, _local_6) <= this._floorHeight)
{
if((_local_7 - 1) < k)
if((_local_7 - 1) < width)
{
k = (_local_7 - 1);
_arg_2 = _local_6;
width = (_local_7 - 1);
height = _local_6;
}
break;
}
@ -167,24 +165,24 @@ export class LegacyWallGeometry implements ILegacyWallGeometry
}
_local_6--;
}
_arg_4 = (_arg_4 + ((this.scale / 4) - (_local_12 / 2)));
_arg_3 = (_arg_3 - _local_12);
localY = (localY + ((this.scale / 4) - (_local_12 / 2)));
localX = (localX - _local_12);
}
}
let _local_8: number = k;
let _local_9: number = _arg_2;
let _local_10: number = this.getHeight(k, _arg_2);
if(_arg_5 == LegacyWallGeometry.R)
let _local_8: number = width;
let _local_9: number = height;
let _local_10: number = this.getHeight(width, height);
if(direction == LegacyWallGeometry.R)
{
_local_8 = (_local_8 + ((_arg_3 / (this._scale / 2)) - 0.5));
_local_8 = (_local_8 + ((localX / (this._scale / 2)) - 0.5));
_local_9 = (_local_9 + 0.5);
_local_10 = (_local_10 - ((_arg_4 - (_arg_3 / 2)) / (this._scale / 2)));
_local_10 = (_local_10 - ((localY - (localX / 2)) / (this._scale / 2)));
}
else
{
_local_9 = (_local_9 + ((((this._scale / 2) - _arg_3) / (this._scale / 2)) - 0.5));
_local_9 = (_local_9 + ((((this._scale / 2) - localX) / (this._scale / 2)) - 0.5));
_local_8 = (_local_8 + 0.5);
_local_10 = (_local_10 - ((_arg_4 - (((this._scale / 2) - _arg_3) / 2)) / (this._scale / 2)));
_local_10 = (_local_10 - ((localY - (((this._scale / 2) - localX) / 2)) / (this._scale / 2)));
}
const _local_11: Vector3d = new Vector3d(_local_8, _local_9, _local_10);
return _local_11;

View File

@ -5,14 +5,23 @@ import { Matrix, Rectangle } from '@pixi/math';
import { Sprite } from '@pixi/sprite';
import { PixiApplicationProxy } from './PixiApplicationProxy';
export class RoomTextureCache
export class PlaneTextureCache
{
private static DEFAULT_PLANE_ID = 'DEFAULT';
public RENDER_TEXTURE_POOL: Map<string, RenderTexture> = new Map();
public RENDER_TEXTURE_CACHE: RenderTexture[] = [];
public clearCache(): void
{
this.RENDER_TEXTURE_CACHE.forEach(renderTexture => renderTexture?.destroy(true));
const previousTextures = this.RENDER_TEXTURE_CACHE.slice();
setTimeout(() =>
{
previousTextures.forEach(renderTexture => renderTexture?.destroy(true));
}, 1000);
this.RENDER_TEXTURE_POOL.clear();
this.RENDER_TEXTURE_CACHE = [];
}
@ -23,10 +32,17 @@ export class RoomTextureCache
return this.writeToRenderTexture(new Sprite(Texture.EMPTY), renderTexture);
}
public createRenderTexture(width: number, height: number): RenderTexture
private getTextureIdentifier(width: number, height: number, planeId: string): string
{
return `${ planeId ?? PlaneTextureCache.DEFAULT_PLANE_ID }:${ width }:${ height }`;
}
public createRenderTexture(width: number, height: number, planeId: string = null): RenderTexture
{
if((width < 0) || (height < 0)) return null;
if(!planeId)
{
const renderTexture = RenderTexture.create({
width,
height
@ -37,20 +53,58 @@ export class RoomTextureCache
return renderTexture;
}
public createAndFillRenderTexture(width: number, height: number, color: number = 16777215): RenderTexture
planeId = this.getTextureIdentifier(width, height, planeId);
let renderTexture = this.RENDER_TEXTURE_POOL.get(planeId);
if(!renderTexture)
{
renderTexture = RenderTexture.create({
width,
height
});
this.RENDER_TEXTURE_CACHE.push(renderTexture);
this.RENDER_TEXTURE_POOL.set(planeId, renderTexture);
}
/* else
{
renderTexture = this.RENDER_TEXTURE_POOL.get(planeId + '-swap');
if(!renderTexture)
{
renderTexture = RenderTexture.create({
width,
height
});
this.RENDER_TEXTURE_CACHE.push(renderTexture);
this.RENDER_TEXTURE_POOL.set(planeId + '-swap', renderTexture);
}
this.RENDER_TEXTURE_POOL.set(planeId + '-swap', this.RENDER_TEXTURE_POOL.get(planeId));
this.RENDER_TEXTURE_POOL.set(planeId, renderTexture);
} */
return renderTexture;
}
public createAndFillRenderTexture(width: number, height: number, planeId = null, color: number = 16777215): RenderTexture
{
if((width < 0) || (height < 0)) return null;
const renderTexture = this.createRenderTexture(width, height);
const renderTexture = this.createRenderTexture(width, height, planeId);
return this.clearAndFillRenderTexture(renderTexture, color);
}
public createAndWriteRenderTexture(width: number, height: number, displayObject: DisplayObject, transform: Matrix = null): RenderTexture
public createAndWriteRenderTexture(width: number, height: number, displayObject: DisplayObject, planeId: string = null, transform: Matrix = null): RenderTexture
{
if((width < 0) || (height < 0)) return null;
const renderTexture = this.createRenderTexture(width, height);
const renderTexture = this.createRenderTexture(width, height, planeId);
return this.writeToRenderTexture(displayObject, renderTexture, true, transform);
}