Redo plane system

This commit is contained in:
billsonnn 2024-03-23 20:54:08 -04:00
parent 62a749dba6
commit fc9e22ad2b
28 changed files with 365 additions and 4318 deletions

View File

@ -1,6 +1,4 @@
import { IVector3D } from '../../../utils';
import { IRoomGeometry } from '../../IRoomGeometry';
import { IPlaneDrawingData } from './IPlaneDrawingData';
export interface IRoomPlane
{
@ -9,5 +7,4 @@ export interface IRoomPlane
leftSide: IVector3D;
rightSide: IVector3D;
color: number;
getDrawingDatas(_arg_1: IRoomGeometry): IPlaneDrawingData[];
}

View File

@ -1166,7 +1166,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
{
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_9: number = (RoomPlaneParser.FLOOR_THICKNESS * this._floorThicknessMultiplier);
const _local_10: Vector3d = Vector3d.crossProduct(_arg_2, _arg_3);

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,7 @@
import { AlphaTolerance, IObjectVisualizationData, IPlaneVisualization, IRoomGeometry, IRoomObjectModel, IRoomObjectSprite, IRoomPlane, RoomObjectSpriteType, RoomObjectVariable } from '@nitrots/api';
import { ToInt32, Vector3d } from '@nitrots/utils';
import { Rectangle } from 'pixi.js';
import { AlphaTolerance, IObjectVisualizationData, IPlaneVisualization, IRoomGeometry, IRoomObjectModel, IRoomObjectSprite, IRoomPlane, RoomObjectSpriteType, RoomObjectVariable } from '../../../../../api';
import { RoomMapData } from '../../RoomMapData';
import { RoomMapMaskData } from '../../RoomMapMaskData';
import { RoomPlaneBitmapMaskData } from '../../RoomPlaneBitmapMaskData';
import { RoomPlaneBitmapMaskParser } from '../../RoomPlaneBitmapMaskParser';
import { RoomPlaneData } from '../../RoomPlaneData';
import { RoomPlaneParser } from '../../RoomPlaneParser';
import { RoomObjectSpriteVisualization } from '../RoomObjectSpriteVisualization';
@ -28,7 +25,6 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
protected _data: RoomVisualizationData;
private _roomPlaneParser: RoomPlaneParser;
private _roomPlaneBitmapMaskParser: RoomPlaneBitmapMaskParser;
private _geometryUpdateId: number;
private _boundingRectangle: Rectangle;
@ -42,19 +38,15 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
private _visiblePlanes: RoomPlane[];
private _visiblePlaneSpriteNumbers: number[];
private _roomScale: number;
private _lastUpdateTime: number;
private _updateIntervalTime: number;
private _wallType: string;
private _floorType: string;
private _landscapeType: string;
private _colorBackgroundOnly: boolean;
private _color: number;
private _redColor: number;
private _greenColor: number;
private _blueColor: number;
private _wallType: string = null;
private _floorType: string = null;
private _landscapeType: string = null;
private _typeVisibility: boolean[];
private _assetUpdateCounter: number;
private _maskData: RoomMapMaskData;
private _isPlaneSet: boolean;
constructor()
@ -64,7 +56,6 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
this._data = null;
this._roomPlaneParser = new RoomPlaneParser();
this._roomPlaneBitmapMaskParser = new RoomPlaneBitmapMaskParser();
this._geometryUpdateId = -1;
this._directionX = 0;
@ -77,19 +68,12 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
this._visiblePlanes = [];
this._visiblePlaneSpriteNumbers = [];
this._roomScale = 0;
this._lastUpdateTime = -1000;
this._updateIntervalTime = 250;
this._wallType = null;
this._floorType = null;
this._landscapeType = null;
this._colorBackgroundOnly = true;
this._color = 0xFFFFFF;
this._redColor = 0xFF;
this._greenColor = 0xFF;
this._blueColor = 0xFF;
this._typeVisibility = [];
this._assetUpdateCounter = 0;
this._maskData = null;
this._isPlaneSet = false;
this._typeVisibility[RoomPlane.TYPE_UNDEFINED] = false;
@ -128,17 +112,8 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
this._roomPlaneParser = null;
}
if(this._roomPlaneBitmapMaskParser)
{
this._roomPlaneBitmapMaskParser.dispose();
this._roomPlaneBitmapMaskParser = null;
}
if(this._data)
{
this._data.clearCache();
this._data = null;
}
}
@ -147,10 +122,6 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
{
super.reset();
this._floorType = null;
this._wallType = null;
this._landscapeType = null;
this._maskData = null;
this._geometryUpdateId = -1;
this._roomScale = 0;
}
@ -162,64 +133,53 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
const geometryUpdate = this.updateGeometry(geometry);
const objectModel = this.object.model;
let needsUpdate = false;
let needsUpdate = geometryUpdate;
if(this.updateThickness(objectModel)) needsUpdate = true;
if(this.updateHole(objectModel)) needsUpdate = true;
if(!needsUpdate) return;
this.initializeRoomPlanes();
this.updatePlaneTexturesAndVisibilities(objectModel);
this.updatePlanes(geometry, geometryUpdate, time);
needsUpdate = this.updateMasks(objectModel);
let index = 0;
if(((time < (this._lastUpdateTime + this._updateIntervalTime)) && (!geometryUpdate)) && (!needsUpdate)) return;
if(this.updatePlaneTexturesAndVisibilities(objectModel))
while(index < this._visiblePlanes.length)
{
needsUpdate = true;
}
const spriteIndex = this._visiblePlaneSpriteNumbers[index];
const sprite = this.getSprite(spriteIndex);
const plane = this._visiblePlanes[index];
if(this.updatePlanes(geometry, geometryUpdate, time)) needsUpdate = true;
if(needsUpdate)
{
let index = 0;
while(index < this._visiblePlanes.length)
if(sprite && plane && (plane.type !== RoomPlane.TYPE_LANDSCAPE))
{
const spriteIndex = this._visiblePlaneSpriteNumbers[index];
const sprite = this.getSprite(spriteIndex);
const plane = this._visiblePlanes[index];
if(sprite && plane && (plane.type !== RoomPlane.TYPE_LANDSCAPE))
if(this._colorBackgroundOnly)
{
if(this._colorBackgroundOnly)
{
let _local_14 = plane.color;
let _local_14 = plane.color;
const _local_15 = (((_local_14 & 0xFF) * this._redColor) / 0xFF);
const _local_16 = ((((_local_14 >> 8) & 0xFF) * this._greenColor) / 0xFF);
const _local_17 = ((((_local_14 >> 16) & 0xFF) * this._blueColor) / 0xFF);
const _local_18 = (_local_14 >> 24);
const _local_15 = (((_local_14 & 0xFF) * this._redColor) / 0xFF);
const _local_16 = ((((_local_14 >> 8) & 0xFF) * this._greenColor) / 0xFF);
const _local_17 = ((((_local_14 >> 16) & 0xFF) * this._blueColor) / 0xFF);
const _local_18 = (_local_14 >> 24);
_local_14 = ((((_local_18 << 24) + (_local_17 << 16)) + (_local_16 << 8)) + _local_15);
_local_14 = ((((_local_18 << 24) + (_local_17 << 16)) + (_local_16 << 8)) + _local_15);
sprite.color = _local_14;
}
else
{
sprite.color = plane.color;
}
sprite.color = _local_14;
}
else
{
sprite.color = plane.color;
}
index++;
}
this.updateSpriteCounter++;
index++;
}
this.updateSpriteCounter++;
this.updateModelCounter = objectModel.updateCounter;
this._lastUpdateTime = time;
}
private updateGeometry(k: IRoomGeometry): boolean
@ -284,47 +244,6 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
return false;
}
private updateMasks(k: IRoomObjectModel): boolean
{
if(this.updateModelCounter === k.updateCounter) return false;
let didUpdate = false;
const planeMask = k.getValue<RoomMapMaskData>(RoomObjectVariable.ROOM_PLANE_MASK_XML);
if(planeMask !== this._maskData)
{
this.updatePlaneMasks(planeMask);
this._maskData = planeMask;
didUpdate = true;
}
const backgroundColor = k.getValue<number>(RoomObjectVariable.ROOM_BACKGROUND_COLOR);
if(backgroundColor !== this._color)
{
this._color = backgroundColor;
this._redColor = (this._color & 0xFF);
this._greenColor = ((this._color >> 8) & 0xFF);
this._blueColor = ((this._color >> 16) & 0xFF);
didUpdate = true;
}
const backgroundOnly = (k.getValue<boolean>(RoomObjectVariable.ROOM_COLORIZE_BG_ONLY) || false);
if(backgroundOnly !== this._colorBackgroundOnly)
{
this._colorBackgroundOnly = backgroundOnly;
didUpdate = true;
}
return didUpdate;
}
private updatePlaneTexturesAndVisibilities(model: IRoomObjectModel): boolean
{
if(this.updateModelCounter === model.updateCounter) return false;
@ -377,7 +296,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
const maxX = this.getLandscapeWidth();
const maxY = this.getLandscapeHeight();
let _local_5 = 0;
let landscapeOffsetX = 0;
let randomSeed = this.object.model.getValue<number>(RoomObjectVariable.ROOM_RANDOM_SEED);
let index = 0;
@ -407,134 +326,30 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
plane = new RoomPlane(this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_FLOOR, true, secondaryNormals, randomSeed, -(textureOffsetX), -(textureOffsetY));
if(_local_14.z !== 0)
{
plane.color = RoomVisualization.FLOOR_COLOR;
}
else
{
plane.color = ((_local_14.x !== 0) ? RoomVisualization.FLOOR_COLOR_RIGHT : RoomVisualization.FLOOR_COLOR_LEFT);
}
if(this._data) plane.rasterizer = this._data.floorRasterizer;
plane.color = (_local_14.z !== 0) ? RoomVisualization.FLOOR_COLOR : ((_local_14.x !== 0) ? RoomVisualization.FLOOR_COLOR_RIGHT : RoomVisualization.FLOOR_COLOR_LEFT);
}
else if(planeType === RoomPlaneData.PLANE_WALL)
{
plane = new RoomPlane(this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_WALL, true, secondaryNormals, randomSeed);
if((leftSide.length < 1) || (rightSide.length < 1))
{
plane.hasTexture = false;
}
if((leftSide.length < 1) || (rightSide.length < 1)) plane.hasTexture = false;
if((_local_14.x === 0) && (_local_14.y === 0))
{
plane.color = RoomVisualization.WALL_COLOR_BORDER;
}
else
{
if(_local_14.y > 0)
{
plane.color = RoomVisualization.WALL_COLOR_TOP;
}
else
{
if(_local_14.y === 0)
{
plane.color = RoomVisualization.WALL_COLOR_SIDE;
}
else
{
plane.color = RoomVisualization.WALL_COLOR_BOTTOM;
}
}
}
if(this._data) plane.rasterizer = this._data.wallRasterizer;
plane.color = ((_local_14.x === 0) && (_local_14.y === 0)) ? RoomVisualization.WALL_COLOR_BORDER : ((_local_14.y > 0) ? RoomVisualization.WALL_COLOR_TOP : ((_local_14.y === 0) ? RoomVisualization.WALL_COLOR_SIDE : RoomVisualization.WALL_COLOR_BOTTOM));
}
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.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_LANDSCAPE, true, secondaryNormals, randomSeed, landscapeOffsetX, 0, maxX, maxY);
if(_local_14.y > 0)
{
plane.color = RoomVisualization.LANDSCAPE_COLOR_TOP;
}
else
{
if(_local_14.y == 0)
{
plane.color = RoomVisualization.LANDSCAPE_COLOR_SIDE;
}
else
{
plane.color = RoomVisualization.LANDSCAPE_COLOR_BOTTOM;
}
}
if((leftSide.length < 1) || (rightSide.length < 1)) plane.hasTexture = false;
if(this._data) plane.rasterizer = this._data.landscapeRasterizer;
plane.color = (_local_14.y > 0) ? RoomVisualization.LANDSCAPE_COLOR_TOP : (_local_14.y === 0) ? RoomVisualization.LANDSCAPE_COLOR_SIDE : RoomVisualization.LANDSCAPE_COLOR_BOTTOM;
_local_5 = (_local_5 + leftSide.length);
landscapeOffsetX = (landscapeOffsetX + leftSide.length);
}
else if(planeType == RoomPlaneData.PLANE_BILLBOARD)
{
plane = new RoomPlane(this.object.getLocation(), location, leftSide, rightSide, RoomPlane.TYPE_WALL, true, secondaryNormals, randomSeed);
if(((leftSide.length < 1) || (rightSide.length < 1)))
{
plane.hasTexture = false;
}
if(((_local_14.x == 0) && (_local_14.y == 0)))
{
plane.color = RoomVisualization.WALL_COLOR_BORDER;
}
else
{
if(_local_14.y > 0)
{
plane.color = RoomVisualization.WALL_COLOR_TOP;
}
else
{
if(_local_14.y == 0)
{
plane.color = RoomVisualization.WALL_COLOR_SIDE;
}
else
{
plane.color = RoomVisualization.WALL_COLOR_BOTTOM;
}
}
}
// if (this._Str_594 != null)
// {
// _local_13.rasterizer = this._Str_594._Str_23913;
// }
}
if(plane)
{
plane.maskManager = this._data.maskManager;
let _local_19 = 0;
while(_local_19 < this._roomPlaneParser.getPlaneMaskCount(index))
{
const _local_20 = this._roomPlaneParser.getPlaneMaskLeftSideLoc(index, _local_19);
const _local_21 = this._roomPlaneParser.getPlaneMaskRightSideLoc(index, _local_19);
const _local_22 = this._roomPlaneParser.getPlaneMaskLeftSideLength(index, _local_19);
const _local_23 = this._roomPlaneParser.getPlaneMaskRightSideLength(index, _local_19);
plane.addRectangleMask(_local_20, _local_21, _local_22, _local_23);
_local_19++;
}
this._planes.push(plane);
}
if(plane) this._planes.push(plane);
}
else
{
@ -788,109 +603,6 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
return updated;
}
protected updatePlaneMasks(k: RoomMapMaskData): void
{
if(!k) return;
this._roomPlaneBitmapMaskParser.initialize(k);
const _local_4: number[] = [];
const _local_5: number[] = [];
let _local_6 = false;
let index = 0;
while(index < this._planes.length)
{
const plane = this._planes[index];
if(plane)
{
plane.resetBitmapMasks();
if(plane.type === RoomPlane.TYPE_LANDSCAPE) _local_4.push(index);
}
index++;
}
for(const mask of this._roomPlaneBitmapMaskParser.masks.values())
{
const maskType = this._roomPlaneBitmapMaskParser.getMaskType(mask);
const maskLocation = this._roomPlaneBitmapMaskParser.getMaskLocation(mask);
const maskCategory = this._roomPlaneBitmapMaskParser.getMaskCategory(mask);
if(maskLocation)
{
let i = 0;
while(i < this._planes.length)
{
const plane = this._planes[i];
if((plane.type === RoomPlane.TYPE_WALL) || (plane.type === RoomPlane.TYPE_LANDSCAPE))
{
if(plane && plane.location && plane.normal)
{
const _local_14 = Vector3d.dif(maskLocation, plane.location);
const _local_15 = Math.abs(Vector3d.scalarProjection(_local_14, plane.normal));
if(_local_15 < 0.01)
{
if(plane.leftSide && plane.rightSide)
{
const leftSideLoc = Vector3d.scalarProjection(_local_14, plane.leftSide);
const rightSideLoc = Vector3d.scalarProjection(_local_14, plane.rightSide);
if((plane.type === RoomPlane.TYPE_WALL) || ((plane.type === RoomPlane.TYPE_LANDSCAPE) && (maskCategory === RoomPlaneBitmapMaskData.HOLE)))
{
plane.addBitmapMask(maskType, leftSideLoc, rightSideLoc);
}
else
{
if(plane.type === RoomPlane.TYPE_LANDSCAPE)
{
if(!plane.canBeVisible) _local_6 = true;
plane.canBeVisible = true;
_local_5.push(i);
}
}
}
}
}
}
i++;
}
}
}
index = 0;
while(index < _local_4.length)
{
const planeIndex = _local_4[index];
if(_local_5.indexOf(planeIndex) < 0)
{
const plane = this._planes[planeIndex];
plane.canBeVisible = false;
_local_6 = true;
}
index++;
}
if(_local_6)
{
this._visiblePlanes = [];
this._visiblePlaneSpriteNumbers = [];
}
}
private updateSprite(sprite: IRoomObjectSprite, geometry: IRoomGeometry, plane: RoomPlane, _arg_3: string, relativeDepth: number): void
{
const offset = plane.offset;
@ -899,7 +611,7 @@ export class RoomVisualization extends RoomObjectSpriteVisualization implements
sprite.offsetY = -(offset.y);
sprite.relativeDepth = relativeDepth;
sprite.color = plane.color;
sprite.texture = plane.bitmapData;
sprite.texture = plane.planeTexture;
sprite.name = ((_arg_3 + '_') + this._assetUpdateCounter);
}

View File

@ -1,12 +1,8 @@
import { IAssetData, IGraphicAssetCollection, IObjectVisualizationData } from '@nitrots/api';
import { PlaneMaskManager } from './mask';
import { FloorRasterizer, LandscapeRasterizer, WallRasterizer } from './rasterizer';
export class RoomVisualizationData implements IObjectVisualizationData
{
private _wallRasterizer: WallRasterizer = new WallRasterizer();
private _floorRasterizer: FloorRasterizer = new FloorRasterizer();
private _landscapeRasterizer: LandscapeRasterizer = new LandscapeRasterizer();
private _maskManager: PlaneMaskManager = new PlaneMaskManager();
private _initialized: boolean = false;
@ -14,18 +10,6 @@ export class RoomVisualizationData implements IObjectVisualizationData
{
if(!asset.roomVisualization) return false;
const wallData = asset.roomVisualization.wallData;
if(wallData) this._wallRasterizer.initialize(wallData);
const floorData = asset.roomVisualization.floorData;
if(floorData) this._floorRasterizer.initialize(floorData);
const landscapeData = asset.roomVisualization.landscapeData;
if(landscapeData) this._landscapeRasterizer.initialize(landscapeData);
const maskData = asset.roomVisualization.maskData;
if(maskData) this._maskManager.initialize(maskData);
@ -35,27 +19,6 @@ export class RoomVisualizationData implements IObjectVisualizationData
public dispose(): void
{
if(this._wallRasterizer)
{
this._wallRasterizer.dispose();
this._wallRasterizer = null;
}
if(this._floorRasterizer)
{
this._floorRasterizer.dispose();
this._floorRasterizer = null;
}
if(this._landscapeRasterizer)
{
this._landscapeRasterizer.dispose();
this._landscapeRasterizer = null;
}
if(this._maskManager)
{
this._maskManager.dispose();
@ -68,9 +31,6 @@ export class RoomVisualizationData implements IObjectVisualizationData
{
if(this._initialized) return;
this._wallRasterizer.initializeAssetCollection(collection);
this._floorRasterizer.initializeAssetCollection(collection);
this._landscapeRasterizer.initializeAssetCollection(collection);
this._maskManager.initializeAssetCollection(collection);
this._initialized = true;
@ -78,26 +38,6 @@ export class RoomVisualizationData implements IObjectVisualizationData
public clearCache(): void
{
if(this._wallRasterizer) this._wallRasterizer.clearCache();
if(this._floorRasterizer) this._floorRasterizer.clearCache();
if(this._landscapeRasterizer) this._landscapeRasterizer.clearCache();
}
public get wallRasterizer(): WallRasterizer
{
return this._wallRasterizer;
}
public get floorRasterizer(): FloorRasterizer
{
return this._floorRasterizer;
}
public get landscapeRasterizer(): LandscapeRasterizer
{
return this._landscapeRasterizer;
}
public get maskManager(): PlaneMaskManager

View File

@ -1,13 +0,0 @@
import { IVector3D } from '@nitrots/api';
import { RenderTexture } from 'pixi.js';
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;
getTextureIdentifier(_arg_1: number, _arg_2: IVector3D): string;
getLayers(_arg_1: string): PlaneVisualizationLayer[];
reinitialize(): void;
}

View File

@ -1,53 +0,0 @@
import { IGraphicAsset } from '@nitrots/api';
import { Point } from 'pixi.js';
export class AnimationItem
{
private _x: number;
private _y: number;
private _speedX: number;
private _speedY: number;
private _asset: IGraphicAsset;
constructor(x: number, y: number, speedX: number, speedY: number, asset: IGraphicAsset)
{
this._x = x;
this._y = y;
this._speedX = speedX;
this._speedY = speedY;
this._asset = asset;
if(isNaN(this._x)) this._x = 0;
if(isNaN(this._y)) this._y = 0;
if(isNaN(this._speedX)) this._speedX = 0;
if(isNaN(this._speedY)) this._speedY = 0;
}
public get bitmapData(): IGraphicAsset
{
return this._asset;
}
public dispose(): void
{
this._asset = null;
}
public getPosition(maxX: number, maxY: number, dimensionX: number, dimensionY: number, timeSinceStartMs: number): Point
{
let x = this._x;
let y = this._y;
if(dimensionX > 0) x = (x + (((this._speedX / dimensionX) * timeSinceStartMs) / 1000));
if(dimensionY > 0) y = (y + (((this._speedY / dimensionY) * timeSinceStartMs) / 1000));
const _local_8 = Math.trunc((x % 1) * maxX);
const _local_9 = Math.trunc((y % 1) * maxY);
return new Point(_local_8, _local_9);
}
}

View File

@ -1,62 +0,0 @@
import { IVector3D } from '@nitrots/api';
import { Vector3d } from '@nitrots/utils';
import { Texture } from 'pixi.js';
import { Plane } from '../basic';
export class LandscapePlane extends Plane
{
public static DEFAULT_COLOR: number = 0xFFFFFF;
public static HORIZONTAL_ANGLE_DEFAULT: number = 45;
public static VERTICAL_ANGLE_DEFAULT: number = 30;
private _width: number = 0;
private _height: number = 0;
public isStatic(scale: number): boolean
{
const visualization = this.getPlaneVisualization(scale);
if(visualization) return !visualization.hasAnimationLayers;
return super.isStatic(scale);
}
public initializeDimensions(width: number, height: number): void
{
if(width < 0) width = 0;
if(height < 0) height = 0;
if((width !== this._width) || (height !== this._height))
{
this._width = width;
this._height = height;
}
}
public render(planeId: string, canvas: Texture, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, maxX: number, maxY: number, timeSinceStartMs: number): Texture
{
const visualization = this.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)));
const renderOffsetX = Math.trunc(offsetX * Math.abs((_local_13.x - _local_15.x)));
const renderOffsetY = Math.trunc(offsetY * Math.abs((_local_13.y - _local_14.y)));
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 null;
}
}

View File

@ -1,239 +0,0 @@
import { IAssetPlane, IAssetPlaneVisualizationAnimatedLayer, IAssetPlaneVisualizationLayer, IVector3D } from '@nitrots/api';
import { GetConfiguration } from '@nitrots/configuration';
import { TextureUtils } from '@nitrots/utils';
import { RenderTexture, Sprite } from 'pixi.js';
import { PlaneBitmapData, Randomizer } from '../../utils';
import { PlaneMaterial, PlaneRasterizer, PlaneVisualizationLayer } from '../basic';
import { LandscapePlane } from './LandscapePlane';
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 _landscapeWidth: number = 0;
private _landscapeHeight: number = 0;
private _cachedBitmap: RenderTexture = null;
constructor()
{
LandscapeRasterizer.LANDSCAPES_ENABLED = GetConfiguration().getValue<boolean>('room.landscapes.enabled', true);
super();
}
public initializeDimensions(k: number, _arg_2: number): boolean
{
if(k < 0) k = 0;
if(_arg_2 < 0) _arg_2 = 0;
this._landscapeWidth = k;
this._landscapeHeight = _arg_2;
return true;
}
protected initializePlanes(): void
{
if(!this.data) return;
const landscapes = this.data.planes;
if(landscapes && landscapes.length) this.parseLandscapes(landscapes);
}
private parseLandscapes(k: IAssetPlane[]): void
{
if(!k) return;
const randomNumber = Math.trunc((Math.random() * 654321));
for(const landscapeIndex in k)
{
const landscape = k[landscapeIndex];
if(!landscape) continue;
const id = landscape.id;
const visualizations = landscape.animatedVisualization;
const plane = new LandscapePlane();
for(const visualization of visualizations)
{
if(!visualization) continue;
const size = visualization.size;
let horizontalAngle = LandscapePlane.HORIZONTAL_ANGLE_DEFAULT;
let verticalAngle = LandscapePlane.VERTICAL_ANGLE_DEFAULT;
if(visualization.horizontalAngle !== undefined) horizontalAngle = visualization.horizontalAngle;
if(visualization.verticalAngle !== undefined) verticalAngle = visualization.verticalAngle;
const totalLayers = (visualization.allLayers.length ?? 0);
const planeVisualization = plane.createPlaneVisualization(size, (totalLayers || 0), this.getGeometry(size, horizontalAngle, verticalAngle));
if(planeVisualization)
{
Randomizer.setSeed(randomNumber);
let layerId = 0;
while(layerId < totalLayers)
{
const layer = visualization.allLayers[layerId];
if(layer)
{
if((layer as IAssetPlaneVisualizationAnimatedLayer).items === undefined)
{
const basicLayer = (layer as IAssetPlaneVisualizationLayer);
let material: PlaneMaterial = null;
let align: number = PlaneVisualizationLayer.ALIGN_DEFAULT;
let color: number = LandscapePlane.DEFAULT_COLOR;
let offset: number = PlaneVisualizationLayer.DEFAULT_OFFSET;
if(basicLayer.materialId) material = this.getMaterial(basicLayer.materialId);
if(basicLayer.color) color = basicLayer.color;
if(basicLayer.offset) offset = basicLayer.offset;
if(basicLayer.align)
{
if(basicLayer.align === 'bottom')
{
align = PlaneVisualizationLayer.ALIGN_BOTTOM;
}
else if(basicLayer.align === 'top') align = PlaneVisualizationLayer.ALIGN_TOP;
}
planeVisualization.setLayer(layerId, material, color, align, offset);
}
else
{
const animatedLayer = (layer as IAssetPlaneVisualizationAnimatedLayer);
const items = animatedLayer.items;
const animationItems: {}[] = [];
if(items && items.length)
{
for(const item of items)
{
if(item)
{
const id = item.id;
const assetId = item.assetId;
const x = this.getCoordinateValue(item.x || '', item.randomX || '');
const y = this.getCoordinateValue(item.y || '', item.randomY || '');
const speedX = item.speedX;
const speedY = item.speedY;
animationItems.push({
asset: assetId,
x,
y,
speedX,
speedY
});
}
}
}
planeVisualization.setAnimationLayer(layerId, animationItems, this.assetCollection);
}
layerId++;
}
}
}
}
if(!this.addPlane(id, plane)) plane.dispose();
}
}
private getCoordinateValue(x: string, randomX: string): number
{
let _local_3 = 0;
if((x.length > 0))
{
if(x.charAt((x.length - 1)) === '%')
{
x = x.substr(0, (x.length - 1));
_local_3 = (parseFloat(x) / 100);
}
}
if((randomX.length > 0))
{
const _local_4 = 10000;
const _local_5 = Randomizer.getValues(1, 0, _local_4);
const _local_6 = (_local_5[0] / _local_4);
if(randomX.charAt((randomX.length - 1)) === '%')
{
randomX = randomX.substr(0, (randomX.length - 1));
_local_3 = (_local_3 + ((_local_6 * parseFloat(randomX)) / 100));
}
}
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
{
let plane = this.getPlane(id) as LandscapePlane;
if(!plane) plane = this.getPlane(LandscapeRasterizer.DEFAULT) as LandscapePlane;
if(!plane) return null;
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))
{
graphic = TextureUtils.generateTexture(new Sprite(graphic.source));
if(!graphic) return null;
}
let planeBitmapData: PlaneBitmapData = null;
if(!plane.isStatic(scale) && (LandscapeRasterizer.UPDATE_INTERVAL > 0))
{
planeBitmapData = new PlaneBitmapData(graphic, ((Math.round((timeSinceStartMs / LandscapeRasterizer.UPDATE_INTERVAL)) * LandscapeRasterizer.UPDATE_INTERVAL) + LandscapeRasterizer.UPDATE_INTERVAL));
}
else
{
planeBitmapData = new PlaneBitmapData(graphic, -1);
}
return planeBitmapData;
}
public getTextureIdentifier(k: number, _arg_2: IVector3D): string
{
if(_arg_2)
{
if(_arg_2.x < 0) return (k + '_0');
return (k + '_1');
}
return super.getTextureIdentifier(k, _arg_2);
}
}

View File

@ -1,120 +0,0 @@
import { IDisposable, IGraphicAssetCollection, IVector3D } from '@nitrots/api';
import { TextureUtils } from '@nitrots/utils';
import { Sprite, Texture } from 'pixi.js';
import { AnimationItem } from './AnimationItem';
export class PlaneVisualizationAnimationLayer implements IDisposable
{
private _color: number = 0;
private _isDisposed: boolean = false;
private _items: AnimationItem[];
constructor(k: any, assets: IGraphicAssetCollection)
{
this._color = 0;
this._isDisposed = false;
this._items = [];
if(k && assets)
{
for(const item of k)
{
if(!item) continue;
const assetName = item.asset;
if(assetName)
{
const asset = assets.getAsset(assetName);
if(asset) this._items.push(new AnimationItem(item.x, item.y, item.speedX, item.speedY, asset));
}
}
}
}
public get disposed(): boolean
{
return this._isDisposed;
}
public dispose(): void
{
this._isDisposed = true;
if(this._items)
{
for(const item of this._items) item && item.dispose();
this._items = [];
}
}
public clearCache(): void
{
}
public render(canvas: Texture, width: number, height: number, normal: IVector3D, offsetX: number, offsetY: number, maxX: number, maxY: number, dimensionX: number, dimensionY: number, timeSinceStartMs: number): Texture
{
if(((maxX > 0) && (maxY > 0)))
{
let index = 0;
while(index < this._items.length)
{
const item = (this._items[index] as AnimationItem);
if(item)
{
const point = item.getPosition(maxX, maxY, dimensionX, dimensionY, timeSinceStartMs);
point.x = Math.trunc(point.x - offsetX);
point.y = Math.trunc(point.y - offsetY);
if(item.bitmapData)
{
if((point.x > -(item.bitmapData.width)) && (point.x < canvas.width) && (point.y > -(item.bitmapData.height)) && (point.y < canvas.height))
{
const sprite = new Sprite(item.bitmapData.texture);
sprite.position.set(point.x, point.y);
TextureUtils.writeToTexture(sprite, canvas, false);
}
if(((point.x - maxX) > -(item.bitmapData.width)) && ((point.x - maxX) < canvas.width) && (point.y > -(item.bitmapData.height)) && (point.y < canvas.height))
{
const sprite = new Sprite(item.bitmapData.texture);
sprite.position.set((point.x - maxX), point.y);
TextureUtils.writeToTexture(sprite, canvas, false);
}
if((point.x > -(item.bitmapData.width)) && (point.x < 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, (point.y - maxY));
TextureUtils.writeToTexture(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))
{
const sprite = new Sprite(item.bitmapData.texture);
sprite.position.set((point.x - maxX), (point.y - maxY));
TextureUtils.writeToTexture(sprite, canvas, false);
}
}
}
index++;
}
}
return canvas;
}
}

View File

@ -1,4 +0,0 @@
export * from './AnimationItem';
export * from './LandscapePlane';
export * from './LandscapeRasterizer';
export * from './PlaneVisualizationAnimationLayer';

View File

@ -1,38 +0,0 @@
import { IVector3D } from '@nitrots/api';
import { Vector3d } from '@nitrots/utils';
import { Texture } from 'pixi.js';
import { Plane } from './Plane';
export class FloorPlane extends Plane
{
public static DEFAULT_COLOR: number = 0xFFFFFF;
public static HORIZONTAL_ANGLE_DEFAULT: number = 45;
public static VERTICAL_ANGLE_DEFAULT: number = 30;
public render(planeId: string, canvas: Texture, width: number, height: number, scale: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number): Texture
{
const visualization = this.getPlaneVisualization(scale);
if(!visualization || !visualization.geometry) return null;
const _local_10 = visualization.geometry.getScreenPoint(new Vector3d(0, 0, 0));
const _local_11 = visualization.geometry.getScreenPoint(new Vector3d(0, (height / visualization.geometry.scale), 0));
const _local_12 = visualization.geometry.getScreenPoint(new Vector3d((width / visualization.geometry.scale), 0, 0));
let x = 0;
let y = 0;
if(_local_10 && _local_11 && _local_12)
{
width = Math.round(Math.abs((_local_10.x - _local_12.x)));
height = Math.round(Math.abs((_local_10.x - _local_11.x)));
const _local_15 = (_local_10.x - visualization.geometry.getScreenPoint(new Vector3d(1, 0, 0)).x);
x = (offsetX * Math.trunc(Math.abs(_local_15)));
y = (offsetY * Math.trunc(Math.abs(_local_15)));
}
return visualization.render(planeId, canvas, width, height, normal, useTexture, x, y);
}
}

View File

@ -1,60 +0,0 @@
import { IAssetPlane, IVector3D } from '@nitrots/api';
import { TextureUtils } from '@nitrots/utils';
import { RenderTexture } from 'pixi.js';
import { PlaneBitmapData } from '../../utils';
import { FloorPlane } from './FloorPlane';
import { PlaneRasterizer } from './PlaneRasterizer';
export class FloorRasterizer extends PlaneRasterizer
{
protected initializePlanes(): void
{
if(!this.data) return;
const floors = this.data.planes;
if(floors && floors.length) this.parseFloors(floors);
}
private parseFloors(k: IAssetPlane[]): void
{
if(!k) return;
for(const floorIndex in k)
{
const floor = k[floorIndex];
if(!floor) continue;
const id = floor.id;
const visualization = floor.visualizations;
const plane = new FloorPlane();
this.parseVisualizations(plane, visualization);
if(!this.addPlane(id, plane)) plane.dispose();
}
}
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;
if(!plane) plane = this.getPlane(PlaneRasterizer.DEFAULT) as FloorPlane;
if(!plane) return null;
if(canvas) TextureUtils.clearAndFillRenderTexture(canvas);
let graphic = plane.render(planeId, canvas, width, height, scale, normal, useTexture, offsetX, offsetY);
if(graphic && (graphic !== canvas))
{
graphic = new RenderTexture(graphic.source);
if(!graphic) return null;
}
return new PlaneBitmapData(graphic, -1);
}
}

View File

@ -1,112 +0,0 @@
import { IRoomGeometry } from '@nitrots/api';
import { PlaneVisualization } from './PlaneVisualization';
import { PlaneVisualizationLayer } from './PlaneVisualizationLayer';
export class Plane
{
private _planeVisualizations: Map<string, PlaneVisualization>;
private _sizes: number[];
private _lastPlaneVisualization: PlaneVisualization;
private _lastSize: number;
constructor()
{
this._planeVisualizations = new Map();
this._sizes = [];
this._lastPlaneVisualization = null;
this._lastSize = -1;
}
public isStatic(size: number): boolean
{
return true;
}
public dispose(): void
{
for(const visualization of this._planeVisualizations.values())
{
if(!visualization) continue;
visualization.dispose();
}
this._planeVisualizations = null;
this._lastPlaneVisualization = null;
this._sizes = null;
this._lastSize = -1;
}
public clearCache(): void
{
for(const visualization of this._planeVisualizations.values())
{
if(!visualization) continue;
visualization.clearCache();
}
}
public createPlaneVisualization(size: number, totalLayers: number, geometry: IRoomGeometry): PlaneVisualization
{
const existing = this._planeVisualizations.get(size.toString());
if(existing) return null;
const plane = new PlaneVisualization(size, totalLayers, geometry);
this._planeVisualizations.set(size.toString(), plane);
this._sizes.push(size);
this._sizes.sort();
return plane;
}
private getSizeIndex(size: number): number
{
let sizeIndex = 0;
let i = 1;
while(i < this._sizes.length)
{
if(this._sizes[i] > size)
{
if((this._sizes[i] - size) < (size - this._sizes[(i - 1)])) sizeIndex = i;
break;
}
sizeIndex = i;
i++;
}
return sizeIndex;
}
public getPlaneVisualization(size: number): PlaneVisualization
{
if(size === this._lastSize) return this._lastPlaneVisualization;
const sizeIndex = this.getSizeIndex(size);
if(sizeIndex < this._sizes.length)
{
this._lastPlaneVisualization = this._planeVisualizations.get(this._sizes[sizeIndex].toString());
}
else
{
this._lastPlaneVisualization = null;
}
this._lastSize = size;
return this._lastPlaneVisualization;
}
public getLayers(): PlaneVisualizationLayer[]
{
return this.getPlaneVisualization(this._lastSize).getLayers();
}
}

View File

@ -1,93 +0,0 @@
import { IVector3D } from '@nitrots/api';
import { Texture } from 'pixi.js';
import { PlaneMaterialCellMatrix } from './PlaneMaterialCellMatrix';
export class PlaneMaterial
{
public static MIN_NORMAL_COORDINATE_VALUE: number = -1;
public static MAX_NORMAL_COORDINATE_VALUE: number = 1;
private _planeMaterialItems: PlaneMaterialCellMatrix[];
private _isCached: boolean;
constructor()
{
this._planeMaterialItems = [];
this._isCached = false;
}
public dispose(): void
{
if(this._planeMaterialItems && this._planeMaterialItems.length)
{
for(const item of this._planeMaterialItems)
{
if(!item) continue;
item.dispose();
}
this._planeMaterialItems = null;
}
this._isCached = false;
}
public clearCache(): void
{
if(!this._isCached) return;
if(this._planeMaterialItems && this._planeMaterialItems.length)
{
for(const item of this._planeMaterialItems)
{
if(!item) continue;
item.clearCache();
}
}
this._isCached = false;
}
public addMaterialCellMatrix(totalColumns: number, repeatMode: number, align: number, normalMinX: number = -1, normalMaxX: number = 1, normalMinY: number = -1, normalMaxY: number = 1): PlaneMaterialCellMatrix
{
const cellMatrix = new PlaneMaterialCellMatrix(totalColumns, repeatMode, align, normalMinX, normalMaxX, normalMinY, normalMaxY);
this._planeMaterialItems.push(cellMatrix);
return cellMatrix;
}
public getMaterialCellMatrix(normal: IVector3D): PlaneMaterialCellMatrix
{
if(!normal) return null;
if(this._planeMaterialItems && this._planeMaterialItems.length)
{
for(const item of this._planeMaterialItems)
{
if(!item) continue;
if((((normal.x >= item.normalMinX) && (normal.x <= item.normalMaxX)) && (normal.y >= item.normalMinY)) && (normal.y <= item.normalMaxY)) return item;
}
}
return null;
}
public render(planeId: string, canvas: Texture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): Texture
{
if(width < 1) width = 1;
if(height < 1) height = 1;
const cellMatrix = this.getMaterialCellMatrix(normal);
if(!cellMatrix) return null;
this._isCached = true;
return cellMatrix.render(planeId, canvas, width, height, normal, useTexture, offsetX, offsetY, topAlign);
}
}

View File

@ -1,195 +0,0 @@
import { IGraphicAsset, IVector3D } from '@nitrots/api';
import { Container, Matrix, Point, Sprite, TilingSprite } from 'pixi.js';
import { Randomizer } from '../../utils';
import { PlaneTexture } from './PlaneTexture';
export class PlaneMaterialCell
{
private _texture: PlaneTexture;
private _extraItemOffsets: Point[];
private _extraItemAssets: IGraphicAsset[];
private _extraItemCount: number = 0;
constructor(texture: PlaneTexture, assets: IGraphicAsset[] = null, offsetPoints: Point[] = null, limit: number = 0)
{
this._texture = texture;
this._extraItemOffsets = [];
this._extraItemAssets = [];
this._extraItemCount = 0;
if(assets && assets.length && (limit > 0))
{
let assetIndex = 0;
while(assetIndex < assets.length)
{
const graphic = assets[assetIndex];
if(graphic) this._extraItemAssets.push(graphic);
assetIndex++;
}
if(this._extraItemAssets.length)
{
if(offsetPoints)
{
let pointIndex = 0;
while(pointIndex < offsetPoints.length)
{
const point = offsetPoints[pointIndex];
if(point) this._extraItemOffsets.push(new Point(point.x, point.y));
pointIndex++;
}
}
this._extraItemCount = limit;
}
}
}
public get isStatic(): boolean
{
return this._extraItemCount === 0;
}
public dispose(): void
{
if(this._texture)
{
this._texture.dispose();
this._texture = null;
}
this._extraItemAssets = null;
this._extraItemOffsets = null;
this._extraItemCount = 0;
}
public clearCache(): void
{
}
public getHeight(normal: IVector3D): number
{
if(this._texture)
{
const texture = this._texture.getBitmap(normal);
if(texture) return texture.height;
}
return 0;
}
public render(normal: IVector3D, textureOffsetX: number, textureOffsetY: number): Container
{
if(!this._texture) return null;
const texture = this._texture.getBitmap(normal);
if(!texture) return null;
const bitmap = new TilingSprite({
texture,
width: texture.width,
height: texture.height
});
if((textureOffsetX !== 0) || (textureOffsetY !== 0))
{
while(textureOffsetX < 0) textureOffsetX += texture.width;
while(textureOffsetY < 0) textureOffsetY += texture.height;
bitmap.tilePosition.set((textureOffsetX % texture.width), (textureOffsetY % texture.height));
//bitmap.uvRespectAnchor = true;
if(textureOffsetX)
{
//bitmap.anchor.x = 1;
bitmap.tileScale.x = -1;
}
if(textureOffsetY)
{
//bitmap.anchor.y = 1;
bitmap.tileScale.y = -1;
}
}
if(!this.isStatic)
{
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)
{
let itemOffsetX = item.offsetX;
let itemOffsetY = item.offsetY;
let x = 1;
let y = 1;
let translateX = 0;
let translateY = 0;
if(item.flipH)
{
x = -1;
translateX = assetTexture.width;
itemOffsetX = -(item.width + item.x);
}
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.setFromMatrix(flipMatrix);
bitmap.addChild(sprite);
}
}
i++;
}
}
return bitmap;
}
public getAssetName(normal: IVector3D): string
{
return (this._texture == null) ? null : this._texture.getAssetName(normal);
}
}

View File

@ -1,457 +0,0 @@
import { IVector3D } from '@nitrots/api';
import { TextureUtils, Vector3d } from '@nitrots/utils';
import { Texture } from 'pixi.js';
import { PlaneMaterialCell } from './PlaneMaterialCell';
export class PlaneMaterialCellColumn
{
public static REPEAT_MODE_NONE: number = 0;
public static REPEAT_MODE_ALL: number = 1;
public static REPEAT_MODE_BORDERS: number = 2;
public static REPEAT_MODE_CENTER: number = 3;
public static REPEAT_MODE_FIRST: number = 4;
public static REPEAT_MODE_LAST: number = 5;
private _cells: PlaneMaterialCell[];
private _repeatMode: number;
private _width: number;
private _cachedBitmapData: Texture;
private _cachedBitmapNormal: IVector3D;
private _cachedBitmapDataOffsetX: number;
private _cachedBitmapDataOffsetY: number;
private _isCached: boolean;
private _isStatic: boolean;
constructor(width: number, cells: PlaneMaterialCell[], repeatMode: number = 1)
{
this._cells = [];
this._repeatMode = repeatMode;
this._width = (width < 1) ? 1 : width;
this._cachedBitmapData = null;
this._cachedBitmapNormal = null;
this._cachedBitmapDataOffsetX = 0;
this._cachedBitmapDataOffsetY = 0;
this._isCached = false;
this._isStatic = true;
if(cells && cells.length)
{
let cellIndex = 0;
while(cellIndex < cells.length)
{
const cell = cells[cellIndex];
if(cell)
{
this._cells.push(cell);
if(!cell.isStatic) this._isStatic = false;
}
cellIndex++;
}
}
}
public get isStatic(): boolean
{
return this._isStatic;
}
public isRepeated(): boolean
{
return !(this._repeatMode === PlaneMaterialCellColumn.REPEAT_MODE_NONE);
}
public get width(): number
{
return this._width;
}
public dispose(): void
{
if(this._cells && this._cells.length)
{
for(const cell of this._cells)
{
if(!cell) continue;
cell.dispose();
}
this._cells = null;
}
this._cachedBitmapData = null;
if(this._cachedBitmapNormal) this._cachedBitmapNormal = null;
}
public clearCache(): void
{
if(!this._isCached) return;
if(this._cachedBitmapData) this._cachedBitmapData = null;
if(this._cachedBitmapNormal)
{
this._cachedBitmapNormal.x = 0;
this._cachedBitmapNormal.y = 0;
this._cachedBitmapNormal.z = 0;
}
if(this._cells && this._cells.length)
{
for(const cell of this._cells)
{
if(!cell) continue;
cell.clearCache();
}
}
this._isCached = false;
}
public render(planeId: string, height: number, normal: IVector3D, offsetX: number, offsetY: number): Texture
{
if(this._repeatMode === PlaneMaterialCellColumn.REPEAT_MODE_NONE) height = this.getCellsHeight(this._cells, normal);
if(!this._cachedBitmapNormal) this._cachedBitmapNormal = new Vector3d();
if(this.isStatic)
{
if(this._cachedBitmapData)
{
if((this._cachedBitmapData.height === height) && Vector3d.isEqual(this._cachedBitmapNormal, normal) && (this._cachedBitmapDataOffsetX === offsetX) && (this._cachedBitmapDataOffsetY === offsetY))
{
return this._cachedBitmapData;
}
else
{
this._cachedBitmapData = null;
}
}
}
else
{
this._cachedBitmapData = null;
}
this._isCached = true;
if(!this._cachedBitmapData)
{
this._cachedBitmapData = TextureUtils.createRenderTexture(this._width, height);
}
this._cachedBitmapNormal.assign(normal);
this._cachedBitmapDataOffsetX = offsetX;
this._cachedBitmapDataOffsetY = offsetY;
if(!this._cells.length) return this._cachedBitmapData;
switch(this._repeatMode)
{
case PlaneMaterialCellColumn.REPEAT_MODE_NONE:
this.renderRepeatNone(normal);
break;
case PlaneMaterialCellColumn.REPEAT_MODE_BORDERS:
this.renderRepeatBorders(normal);
break;
case PlaneMaterialCellColumn.REPEAT_MODE_CENTER:
this.renderRepeatCenter(normal);
break;
case PlaneMaterialCellColumn.REPEAT_MODE_FIRST:
this.renderRepeatFirst(normal);
break;
case PlaneMaterialCellColumn.REPEAT_MODE_LAST:
this.renderRepeatLast(normal);
break;
default:
this.renderRepeatAll(normal, offsetX, offsetY);
break;
}
return this._cachedBitmapData;
}
private getCellsHeight(cells: PlaneMaterialCell[], normal: IVector3D): number
{
if(!cells || !cells.length) return 0;
let height = 0;
let cellIterator = 0;
while(cellIterator < cells.length)
{
const cell = cells[cellIterator];
if(cell) height += cell.getHeight(normal);
cellIterator++;
}
return height;
}
private renderCells(cells: PlaneMaterialCell[], index: number, flag: boolean, normal: IVector3D, offsetX: number = 0, offsetY: number = 0): number
{
if(((!cells || !cells.length) || !this._cachedBitmapData)) return index;
let cellIndex = 0;
while(cellIndex < cells.length)
{
let cell: PlaneMaterialCell = null;
if(flag)
{
cell = cells[cellIndex];
}
else
{
cell = cells[((cells.length - 1) - cellIndex)];
}
if(cell)
{
const graphic = cell.render(normal, offsetX, offsetY);
if(graphic)
{
if(!flag) index -= graphic.height;
graphic.y = index;
TextureUtils.writeToTexture(graphic, this._cachedBitmapData, false);
if(flag) index = (index + graphic.height);
if(((flag) && (index >= this._cachedBitmapData.height)) || ((!(flag)) && (index <= 0))) return index;
}
}
cellIndex++;
}
return index;
}
private renderRepeatNone(normal: IVector3D): void
{
if(!this._cells.length || !this._cachedBitmapData) return;
this.renderCells(this._cells, 0, true, normal);
}
private renderRepeatAll(normal: IVector3D, offsetX: number, offsetY: number): void
{
if(!this._cells.length || !this._cachedBitmapData) return;
let index = 0;
while(index < this._cachedBitmapData.height)
{
index = this.renderCells(this._cells, index, true, normal, offsetX, offsetY);
if(!index) return;
}
}
private renderRepeatBorders(k:IVector3D): void
{
if(!this._cells.length || !this._cachedBitmapData) return;
const _local_4: PlaneMaterialCell[] = [];
let _local_5 = 0;
let _local_7 = 1;
while(_local_7 < (this._cells.length - 1))
{
const cell = (this._cells[_local_7] as PlaneMaterialCell);
if(cell)
{
const height = cell.getHeight(k);
if(height > 0)
{
_local_5 = (_local_5 + height);
_local_4.push(cell);
}
}
_local_7++;
}
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[]
{
return this._cells;
}
}

View File

@ -1,655 +0,0 @@
import { IVector3D } from '@nitrots/api';
import { NitroLogger, TextureUtils, Vector3d } from '@nitrots/utils';
import { Point, Rectangle, RenderTexture, Sprite, Texture } from 'pixi.js';
import { Randomizer } from '../../utils';
import { PlaneMaterialCell } from './PlaneMaterialCell';
import { PlaneMaterialCellColumn } from './PlaneMaterialCellColumn';
export class PlaneMaterialCellMatrix
{
public static REPEAT_MODE_ALL: number = 1;
public static REPEAT_MODE_BORDERS: number = 2;
public static REPEAT_MODE_CENTER: number = 3;
public static REPEAT_MODE_FIRST: number = 4;
public static REPEAT_MODE_LAST: number = 5;
public static REPEAT_MODE_RANDOM: number = 6;
public static REPEAT_MODE_DEFAULT: number = PlaneMaterialCellMatrix.REPEAT_MODE_ALL;//1
public static MIN_NORMAL_COORDINATE_VALUE: number = -1;
public static MAX_NORMAL_COORDINATE_VALUE: number = 1;
public static ALIGN_TOP: number = 1;
public static ALIGN_BOTTOM: number = 2;
public static ALIGN_DEFAULT: number = PlaneMaterialCellMatrix.ALIGN_TOP;//1
private _columns: PlaneMaterialCellColumn[];
private _repeatMode: number = 1;
private _align: number = 1;
private _cachedBitmapData: Texture;
private _cachedBitmapNormal: IVector3D = null;
private _cachedBitmapHeight: number = 0;
private _isCached: boolean = false;
private _isStatic: boolean = true;
private _normalMinX: number = -1;
private _normalMaxX: number = 1;
private _normalMinY: number = -1;
private _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 = [];
if(totalColumns < 1) totalColumns = 1;
let _local_8 = 0;
while(_local_8 < totalColumns)
{
this._columns.push(null);
_local_8++;
}
this._repeatMode = repeatMode;
this._align = align;
this._normalMinX = normalMinX;
this._normalMaxX = normalMaxX;
this._normalMinY = normalMinY;
this._normalMaxY = normalMaxY;
if(this._repeatMode === PlaneMaterialCellMatrix.REPEAT_MODE_RANDOM) this._isStatic = false;
}
private static nextRandomColumnIndex(totalColumns: number): number
{
const _local_2 = Randomizer.getValues(1, 0, (totalColumns * 17631));
return _local_2[0] % totalColumns;
}
public get normalMinX(): number
{
return this._normalMinX;
}
public get normalMaxX(): number
{
return this._normalMaxX;
}
public get normalMinY(): number
{
return this._normalMinY;
}
public get normalMaxY(): number
{
return this._normalMaxY;
}
public isBottomAligned(): boolean
{
return this._align === PlaneMaterialCellMatrix.ALIGN_BOTTOM;
}
public get isStatic(): boolean
{
return this._isStatic;
}
public dispose(): void
{
if(this._cachedBitmapNormal) this._cachedBitmapNormal = null;
}
public clearCache(): void
{
if(!this._isCached) return;
if(this._cachedBitmapNormal)
{
this._cachedBitmapNormal.x = 0;
this._cachedBitmapNormal.y = 0;
this._cachedBitmapNormal.z = 0;
}
if(this._columns && this._columns.length)
{
for(const column of this._columns)
{
if(!column) continue;
column.clearCache();
}
}
this._isCached = false;
}
public createColumn(index: number, width: number, cells: PlaneMaterialCell[], repeatMode: number = 1): boolean
{
if((index < 0) || (index >= this._columns.length)) return false;
const newColumn = new PlaneMaterialCellColumn(width, cells, repeatMode);
const oldColumn = this._columns[index];
if(oldColumn) oldColumn.dispose();
this._columns[index] = newColumn;
if(newColumn && !newColumn.isStatic) this._isStatic = false;
return true;
}
public render(planeId: string, canvas: Texture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number, topAlign: boolean): Texture
{
if(width < 1) width = 1;
if(height < 1) height = 1;
if(!this._cachedBitmapNormal) this._cachedBitmapNormal = new Vector3d();
if(this.isStatic)
{
if(this._cachedBitmapData)
{
if(this._cachedBitmapData.source && (this._cachedBitmapData.width === width) && (this._cachedBitmapData.height === height) && Vector3d.isEqual(this._cachedBitmapNormal, normal))
{
if(canvas)
{
this.copyCachedBitmapOnCanvas(canvas, this._cachedBitmapHeight, offsetY, topAlign);
return canvas;
}
return this._cachedBitmapData;
}
this._cachedBitmapData = null;
}
}
else
{
this._cachedBitmapData = null;
}
this._isCached = true;
this._cachedBitmapNormal.assign(normal);
if(!useTexture)
{
this._cachedBitmapHeight = height;
if(!this._cachedBitmapData)
{
this._cachedBitmapData = TextureUtils.createAndFillRenderTexture(width, height);
}
else
{
TextureUtils.clearAndFillRenderTexture(this._cachedBitmapData);
}
return this._cachedBitmapData;
}
if(!this._cachedBitmapData)
{
this._cachedBitmapHeight = height;
this._cachedBitmapData = TextureUtils.createRenderTexture(width, height);
TextureUtils.clearRenderTexture(this._cachedBitmapData);
}
const columns: Texture[] = [];
let columnIndex = 0;
while(columnIndex < this._columns.length)
{
const column = this._columns[columnIndex];
if(column)
{
const columnBitmapData = column.render(planeId, height, normal, offsetX, offsetY);
if(columnBitmapData) columns.push(columnBitmapData);
}
columnIndex++;
}
if(!columns.length)
{
if(canvas) return canvas;
return this._cachedBitmapData;
}
let maxColumnHeight = 0;
switch(this._repeatMode)
{
case PlaneMaterialCellMatrix.REPEAT_MODE_BORDERS:
NitroLogger.log('REPEAT_MODE_BORDERS');
// maxColumnHeight = this.renderRepeatBorders(this._cachedBitmapData, columns);
break;
case PlaneMaterialCellMatrix.REPEAT_MODE_CENTER:
NitroLogger.log('REPEAT_MODE_CENTER');
// maxColumnHeight = this.renderRepeatCenter(this._cachedBitmapData, columns);
break;
case PlaneMaterialCellMatrix.REPEAT_MODE_FIRST:
NitroLogger.log('REPEAT_MODE_FIRST');
// maxColumnHeight = this.renderRepeatFirst(this._cachedBitmapData, columns);
break;
case PlaneMaterialCellMatrix.REPEAT_MODE_LAST:
NitroLogger.log('REPEAT_MODE_LAST');
// maxColumnHeight = this.renderRepeatLast(this._cachedBitmapData, columns);
break;
case PlaneMaterialCellMatrix.REPEAT_MODE_RANDOM:
maxColumnHeight = this.renderRepeatRandom(this._cachedBitmapData, columns);
break;
default:
maxColumnHeight = this.renderRepeatAll(this._cachedBitmapData, columns);
break;
}
this._cachedBitmapHeight = maxColumnHeight;
if(canvas)
{
this.copyCachedBitmapOnCanvas(canvas, maxColumnHeight, offsetY, topAlign);
return canvas;
}
return this._cachedBitmapData;
}
private copyCachedBitmapOnCanvas(canvas: Texture, height: number, offsetY: number, topAlign: boolean): void
{
if(!canvas || !this._cachedBitmapData || (canvas === this._cachedBitmapData)) return;
if(!topAlign) offsetY = ((canvas.height - height) - offsetY);
let bounds: Rectangle = null;
if(this._align === PlaneMaterialCellMatrix.ALIGN_TOP)
{
bounds = new Rectangle(0, 0, this._cachedBitmapData.width, this._cachedBitmapHeight);
}
else
{
bounds = new Rectangle(0, (this._cachedBitmapData.height - this._cachedBitmapHeight), this._cachedBitmapData.width, this._cachedBitmapHeight);
}
const texture = new RenderTexture({
source: this._cachedBitmapData.source,
frame: bounds
});
const sprite = new Sprite(texture);
sprite.position.set(0, offsetY);
TextureUtils.writeToTexture(sprite, canvas, false);
}
private getColumnsWidth(columns: Texture[]): number
{
if(!columns || !columns.length) return 0;
let width = 0;
for(const texture of columns)
{
if(!texture) continue;
width += texture.width;
}
return width;
}
private renderColumns(canvas: Texture, columns: Texture[], x: number, flag: boolean): Point
{
if(!canvas || !columns || !columns.length) return new Point(x, 0);
let height = 0;
let i = 0;
while(i < columns.length)
{
const column = flag ? columns[i] : columns[((columns.length - 1) - i)];
if(column)
{
if(!flag) x = (x - column.width);
let y = 0;
if(this._align == PlaneMaterialCellMatrix.ALIGN_BOTTOM) y = (canvas.height - column.height);
const sprite = new Sprite(column);
sprite.position.set(x, y);
TextureUtils.writeToTexture(sprite, canvas, false);
if(column.height > height) height = column.height;
if(flag) x = (x + column.width);
if((flag && (x >= canvas.width)) || (!flag && (x <= 0))) return new Point(x, height);
}
i++;
}
return new Point(x, height);
}
private renderRepeatAll(canvas: Texture, columns: Texture[]): number
{
if(!canvas || !columns || !columns.length) return 0;
const totalWidth: number = this.getColumnsWidth(columns);
let x = 0;
let y = 0;
while(x < canvas.width)
{
const point = this.renderColumns(canvas, columns, x, true);
x = point.x;
if(point.y > y) y = point.y;
if(!point.x) return y;
}
return y;
}
// private renderRepeatBorders(k:BitmapData, _arg_2:Array): number
// {
// if ((((_arg_2 == null) || (_arg_2.length == 0)) || (k == null)))
// {
// return 0;
// }
// var _local_3: number;
// var _local_4:BitmapData;
// var _local_5:Array = [];
// var _local_6: number;
// var _local_7: number;
// _local_7 = 1;
// while (_local_7 < (_arg_2.length - 1))
// {
// _local_4 = (_arg_2[_local_7] as BitmapData);
// if (_local_4 != null)
// {
// _local_6 = (_local_6 + _local_4.width);
// _local_5.push(_local_4);
// }
// _local_7++;
// }
// if (this._columns.length == 1)
// {
// _local_4 = (this._columns[0] as BitmapData);
// if (_local_4 != null)
// {
// _local_6 = _local_4.width;
// _local_5.push(_local_4);
// }
// }
// var _local_8:* = ((k.width - _local_6) >> 1);
// var _local_9:Point;
// _local_9 = this.renderColumns(k, _local_5, _local_8, true);
// var _local_10: number = _local_9.x;
// if (_local_9.y > _local_3)
// {
// _local_3 = _local_9.y;
// }
// _local_4 = (_arg_2[0] as BitmapData);
// if (_local_4 != null)
// {
// _local_5 = [_local_4];
// while (_local_8 >= 0)
// {
// _local_9 = this.renderColumns(k, _local_5, _local_8, false);
// _local_8 = _local_9.x;
// if (_local_9.y > _local_3)
// {
// _local_3 = _local_9.y;
// }
// }
// }
// _local_4 = (_arg_2[(_arg_2.length - 1)] as BitmapData);
// if (_local_4 != null)
// {
// _local_5 = [_local_4];
// while (_local_10 < k.height)
// {
// _local_9 = this.renderColumns(k, _local_5, _local_10, true);
// _local_10 = _local_9.x;
// if (_local_9.y > _local_3)
// {
// _local_3 = _local_9.y;
// }
// }
// }
// return _local_3;
// }
// private renderRepeatCenter(k:BitmapData, _arg_2:Array): number
// {
// var _local_14: number;
// var _local_15: number;
// var _local_16: number;
// var _local_17: number;
// var _local_18:Array;
// if ((((_arg_2 == null) || (_arg_2.length == 0)) || (k == null)))
// {
// return 0;
// }
// var _local_3: number;
// var _local_4:BitmapData;
// var _local_5:Array = [];
// var _local_6:Array = [];
// var _local_7: number;
// var _local_8: number;
// var _local_9: number;
// _local_9 = 0;
// while (_local_9 < (_arg_2.length >> 1))
// {
// _local_4 = (_arg_2[_local_9] as BitmapData);
// if (_local_4 != null)
// {
// _local_7 = (_local_7 + _local_4.width);
// _local_5.push(_local_4);
// }
// _local_9++;
// }
// _local_9 = ((_arg_2.length >> 1) + 1);
// while (_local_9 < _arg_2.length)
// {
// _local_4 = (_arg_2[_local_9] as BitmapData);
// if (_local_4 != null)
// {
// _local_8 = (_local_8 + _local_4.width);
// _local_6.push(_local_4);
// }
// _local_9++;
// }
// var _local_10:Point;
// var _local_11: number;
// var _local_12: number;
// var _local_13: number = k.width;
// if ((_local_7 + _local_8) > k.width)
// {
// _local_11 = ((_local_7 + _local_8) - k.width);
// _local_12 = (_local_12 - (_local_11 >> 1));
// _local_13 = (_local_13 + (_local_11 - (_local_11 >> 1)));
// }
// if (_local_11 == 0)
// {
// _local_4 = (_arg_2[(_arg_2.length >> 1)] as BitmapData);
// if (_local_4 != null)
// {
// _local_14 = _local_4.width;
// _local_15 = (k.width - (_local_7 + _local_8));
// _local_16 = (Math.ceil((_local_15 / _local_14)) * _local_14);
// _local_12 = (_local_7 - ((_local_16 - _local_15) >> 1));
// _local_17 = (_local_12 + _local_16);
// _local_18 = [_local_4];
// while (_local_12 < _local_17)
// {
// _local_10 = this.renderColumns(k, _local_18, _local_12, true);
// _local_12 = _local_10.x;
// if (_local_10.y > _local_3)
// {
// _local_3 = _local_10.y;
// }
// }
// }
// }
// _local_12 = 0;
// _local_10 = this.renderColumns(k, _local_5, _local_12, true);
// if (_local_10.y > _local_3)
// {
// _local_3 = _local_10.y;
// }
// _local_10 = this.renderColumns(k, _local_6, _local_13, false);
// if (_local_10.y > _local_3)
// {
// _local_3 = _local_10.y;
// }
// return _local_3;
// }
// private renderRepeatFirst(k:BitmapData, _arg_2:Array): number
// {
// var _local_7:Array;
// if ((((_arg_2 == null) || (_arg_2.length == 0)) || (k == null)))
// {
// return 0;
// }
// var _local_3: number;
// var _local_4:BitmapData;
// var _local_5: number = k.width;
// var _local_6:Point = this.renderColumns(k, _arg_2, _local_5, false);
// _local_5 = _local_6.x;
// if (_local_6.y > _local_3)
// {
// _local_3 = _local_6.y;
// }
// _local_4 = (_arg_2[0] as BitmapData);
// if (_local_4 != null)
// {
// _local_7 = [_local_4];
// while (_local_5 >= 0)
// {
// _local_6 = this.renderColumns(k, _local_7, _local_5, false);
// _local_5 = _local_6.x;
// if (_local_6.y > _local_3)
// {
// _local_3 = _local_6.y;
// }
// }
// }
// return _local_3;
// }
// private renderRepeatLast(k:BitmapData, _arg_2:Array): number
// {
// var _local_7:Array;
// if ((((_arg_2 == null) || (_arg_2.length == 0)) || (k == null)))
// {
// return 0;
// }
// var _local_3: number;
// var _local_4:BitmapData;
// var _local_5: number;
// var _local_6:Point = this.renderColumns(k, _arg_2, _local_5, true);
// _local_5 = _local_6.x;
// if (_local_6.y > _local_3)
// {
// _local_3 = _local_6.y;
// }
// _local_4 = (_arg_2[(_arg_2.length - 1)] as BitmapData);
// if (_local_4 != null)
// {
// _local_7 = [_local_4];
// while (_local_5 < k.width)
// {
// _local_6 = this.renderColumns(k, _local_7, _local_5, true);
// _local_5 = _local_6.x;
// if (_local_6.y > _local_3)
// {
// _local_3 = _local_6.y;
// }
// }
// }
// return _local_3;
// }
private renderRepeatRandom(canvas: Texture, columns: Texture[]): number
{
if(!canvas || !columns || !columns.length) return 0;
let height = 0;
let width = 0;
while(width < canvas.width)
{
const column = columns[PlaneMaterialCellMatrix.nextRandomColumnIndex(columns.length)];
if(column != null)
{
const point = this.renderColumns(canvas, [ column ], width, true);
width = point.x;
if(point.y > height)
{
height = point.y;
}
}
else
{
return height;
}
}
return height;
}
public getColumns(width: number): PlaneMaterialCellColumn[]
{
if(this._repeatMode === PlaneMaterialCellMatrix.REPEAT_MODE_RANDOM)
{
const columns: PlaneMaterialCellColumn[] = [];
let columnIndex = 0;
while(columnIndex < width)
{
const column = this._columns[PlaneMaterialCellMatrix.nextRandomColumnIndex(this._columns.length)];
if(column)
{
columns.push(column);
if(column.width > 1) columnIndex += column.width;
else break;
}
else break;
}
return columns;
}
return this._columns;
}
}

View File

@ -1,598 +0,0 @@
import { IAssetPlaneMaterial, IAssetPlaneMaterialCellColumn, IAssetPlaneTexture, IAssetPlaneVisualization, IAssetPlaneVisualizationData, IAssetPlaneVisualizationLayer, IGraphicAsset, IGraphicAssetCollection, IRoomGeometry, IVector3D } from '@nitrots/api';
import { TextureUtils, Vector3d } from '@nitrots/utils';
import { Point, Texture } from 'pixi.js';
import { RoomGeometry } from '../../../../../utils';
import { PlaneBitmapData } from '../../utils';
import { IPlaneRasterizer } from '../IPlaneRasterizer';
import { FloorPlane } from './FloorPlane';
import { Plane } from './Plane';
import { PlaneMaterial } from './PlaneMaterial';
import { PlaneMaterialCell } from './PlaneMaterialCell';
import { PlaneMaterialCellColumn } from './PlaneMaterialCellColumn';
import { PlaneMaterialCellMatrix } from './PlaneMaterialCellMatrix';
import { PlaneTexture } from './PlaneTexture';
import { PlaneVisualizationLayer } from './PlaneVisualizationLayer';
export class PlaneRasterizer implements IPlaneRasterizer
{
protected static DEFAULT: string = 'default';
private _assetCollection: IGraphicAssetCollection;
private _materials: Map<string, PlaneMaterial>;
private _textures: Map<string, PlaneTexture>;
private _planes: Map<string, Plane>;
private _geometries: Map<string, RoomGeometry>;
private _data: IAssetPlaneVisualizationData;
constructor()
{
this._assetCollection = null;
this._textures = new Map();
this._materials = new Map();
this._planes = new Map();
this._geometries = new Map();
this._data = null;
}
protected get data(): IAssetPlaneVisualizationData
{
return this._data;
}
protected get assetCollection(): IGraphicAssetCollection
{
return this._assetCollection;
}
public initializeDimensions(k: number, _arg_2: number): boolean
{
return true;
}
public dispose(): void
{
if(this._planes)
{
for(const plane of this._planes.values())
{
if(!plane) continue;
plane.dispose();
}
this._planes = null;
}
if(this._materials)
{
this.resetMaterials();
this._materials = null;
}
if(this._textures)
{
this.resetTextures();
this._textures = null;
}
if(this._geometries)
{
for(const geometry of this._geometries.values())
{
if(!geometry) continue;
geometry.dispose();
}
this._geometries = null;
}
this._data = null;
this._assetCollection = null;
}
public clearCache(): void
{
for(const plane of this._planes.values())
{
if(!plane) continue;
plane.clearCache();
}
for(const material of this._materials.values())
{
if(!material) continue;
material.clearCache();
}
}
public initialize(data: IAssetPlaneVisualizationData): void
{
this._data = data;
}
public reinitialize(): void
{
this.resetTextures();
this.resetMaterials();
this.initializeAll();
}
private resetMaterials(): void
{
for(const material of this._materials.values())
{
if(!material) continue;
material.dispose();
}
this._materials.clear();
}
private resetTextures(): void
{
for(const texture of this._textures.values())
{
if(!texture) continue;
texture.dispose();
}
this._textures.clear();
}
protected getTexture(textureId: string): PlaneTexture
{
return this._textures.get(textureId);
}
protected getMaterial(materialId: string): PlaneMaterial
{
return this._materials.get(materialId);
}
protected getPlane(planeId: string): Plane
{
return this._planes.get(planeId);
}
protected addPlane(id: string, plane: Plane): boolean
{
if(!plane) return false;
const existing = this._planes.get(id);
if(!existing)
{
this._planes.set(id, plane);
return true;
}
return false;
}
public initializeAssetCollection(collection: IGraphicAssetCollection): void
{
if(!this._data) return;
this._assetCollection = collection;
this.initializeAll();
}
private initializeAll(): void
{
if(!this._data) return;
this.initializeTexturesAndMaterials();
this.initializePlanes();
}
private initializeTexturesAndMaterials(): void
{
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);
}
protected initializePlanes(): void
{
}
private parseTextures(textures: IAssetPlaneTexture[], collection: IGraphicAssetCollection): void
{
if(!textures || !collection) return;
if(textures.length)
{
for(const texture of textures)
{
if(!texture) continue;
const id = texture.id;
if(!this._textures.get(id))
{
const plane = new PlaneTexture();
if(texture.bitmaps && texture.bitmaps.length)
{
for(const bitmap of texture.bitmaps)
{
if(!bitmap) continue;
const assetName = bitmap.assetName;
let normalMinX = PlaneTexture.MIN_NORMAL_COORDINATE_VALUE;
let normalMaxX = PlaneTexture.MAX_NORMAL_COORDINATE_VALUE;
let normalMinY = PlaneTexture.MIN_NORMAL_COORDINATE_VALUE;
let normalMaxY = PlaneTexture.MAX_NORMAL_COORDINATE_VALUE;
if(bitmap.normalMinX !== undefined) normalMinX = bitmap.normalMinX;
if(bitmap.normalMaxX !== undefined) normalMaxX = bitmap.normalMaxX;
if(bitmap.normalMinY !== undefined) normalMinY = bitmap.normalMinY;
if(bitmap.normalMaxY !== undefined) normalMaxY = bitmap.normalMaxY;
const asset = collection.getAsset(assetName);
if(asset)
{
const texture = asset.texture;
if(texture)
{
let newTexture: Texture = texture;
if(asset.flipH) newTexture = TextureUtils.flipTextureHorizontal(texture);
plane.addBitmap(newTexture, normalMinX, normalMaxX, normalMinY, normalMaxY, assetName);
}
}
}
}
this._textures.set(id, plane);
}
}
}
}
private parsePlaneMaterials(materials: IAssetPlaneMaterial[]): void
{
if(!materials || !materials.length) return;
for(const material of materials)
{
if(!material) continue;
const id = material.id;
const newMaterial = new PlaneMaterial();
if(material.matrices && material.matrices.length)
{
for(const matrix of material.matrices)
{
if(!matrix) continue;
let repeatMode = PlaneMaterialCellMatrix.REPEAT_MODE_DEFAULT;
let align = PlaneMaterialCellMatrix.ALIGN_DEFAULT;
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':
repeatMode = PlaneMaterialCellMatrix.REPEAT_MODE_BORDERS;
break;
case 'center':
repeatMode = PlaneMaterialCellMatrix.REPEAT_MODE_CENTER;
break;
case 'first':
repeatMode = PlaneMaterialCellMatrix.REPEAT_MODE_FIRST;
break;
case 'last':
repeatMode = PlaneMaterialCellMatrix.REPEAT_MODE_LAST;
break;
case 'random':
repeatMode = PlaneMaterialCellMatrix.REPEAT_MODE_RANDOM;
break;
default:
repeatMode = PlaneMaterialCellMatrix.REPEAT_MODE_DEFAULT;
break;
}
switch(matrix.align)
{
case 'top':
align = PlaneMaterialCellMatrix.ALIGN_TOP;
break;
case 'bottom':
align = PlaneMaterialCellMatrix.ALIGN_BOTTOM;
break;
default:
align = PlaneMaterialCellMatrix.ALIGN_DEFAULT;
break;
}
if(matrix.columns && matrix.columns.length)
{
const cellMatrix = newMaterial.addMaterialCellMatrix(matrix.columns.length, repeatMode, align, normalMinX, normalMaxX, normalMinY, normalMaxY);
let index = 0;
while(index < matrix.columns.length)
{
const column = matrix.columns[index];
if(column) this.parsePlaneMaterialCellColumn(column, cellMatrix, index);
index++;
}
}
}
}
this._materials.set(id, newMaterial);
}
}
private parsePlaneMaterialCellColumn(column: IAssetPlaneMaterialCellColumn, cellMatrix: PlaneMaterialCellMatrix, index: number): void
{
if(!column || !cellMatrix) return;
let repeatMode = PlaneMaterialCellColumn.REPEAT_MODE_ALL;
const width = column.width;
const cells = this.parsePlaneMaterialCells(column);
switch(column.repeatMode)
{
case 'borders':
repeatMode = PlaneMaterialCellColumn.REPEAT_MODE_BORDERS;
break;
case 'center':
repeatMode = PlaneMaterialCellColumn.REPEAT_MODE_CENTER;
break;
case 'first':
repeatMode = PlaneMaterialCellColumn.REPEAT_MODE_FIRST;
break;
case 'last':
repeatMode = PlaneMaterialCellColumn.REPEAT_MODE_LAST;
break;
case 'none':
repeatMode = PlaneMaterialCellColumn.REPEAT_MODE_NONE;
break;
default:
repeatMode = PlaneMaterialCellColumn.REPEAT_MODE_ALL;
break;
}
cellMatrix.createColumn(index, width, cells, repeatMode);
}
private parsePlaneMaterialCells(column: IAssetPlaneMaterialCellColumn): PlaneMaterialCell[]
{
if(!column || !column.cells || !column.cells.length) return null;
const cells: PlaneMaterialCell[] = [];
let index = 0;
while(index < column.cells.length)
{
const cell = column.cells[index];
if(cell)
{
const textureId = cell.textureId;
let assetNames: string[] = null;
let offsetPoints: Point[] = null;
let graphics: IGraphicAsset[] = null;
let limit = 0;
if(cell.extraData)
{
const types = cell.extraData.extraItemTypes;
const offsets = cell.extraData.offsets;
if(types && offsets)
{
if(types.length && offsets.length)
{
assetNames = this.parseExtraItemTypes(types);
offsetPoints = this.parseExtraItemOffsets(offsets);
limit = offsetPoints.length;
if(cell.extraData.limitMax !== undefined) limit = cell.extraData.limitMax;
}
}
}
if(assetNames && assetNames.length)
{
graphics = [];
for(const assetName of assetNames)
{
if(!assetName) continue;
const asset = this._assetCollection.getAsset(assetName);
if(!asset) continue;
graphics.push(asset);
}
}
const texture = this.getTexture(textureId);
const newCell = new PlaneMaterialCell(texture, graphics, offsetPoints, limit);
cells.push(newCell);
}
index++;
}
if(!cells || !cells.length) return null;
return cells;
}
private parseExtraItemTypes(k: string[]): string[]
{
const assetNames: string[] = [];
if(k && k.length)
{
let index = 0;
while(index < k.length)
{
const type = k[index];
if(type) assetNames.push(type);
index++;
}
}
return assetNames;
}
private parseExtraItemOffsets(k: [ number, number][]): Point[]
{
const offsets: Point[] = [];
if(k && k.length)
{
let index = 0;
while(index < k.length)
{
const [ x, y ] = k[index];
offsets.push(new Point(x, y));
index++;
}
}
return offsets;
}
protected getGeometry(size: number, horizontalAngle: number, verticalAngle: number): IRoomGeometry
{
horizontalAngle = Math.abs(horizontalAngle);
if(horizontalAngle > 90) horizontalAngle = 90;
verticalAngle = Math.abs(verticalAngle);
if(verticalAngle > 90) verticalAngle = 90;
const identifier = `${size}_${Math.round(horizontalAngle)}_${Math.round(verticalAngle)}`;
let geometry = this._geometries.get(identifier);
if(geometry) return geometry;
geometry = new RoomGeometry(size, new Vector3d(horizontalAngle, verticalAngle), new Vector3d(-10, 0, 0));
this._geometries.set(identifier, geometry);
return geometry;
}
protected parseVisualizations(plane: Plane, visualizations: IAssetPlaneVisualization[]): void
{
if(!plane || !visualizations) return;
if(visualizations && visualizations.length)
{
for(const visualization of visualizations)
{
if(!visualization) continue;
const size = visualization.size;
let horizontalAngle = FloorPlane.HORIZONTAL_ANGLE_DEFAULT;
let verticalAngle = FloorPlane.VERTICAL_ANGLE_DEFAULT;
if(visualization.horizontalAngle !== undefined) horizontalAngle = visualization.horizontalAngle;
if(visualization.verticalAngle !== undefined) verticalAngle = visualization.verticalAngle;
const layers = visualization.allLayers as IAssetPlaneVisualizationLayer[];
const planeVisualization = plane.createPlaneVisualization(size, ((layers && layers.length) || 0), this.getGeometry(size, horizontalAngle, verticalAngle));
if(planeVisualization && (layers && layers.length))
{
let layerId = 0;
while(layerId < layers.length)
{
const layer = layers[layerId];
if(layer)
{
let material: PlaneMaterial = null;
let align: number = PlaneVisualizationLayer.ALIGN_DEFAULT;
let color: number = FloorPlane.DEFAULT_COLOR;
let offset: number = PlaneVisualizationLayer.DEFAULT_OFFSET;
if(layer.materialId) material = this.getMaterial(layer.materialId);
if(layer.color) color = layer.color;
if(layer.offset) offset = layer.offset;
if(layer.align)
{
if(layer.align === 'bottom') align = PlaneVisualizationLayer.ALIGN_BOTTOM;
else if(layer.align == 'top') align = PlaneVisualizationLayer.ALIGN_TOP;
}
planeVisualization.setLayer(layerId, material, color, align, offset);
}
layerId++;
}
}
}
}
}
public render(planeId: string, canvas: Texture, 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;
}
public getTextureIdentifier(k: number, normal: IVector3D): string
{
return k.toString();
}
public getLayers(id: string): PlaneVisualizationLayer[]
{
let planes = this.getPlane(id);
if(!planes) planes = this.getPlane(PlaneRasterizer.DEFAULT);
return planes.getLayers();
}
}

View File

@ -1,66 +0,0 @@
import { IVector3D } from '@nitrots/api';
import { Texture } from 'pixi.js';
import { PlaneTextureBitmap } from './PlaneTextureBitmap';
export class PlaneTexture
{
public static MIN_NORMAL_COORDINATE_VALUE: number = -1;
public static MAX_NORMAL_COORDINATE_VALUE: number = 1;
private _bitmaps: PlaneTextureBitmap[];
constructor()
{
this._bitmaps = [];
}
public dispose(): void
{
if(this._bitmaps)
{
for(const bitmap of this._bitmaps)
{
if(!bitmap) continue;
bitmap.dispose();
}
this._bitmaps = null;
}
}
public addBitmap(bitmap: Texture, normalMinX: number = -1, normalMaxX: number = 1, normalMinY: number = -1, normalMaxY: number = 1, assetName: string = null): void
{
this._bitmaps.push(new PlaneTextureBitmap(bitmap, normalMinX, normalMaxX, normalMinY, normalMaxY, assetName));
}
public getBitmap(k: IVector3D): Texture
{
const _local_2 = this.getPlaneTextureBitmap(k);
if(!_local_2) return null;
return _local_2.bitmap;
}
public getPlaneTextureBitmap(k: IVector3D): PlaneTextureBitmap
{
if(!k) return null;
for(const bitmap of this._bitmaps)
{
if(!bitmap) continue;
if((((k.x >= bitmap.normalMinX) && (k.x <= bitmap.normalMaxX)) && (k.y >= bitmap.normalMinY)) && (k.y <= bitmap.normalMaxY)) return bitmap;
}
return null;
}
public getAssetName(k: IVector3D): string
{
const _local_2 = this.getPlaneTextureBitmap(k);
return (!_local_2) ? null : _local_2.assetName;
}
}

View File

@ -1,59 +0,0 @@
import { Texture } from 'pixi.js';
export class PlaneTextureBitmap
{
public static MIN_NORMAL_COORDINATE_VALUE: number = -1;
public static MAX_NORMAL_COORDINATE_VALUE: number = 1;
private _bitmap: Texture;
private _normalMinX: number;
private _normalMaxX: number;
private _normalMinY: number;
private _normalMaxY: number;
private _assetName: string;
constructor(bitmap: Texture, normalMinX: number = -1, normalMaxX: number = 1, normalMinY: number = -1, normalMaxY: number = 1, assetName: string = null)
{
this._bitmap = bitmap;
this._normalMinX = normalMinX;
this._normalMaxX = normalMaxX;
this._normalMinY = normalMinY;
this._normalMaxY = normalMaxY;
this._assetName = assetName;
}
public get bitmap(): Texture
{
return this._bitmap;
}
public get normalMinX(): number
{
return this._normalMinX;
}
public get normalMaxX(): number
{
return this._normalMaxX;
}
public get normalMinY(): number
{
return this._normalMinY;
}
public get normalMaxY(): number
{
return this._normalMaxY;
}
public get assetName(): string
{
return this._assetName;
}
public dispose(): void
{
this._bitmap = null;
}
}

View File

@ -1,159 +0,0 @@
import { IDisposable, IGraphicAssetCollection, IRoomGeometry, IVector3D } from '@nitrots/api';
import { TextureUtils, Vector3d } from '@nitrots/utils';
import { Texture } from 'pixi.js';
import { PlaneVisualizationAnimationLayer } from '../animated';
import { PlaneMaterial } from './PlaneMaterial';
import { PlaneVisualizationLayer } from './PlaneVisualizationLayer';
export class PlaneVisualization
{
private _layers: IDisposable[];
private _geometry: IRoomGeometry;
private _cachedBitmapNormal: Vector3d;
private _isCached: boolean;
private _hasAnimationLayers: boolean;
constructor(size: number, totalLayers: number, geometry: IRoomGeometry)
{
this._layers = [];
this._geometry = geometry;
this._cachedBitmapNormal = new Vector3d();
this._isCached = false;
this._hasAnimationLayers = false;
if(totalLayers < 0) totalLayers = 0;
let index = 0;
while(index < totalLayers)
{
this._layers.push(null);
index++;
}
}
public get geometry(): IRoomGeometry
{
return this._geometry;
}
public get hasAnimationLayers(): boolean
{
return this._hasAnimationLayers;
}
public dispose(): void
{
if(this._layers && this._layers.length)
{
for(const layer of this._layers)
{
if(!layer) continue;
layer.dispose();
}
this._layers = null;
}
this._geometry = null;
if(this._cachedBitmapNormal) this._cachedBitmapNormal = null;
}
public clearCache(): void
{
if(!this._isCached) return;
if(this._cachedBitmapNormal)
{
this._cachedBitmapNormal.assign(new Vector3d());
}
if(this._layers && this._layers.length)
{
for(const layer of this._layers)
{
if(!layer) continue;
const planeLayer = layer as PlaneVisualizationLayer;
planeLayer.clearCache();
}
}
this._isCached = false;
}
public setLayer(layerId: number, material: PlaneMaterial, color: number, align: number, offset: number = 0): boolean
{
if((layerId < 0) || (layerId > this._layers.length)) return false;
let layer = this._layers[layerId];
if(layer) layer.dispose();
layer = new PlaneVisualizationLayer(material, color, align, offset);
this._layers[layerId] = layer;
return true;
}
public setAnimationLayer(layerId: number, animationItems: any, collection: IGraphicAssetCollection): boolean
{
if((layerId < 0) || (layerId > this._layers.length)) return false;
let layer = this._layers[layerId] as IDisposable;
if(layer) layer.dispose();
layer = new PlaneVisualizationAnimationLayer(animationItems, collection);
this._layers[layerId] = layer;
this._hasAnimationLayers = true;
return true;
}
public getLayers(): PlaneVisualizationLayer[]
{
return this._layers as PlaneVisualizationLayer[];
}
public render(planeId: string, canvas: Texture, 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): Texture
{
if(width < 1) width = 1;
if(height < 1) height = 1;
if((!canvas || (canvas.width !== width)) || (canvas.height !== height)) canvas = null;
this._isCached = true;
const bitmap = TextureUtils.createAndFillRenderTexture(width, height);
this._cachedBitmapNormal.assign(normal);
if(this._layers && this._layers.length)
{
for(const layer of this._layers)
{
if(!layer) continue;
if(layer instanceof PlaneVisualizationLayer)
{
layer.render(`${ planeId }:${ this._layers.indexOf(layer) }`, bitmap, width, height, normal, useTexture, offsetX, offsetY);
}
else if(layer instanceof PlaneVisualizationAnimationLayer)
{
layer.render(bitmap, width, height, normal, offsetX, offsetY, maxX, maxY, dimensionX, dimensionY, timeSinceStartMs);
}
}
}
return bitmap;
}
}

View File

@ -1,94 +0,0 @@
import { IVector3D } from '@nitrots/api';
import { TextureUtils } from '@nitrots/utils';
import { Sprite, Texture } from 'pixi.js';
import { PlaneMaterial } from './PlaneMaterial';
export class PlaneVisualizationLayer
{
public static DEFAULT_OFFSET: number = 0;
public static ALIGN_TOP: number = 1;
public static ALIGN_BOTTOM: number = 2;
public static ALIGN_DEFAULT: number = PlaneVisualizationLayer.ALIGN_TOP;
private _material: PlaneMaterial;
private _color: number;
private _offset: number;
private _align: number;
private _isDisposed: boolean;
constructor(material: PlaneMaterial, color: number, align: number, offset: number = 0)
{
this._material = material;
this._offset = offset;
this._align = align;
this._color = color;
this._isDisposed = false;
}
public get offset(): number
{
return this._offset;
}
public get align(): number
{
return this._align;
}
public get disposed(): boolean
{
return this._isDisposed;
}
public dispose(): void
{
this._isDisposed = true;
this._material = null;
this.clearCache();
}
public clearCache(): void
{
}
public render(planeId: string, canvas: Texture, width: number, height: number, normal: IVector3D, useTexture: boolean, offsetX: number, offsetY: number): Texture
{
const r = (this._color >> 16);
const g = ((this._color >> 8) & 0xFF);
const b = (this._color & 0xFF);
const hasColor = ((r < 0xFF) || (g < 0xFF) || (b < 0xFF));
if(this._material)
{
const bitmapData = this._material.render(planeId, hasColor ? null : canvas, width, height, normal, useTexture, offsetX, (offsetY + this.offset), (this.align === PlaneVisualizationLayer.ALIGN_TOP));
if(bitmapData && hasColor)
{
const sprite = new Sprite(bitmapData);
if(hasColor) sprite.tint = this._color;
TextureUtils.writeToTexture(sprite, canvas, false);
}
}
else
{
const bitmapData = TextureUtils.createAndFillRenderTexture(width, height, this._color);
TextureUtils.writeToTexture(new Sprite(bitmapData), canvas, false);
}
return canvas;
}
public getMaterial(): PlaneMaterial
{
return this._material;
}
public getColor(): number
{
return this._color;
}
}

View File

@ -1,30 +0,0 @@
import { IVector3D } from '@nitrots/api';
import { Vector3d } from '@nitrots/utils';
import { Texture } from 'pixi.js';
import { Plane } from './Plane';
export class WallPlane extends Plane
{
public static DEFAULT_COLOR: number = 0xFFFFFF;
public static HORIZONTAL_ANGLE_DEFAULT: number = 45;
public static VERTICAL_ANGLE_DEFAULT: number = 30;
public render(planeId: string, canvas: Texture, width: number, height: number, size: number, normal: IVector3D, useTexture: boolean): Texture
{
const visualization = this.getPlaneVisualization(size);
if(!visualization || !visualization.geometry) return null;
const _local_8 = visualization.geometry.getScreenPoint(new Vector3d(0, 0, 0));
const _local_9 = visualization.geometry.getScreenPoint(new Vector3d(0, 0, (height / visualization.geometry.scale)));
const _local_10 = visualization.geometry.getScreenPoint(new Vector3d(0, (width / visualization.geometry.scale), 0));
if(_local_8 && _local_9 && _local_10)
{
width = Math.round(Math.abs((_local_8.x - _local_10.x)));
height = Math.round(Math.abs((_local_8.y - _local_9.y)));
}
return visualization.render(planeId, canvas, width, height, normal, useTexture);
}
}

View File

@ -1,70 +0,0 @@
import { IAssetPlane, IVector3D } from '@nitrots/api';
import { TextureUtils } from '@nitrots/utils';
import { RenderTexture, Texture } from 'pixi.js';
import { PlaneBitmapData } from '../../utils';
import { PlaneRasterizer } from './PlaneRasterizer';
import { WallPlane } from './WallPlane';
export class WallRasterizer extends PlaneRasterizer
{
protected initializePlanes(): void
{
if(!this.data) return;
const walls = this.data.planes;
if(walls && walls.length) this.parseWalls(walls);
}
private parseWalls(k: IAssetPlane[]): void
{
if(!k) return;
for(const wallIndex in k)
{
const wall = k[wallIndex];
if(!wall) continue;
const id = wall.id;
const visualization = wall.visualizations;
const plane = new WallPlane();
this.parseVisualizations(plane, visualization);
if(!this.addPlane(id, plane)) plane.dispose();
}
}
public render(planeId: string, canvas: Texture, 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;
if(!plane) plane = this.getPlane(PlaneRasterizer.DEFAULT) as WallPlane;
if(!plane) return null;
if(canvas) TextureUtils.clearAndFillRenderTexture(canvas);
let graphic = plane.render(planeId, canvas, width, height, scale, normal, useTexture);
if(graphic && (graphic !== canvas))
{
graphic = new RenderTexture(graphic.source);
if(!graphic) return null;
}
return new PlaneBitmapData(graphic, -1);
}
public getTextureIdentifier(k: number, normal: IVector3D): string
{
if(normal)
{
return `${k}_${normal.x}_${normal.y}_${normal.z}`;
}
return super.getTextureIdentifier(k, normal);
}
}

View File

@ -1,14 +0,0 @@
export * from './FloorPlane';
export * from './FloorRasterizer';
export * from './Plane';
export * from './PlaneMaterial';
export * from './PlaneMaterialCell';
export * from './PlaneMaterialCellColumn';
export * from './PlaneMaterialCellMatrix';
export * from './PlaneRasterizer';
export * from './PlaneTexture';
export * from './PlaneTextureBitmap';
export * from './PlaneVisualization';
export * from './PlaneVisualizationLayer';
export * from './WallPlane';
export * from './WallRasterizer';

View File

@ -1,3 +0,0 @@
export * from './IPlaneRasterizer';
export * from './animated';
export * from './basic';

View File

@ -54,7 +54,7 @@ export class ExtendedSprite extends Sprite
if((!textureSource || !textureSource.hitMap) && !ExtendedSprite.generateHitMapForTextureSource(textureSource)) return false;
//@ts-ignore
const hitMap = (textureSource.hitMap as Uint32Array);
const hitMap = (textureSource.hitMap as U8intclampedArray);
let dx = (point.x + texture.frame.x);
let dy = (point.y + texture.frame.y);
@ -68,11 +68,16 @@ export class ExtendedSprite extends Sprite
dx = (Math.round(dx) * textureSource.resolution);
dy = (Math.round(dy) * textureSource.resolution);
const ind = (dx + dy * textureSource.width);
const ind1 = ind % 32;
const ind2 = ind / 32 | 0;
const index = (dx + dy * textureSource.width) * 4;
return (hitMap[ind2] & (1 << ind1)) !== 0;
const red = hitMap[index];
const green = hitMap[index + 1];
const blue = hitMap[index + 2];
const alpha = hitMap[index + 3];
const result = (alpha >= this.alphaTolerance);
return result;
}
private static generateHitMapForTextureSource(textureSource: TextureSource): boolean
@ -80,24 +85,10 @@ export class ExtendedSprite extends Sprite
if(!textureSource) return false;
const texture = new Texture(textureSource);
const sprite = new Sprite(texture);
const pixels = TextureUtils.getPixels(sprite);
const width = textureSource.width;
const height = textureSource.height;
const hitmap = new Uint32Array(Math.ceil(width * height / 32));
for(let i = 0; i < width * height; i++)
{
const ind1 = i % 32;
const ind2 = i / 32 | 0;
if(pixels.pixels[i * 4 + 3] >= AlphaTolerance.MATCH_OPAQUE_PIXELS) hitmap[ind2] = hitmap[ind2] | (1 << ind1);
}
const pixels = TextureUtils.getPixels(texture);
//@ts-ignore
textureSource.hitMap = hitmap;
sprite.destroy();
textureSource.hitMap = pixels.pixels;
texture.destroy();
return true;