From fc9e22ad2b3b6342522515c79d2e046f32782039 Mon Sep 17 00:00:00 2001 From: billsonnn Date: Sat, 23 Mar 2024 20:54:08 -0400 Subject: [PATCH] Redo plane system --- .../room/object/visualization/IRoomPlane.ts | 3 - packages/room/src/object/RoomPlaneParser.ts | 2 +- .../object/visualization/room/RoomPlane.ts | 1023 +++++------------ .../visualization/room/RoomVisualization.ts | 368 +----- .../room/RoomVisualizationData.ts | 60 - .../room/rasterizer/IPlaneRasterizer.ts | 13 - .../room/rasterizer/animated/AnimationItem.ts | 53 - .../rasterizer/animated/LandscapePlane.ts | 62 - .../animated/LandscapeRasterizer.ts | 239 ---- .../PlaneVisualizationAnimationLayer.ts | 120 -- .../room/rasterizer/animated/index.ts | 4 - .../room/rasterizer/basic/FloorPlane.ts | 38 - .../room/rasterizer/basic/FloorRasterizer.ts | 60 - .../room/rasterizer/basic/Plane.ts | 112 -- .../room/rasterizer/basic/PlaneMaterial.ts | 93 -- .../rasterizer/basic/PlaneMaterialCell.ts | 195 ---- .../basic/PlaneMaterialCellColumn.ts | 457 -------- .../basic/PlaneMaterialCellMatrix.ts | 655 ----------- .../room/rasterizer/basic/PlaneRasterizer.ts | 598 ---------- .../room/rasterizer/basic/PlaneTexture.ts | 66 -- .../rasterizer/basic/PlaneTextureBitmap.ts | 59 - .../rasterizer/basic/PlaneVisualization.ts | 159 --- .../basic/PlaneVisualizationLayer.ts | 94 -- .../room/rasterizer/basic/WallPlane.ts | 30 - .../room/rasterizer/basic/WallRasterizer.ts | 70 -- .../room/rasterizer/basic/index.ts | 14 - .../visualization/room/rasterizer/index.ts | 3 - .../room/src/renderer/utils/ExtendedSprite.ts | 33 +- 28 files changed, 365 insertions(+), 4318 deletions(-) delete mode 100644 packages/room/src/object/visualization/room/rasterizer/IPlaneRasterizer.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/animated/AnimationItem.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/animated/LandscapePlane.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/animated/LandscapeRasterizer.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/animated/PlaneVisualizationAnimationLayer.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/animated/index.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/FloorPlane.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/FloorRasterizer.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/Plane.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterial.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterialCell.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterialCellColumn.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterialCellMatrix.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/PlaneRasterizer.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/PlaneTexture.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/PlaneTextureBitmap.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/PlaneVisualization.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/PlaneVisualizationLayer.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/WallPlane.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/WallRasterizer.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/basic/index.ts delete mode 100644 packages/room/src/object/visualization/room/rasterizer/index.ts diff --git a/packages/api/src/room/object/visualization/IRoomPlane.ts b/packages/api/src/room/object/visualization/IRoomPlane.ts index 0b875942..1cc6bc6a 100644 --- a/packages/api/src/room/object/visualization/IRoomPlane.ts +++ b/packages/api/src/room/object/visualization/IRoomPlane.ts @@ -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[]; } diff --git a/packages/room/src/object/RoomPlaneParser.ts b/packages/room/src/object/RoomPlaneParser.ts index da5602e6..55503852 100644 --- a/packages/room/src/object/RoomPlaneParser.ts +++ b/packages/room/src/object/RoomPlaneParser.ts @@ -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); diff --git a/packages/room/src/object/visualization/room/RoomPlane.ts b/packages/room/src/object/visualization/room/RoomPlane.ts index 577fdeb3..e9c91086 100644 --- a/packages/room/src/object/visualization/room/RoomPlane.ts +++ b/packages/room/src/object/visualization/room/RoomPlane.ts @@ -1,16 +1,15 @@ -import { IRoomGeometry, IRoomPlane, IVector3D } from '@nitrots/api'; -import { ColorConverter, TextureUtils, Vector3d } from '@nitrots/utils'; -import { GetPixelsOutput, Matrix, Point, Sprite, Texture } from 'pixi.js'; -import { PlaneDrawingData } from './PlaneDrawingData'; -import { RoomPlaneBitmapMask } from './RoomPlaneBitmapMask'; -import { RoomPlaneRectangleMask } from './RoomPlaneRectangleMask'; -import { PlaneMaskManager } from './mask'; -import { IPlaneRasterizer } from './rasterizer'; -import { PlaneBitmapData, Randomizer } from './utils'; +import { IAssetPlaneVisualizationLayer, IAssetRoomVisualizationData, IRoomGeometry, IRoomPlane, IVector3D } from '@nitrots/api'; +import { GetAssetManager } from '@nitrots/assets'; +import { TextureUtils, Vector3d } from '@nitrots/utils'; +import { Matrix, Point, Texture, TilingSprite } from 'pixi.js'; +import { RoomGeometry } from '../../../utils'; +import { Randomizer } from './utils'; export class RoomPlane implements IRoomPlane { - private static ZERO_POINT: Point = new Point(0, 0); + public static HORIZONTAL_ANGLE_DEFAULT: number = 45; + public static VERTICAL_ANGLE_DEFAULT: number = 30; + public static TYPE_UNDEFINED: number = 0; public static TYPE_WALL: number = 1; public static TYPE_FLOOR: number = 2; @@ -25,51 +24,33 @@ export class RoomPlane implements IRoomPlane private _rightSide: IVector3D; private _normal: IVector3D; private _secondaryNormals: IVector3D[]; - private _geometryUpdateId: number; private _type: number; private _isVisible: boolean; - private _bitmapData: Texture; - private _hasTexture: boolean; private _offset: Point; private _relativeDepth: number; private _color: number; - private _rasterizer: IPlaneRasterizer; - private _maskManager: PlaneMaskManager = null; private _id: string; private _uniqueId: number; - private _textureOffsetX: number; - private _textureOffsetY: number; - private _textureMaxX: number; - private _textureMaxY: number; - private _activeTexture: PlaneBitmapData; - private _useMask: boolean; - private _bitmapMasks: RoomPlaneBitmapMask[]; - private _rectangleMasks: RoomPlaneRectangleMask[]; - private _maskChanged: boolean; - private _maskBitmapData: Texture; - private _maskPixels: GetPixelsOutput; - private _bitmapMasksOld: RoomPlaneBitmapMask[]; - private _rectangleMasksOld: RoomPlaneRectangleMask[]; private _cornerA: IVector3D; private _cornerB: IVector3D; private _cornerC: IVector3D; private _cornerD: IVector3D; + private _textureOffsetX: number; + private _textureOffsetY: number; + private _textureMaxX: number; + private _textureMaxY: number; private _width: number = 0; private _height: number = 0; + private _hasTexture: boolean = true; private _canBeVisible: boolean; + private _tilingSprite: TilingSprite = null; + private _planeTexture: Texture = null; + constructor(origin: IVector3D, location: IVector3D, leftSide: IVector3D, rightSide: IVector3D, type: number, usesMask: boolean, secondaryNormals: IVector3D[], randomSeed: number, textureOffsetX: number = 0, textureOffsetY: number = 0, textureMaxX: number = 0, textureMaxY: number = 0) { this._secondaryNormals = []; - this._bitmapMasks = []; - this._rectangleMasks = []; - this._bitmapMasksOld = []; - this._rectangleMasksOld = []; this._randomSeed = randomSeed; - this._bitmapData = null; - this._maskBitmapData = null; - this._maskChanged = false; - this._activeTexture = null; this._origin = new Vector3d(); this._origin.assign(origin); this._location = new Vector3d(); @@ -101,41 +82,317 @@ export class RoomPlane implements IRoomPlane this._disposed = false; this._isVisible = false; this._id = null; - this._hasTexture = true; - this._geometryUpdateId = -1; this._offset = new Point(); this._relativeDepth = 0; this._type = type; this._color = 0; - this._rasterizer = null; this._canBeVisible = true; this._cornerA = new Vector3d(); this._cornerB = new Vector3d(); this._cornerC = new Vector3d(); this._cornerD = new Vector3d(); - this._width = 0; - this._height = 0; this._textureOffsetX = textureOffsetX; this._textureOffsetY = textureOffsetY; this._textureMaxX = textureMaxX; this._textureMaxY = textureMaxY; - this._useMask = usesMask; + this._width = 0; + this._height = 0; this._uniqueId = ++RoomPlane._uniqueIdCounter; } - private static blend(a: number, b: number): number + public dispose(): void { - return ColorConverter.colorize(b, (a | 0xFF000000)) & 0xFFFFFF; + this._location = null; + this._origin = null; + this._leftSide = null; + this._rightSide = null; + this._normal = null; + this._cornerA = null; + this._cornerB = null; + this._cornerC = null; + this._cornerD = null; + + this._disposed = true; } - public set canBeVisible(k: boolean) + public update(geometry: IRoomGeometry, timeSinceStartMs: number): boolean { - if(k !== this._canBeVisible) - { - if(!this._canBeVisible) this.resetTextureCache(); + if(!geometry || this._disposed) return false; - this._canBeVisible = k; + let cosAngle = 0; + + cosAngle = Vector3d.cosAngle(geometry.directionAxis, this.normal); + + if(cosAngle > -0.001) + { + if(this._isVisible) + { + this._isVisible = false; + + return true; + } + + return false; } + + let i = 0; + + while(i < this._secondaryNormals.length) + { + cosAngle = Vector3d.cosAngle(geometry.directionAxis, this._secondaryNormals[i]); + + if(cosAngle > -0.001) + { + if(this._isVisible) + { + this._isVisible = false; + return true; + } + + return false; + } + + i++; + } + + this.updateCorners(geometry); + + let relativeDepth = (Math.max(this._cornerA.z, this._cornerB.z, this._cornerC.z, this._cornerD.z) - geometry.getScreenPosition(this._origin).z); + + switch(this._type) + { + case RoomPlane.TYPE_FLOOR: + relativeDepth = (relativeDepth - ((this._location.z + Math.min(0, this._leftSide.z, this._rightSide.z)) * 8)); + break; + case RoomPlane.TYPE_LANDSCAPE: + relativeDepth = (relativeDepth + 0.02); + break; + } + + this._relativeDepth = relativeDepth; + this._isVisible = true; + + Randomizer.setSeed(this._randomSeed); + + const horizontalAngle = RoomPlane.HORIZONTAL_ANGLE_DEFAULT; + const verticalAngle = RoomPlane.VERTICAL_ANGLE_DEFAULT; + + geometry = new RoomGeometry(64, new Vector3d(horizontalAngle, verticalAngle), new Vector3d(-10, 0, 0)); + + let width = (this._leftSide.length * geometry.scale); + let height = (this._rightSide.length * geometry.scale); + const normal = geometry.getCoordinatePosition(this._normal); + + const getTextureAndColorForPlane = (planeId: string, planeType: number) => + { + const dataType: keyof IAssetRoomVisualizationData = (planeType === RoomPlane.TYPE_FLOOR) ? 'floorData' : (planeType === RoomPlane.TYPE_WALL) ? 'wallData' : 'landscapeData'; + + const roomCollection = GetAssetManager().getCollection('room'); + const planeVisualizationData = roomCollection?.data?.roomVisualization?.[dataType]; + const planeVisualization = planeVisualizationData?.planes?.find(plane => (plane.id === planeId))?.visualizations?.[0]; + const planeLayer = planeVisualization?.allLayers?.[0] as IAssetPlaneVisualizationLayer; + const planeMaterialId = planeLayer?.materialId; + const planeColor = planeLayer?.color; + const planeAssetName = planeVisualizationData?.textures?.find(texture => (texture.id === planeMaterialId))?.bitmaps?.[0]?.assetName; + const texture = GetAssetManager().getAsset(planeAssetName)?.texture; + + const getRandomColor = () => + { + const letters = '0123456789ABCDEF'; + let color = '0x'; + for(let i = 0; i < 6; i++) + { + color += letters[Math.floor(Math.random() * 16)]; + } + return parseInt(color, 16); + }; + + return { texture, color: getRandomColor() }; + }; + + const planeData = getTextureAndColorForPlane(this._id, this._type); + const texture = this._hasTexture ? planeData.texture ?? Texture.WHITE : Texture.WHITE; + + let planeSprite: TilingSprite = null; + + switch(this._type) + { + case RoomPlane.TYPE_FLOOR: { + const _local_10 = geometry.getScreenPoint(new Vector3d(0, 0, 0)); + const _local_11 = geometry.getScreenPoint(new Vector3d(0, (height / geometry.scale), 0)); + const _local_12 = geometry.getScreenPoint(new Vector3d((width / 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 - geometry.getScreenPoint(new Vector3d(1, 0, 0)).x); + + x = (this._textureOffsetX * Math.trunc(Math.abs(_local_15))); + y = (this._textureOffsetY * Math.trunc(Math.abs(_local_15))); + } + + if((x !== 0) || (y !== 0)) + { + while(x < 0) x += texture.width; + + while(y < 0) y += texture.height; + } + + planeSprite = new TilingSprite({ + texture, + width, + height, + tint: planeData.color, + tilePosition: { + x: (x % texture.width) + (this._textureOffsetX * texture.width), + y: (y % texture.height) + (this._textureOffsetY * texture.height) + } + }); + + break; + } + case RoomPlane.TYPE_WALL: { + const _local_8 = geometry.getScreenPoint(new Vector3d(0, 0, 0)); + const _local_9 = geometry.getScreenPoint(new Vector3d(0, 0, (height / geometry.scale))); + const _local_10 = geometry.getScreenPoint(new Vector3d(0, (width / 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))); + } + + planeSprite = new TilingSprite({ + texture, + width, + height, + tint: planeData.color, + tilePosition: { + x: (this._textureOffsetX * texture.width), + y: (this._textureOffsetY * texture.height) + } + }); + + break; + } + case RoomPlane.TYPE_LANDSCAPE: { + const _local_13 = geometry.getScreenPoint(new Vector3d(0, 0, 0)); + const _local_14 = geometry.getScreenPoint(new Vector3d(0, 0, 1)); + const _local_15 = 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) / geometry.scale))); + height = Math.round(Math.abs((((_local_13.y - _local_14.y) * height) / geometry.scale))); + } + + const renderMaxX = Math.trunc(this._textureMaxX * Math.abs((_local_13.x - _local_15.x))); + const renderMaxY = Math.trunc(this._textureMaxY * Math.abs((_local_13.y - _local_14.y))); + + const renderOffsetX = Math.trunc(this._textureOffsetX * Math.abs((_local_13.x - _local_15.x))); + const renderOffsetY = Math.trunc(this._textureOffsetY * Math.abs((_local_13.y - _local_14.y))); + + planeSprite = new TilingSprite({ + texture, + width: width, + height: height, + tilePosition: { + x: renderOffsetX, + y: renderOffsetY + }, + tint: planeData.color, + applyAnchorToTexture: true + }); + break; + } + default: { + planeSprite = new TilingSprite({ + texture: Texture.WHITE, + width: width, + height: height, + applyAnchorToTexture: true + }); + } + } + + this._planeTexture = TextureUtils.createAndWriteRenderTexture(this._width, this._height, planeSprite, this.getMatrixForDimensions(width, height)) as Texture; + + return true; + } + + private updateCorners(geometry: IRoomGeometry): void + { + this._cornerA.assign(geometry.getScreenPosition(this._location)); + this._cornerB.assign(geometry.getScreenPosition(Vector3d.sum(this._location, this._rightSide))); + this._cornerC.assign(geometry.getScreenPosition(Vector3d.sum(Vector3d.sum(this._location, this._leftSide), this._rightSide))); + this._cornerD.assign(geometry.getScreenPosition(Vector3d.sum(this._location, this._leftSide))); + + this._offset = geometry.getScreenPoint(this._origin); + this._cornerA.x = Math.round(this._cornerA.x); + this._cornerA.y = Math.round(this._cornerA.y); + this._cornerB.x = Math.round(this._cornerB.x); + this._cornerB.y = Math.round(this._cornerB.y); + this._cornerC.x = Math.round(this._cornerC.x); + this._cornerC.y = Math.round(this._cornerC.y); + this._cornerD.x = Math.round(this._cornerD.x); + this._cornerD.y = Math.round(this._cornerD.y); + this._offset.x = Math.round(this._offset.x); + this._offset.y = Math.round(this._offset.y); + + const minX = Math.min(this._cornerA.x, this._cornerB.x, this._cornerC.x, this._cornerD.x); + const maxX = Math.max(this._cornerA.x, this._cornerB.x, this._cornerC.x, this._cornerD.x) - minX; + const minY = Math.min(this._cornerA.y, this._cornerB.y, this._cornerC.y, this._cornerD.y); + const maxY = Math.max(this._cornerA.y, this._cornerB.y, this._cornerC.y, this._cornerD.y) - minY; + + this._offset.x = (this._offset.x - minX); + this._cornerA.x = (this._cornerA.x - minX); + this._cornerB.x = (this._cornerB.x - minX); + this._cornerC.x = (this._cornerC.x - minX); + this._cornerD.x = (this._cornerD.x - minX); + + this._offset.y = (this._offset.y - minY); + this._cornerA.y = (this._cornerA.y - minY); + this._cornerB.y = (this._cornerB.y - minY); + this._cornerC.y = (this._cornerC.y - minY); + this._cornerD.y = (this._cornerD.y - minY); + + this._width = maxX; + this._height = maxY; + } + + private getMatrixForDimensions(width: number, height: number): Matrix + { + let a: number = (this._cornerD.x - this._cornerC.x); + let b: number = (this._cornerD.y - this._cornerC.y); + let c: number = (this._cornerB.x - this._cornerC.x); + let d: number = (this._cornerB.y - this._cornerC.y); + + if((this._type === RoomPlane.TYPE_WALL) || (this._type === RoomPlane.TYPE_LANDSCAPE)) + { + if(Math.abs((c - width)) <= 1) c = width; + + if(Math.abs((d - width)) <= 1) d = width; + + if(Math.abs((a - height)) <= 1) a = height; + + if(Math.abs((b - height)) <= 1) b = height; + } + + const xScale: number = (c / width); + const ySkew: number = (d / width); + const xSkew: number = (a / height); + const yScale: number = (b / height); + + const matrix = new Matrix(xScale, ySkew, xSkew, yScale); + + matrix.translate(this._cornerC.x, this._cornerC.y); + + return matrix; } public get canBeVisible(): boolean @@ -143,18 +400,9 @@ export class RoomPlane implements IRoomPlane return this._canBeVisible; } - public get bitmapData(): Texture + public set canBeVisible(flag: boolean) { - if(!this.visible || !this._bitmapData) return null; - - return this._bitmapData; - } - - public get maskBitmapData(): Texture - { - if(!this.visible || !this._maskBitmapData) return null; - - return this._maskBitmapData; + if(flag !== this._canBeVisible) this._canBeVisible = flag; } public get visible(): boolean @@ -207,31 +455,10 @@ export class RoomPlane implements IRoomPlane return this._normal; } - public get hasTexture(): boolean - { - return this._hasTexture; - } - - public set hasTexture(k: boolean) - { - this._hasTexture = k; - } - - public set rasterizer(k: IPlaneRasterizer) - { - this._rasterizer = k; - } - - public set maskManager(k: PlaneMaskManager) - { - this._maskManager = k; - } - public set id(k: string) { if(k === this._id) return; - this.resetTextureCache(); this._id = k; } @@ -240,639 +467,13 @@ export class RoomPlane implements IRoomPlane return this._uniqueId; } - public dispose(): void + public get planeTexture(): Texture { - this._activeTexture = null; - this._location = null; - this._origin = null; - this._leftSide = null; - this._rightSide = null; - this._normal = null; - this._rasterizer = null; - this._cornerA = null; - this._cornerB = null; - this._cornerC = null; - this._cornerD = null; - this._bitmapMasks = null; - this._rectangleMasks = null; - this._maskPixels = null; - - if(this._maskBitmapData) - { - this._maskBitmapData.destroy(true); - - this._maskBitmapData = null; - } - - this._disposed = true; + return this._planeTexture; } - public copyBitmapData(k: Texture): Texture + public set hasTexture(flag: boolean) { - if(!this.visible || !this._bitmapData || !k) return null; - - if((this._bitmapData.width !== k.width) || (this._bitmapData.height !== k.height)) return null; - - //k.copyPixels(this._bitmapData, this._bitmapData.rect, RoomPlane.ZERO_POINT); - return k; - } - - private resetTextureCache(): void - { - this._activeTexture = null; - } - - private getTextureIdentifier(k: number): string - { - if(this._rasterizer) return this._rasterizer.getTextureIdentifier(k, this.normal); - - return k.toString(); - } - - private needsNewTexture(k: IRoomGeometry, _arg_2: number): boolean - { - if(!k) return false; - - const planeBitmap = this._activeTexture; - - this.updateMaskChangeStatus(); - - if(this._canBeVisible && ((!planeBitmap || ((planeBitmap.timeStamp >= 0) && (_arg_2 > planeBitmap.timeStamp))) || this._maskChanged)) return true; - - return false; - } - - private getTexture(geometry: IRoomGeometry, timeSinceStartMs: number): Texture - { - if(!geometry) return null; - - let bitmapData: PlaneBitmapData = null; - - if(this.needsNewTexture(geometry, timeSinceStartMs)) - { - const identifier = this.getTextureIdentifier(geometry.scale); - const width = this._leftSide.length * geometry.scale; - const height = this._rightSide.length * geometry.scale; - const normal = geometry.getCoordinatePosition(this._normal); - - bitmapData = this._rasterizer.render(this._uniqueId.toString(), 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); - } - } - else - { - if(this._activeTexture) bitmapData = this._activeTexture; - } - - if(bitmapData) - { - this._activeTexture = bitmapData; - - return bitmapData.texture; - } - - return null; - } - - private resolveMasks(k: IRoomGeometry): PlaneDrawingData - { - if(!this._useMask) return null; - - const drawingData = new PlaneDrawingData(); - - const index = 0; - - while(index < this._bitmapMasks.length) - { - const mask = this._bitmapMasks[index]; - - if(mask) - { - const planeMask = this._maskManager.getMask(mask.type); - - if(planeMask) - { - const assetName = planeMask.getAssetName(k.scale); - - if(assetName) - { - const position = k.getCoordinatePosition(this._normal); - const asset = planeMask.getGraphicAsset(k.scale, position); - - if(asset) - { - const x = (this._maskBitmapData.width * (1 - (mask.leftSideLoc / this._leftSide.length))); - const y = (this._maskBitmapData.height * (1 - (mask.rightSideLoc / this._rightSide.length))); - - drawingData.addMask(assetName, new Point((x + asset.offsetX), (y + asset.offsetY)), asset.flipH, asset.flipV); - } - } - } - } - } - - return drawingData; - } - - private screenWidth(k: IRoomGeometry): number - { - const _local_2 = k.getScreenPoint(new Vector3d(0, 0, 0)); - const _local_3 = k.getScreenPoint(new Vector3d(0, 1, 0)); - - return Math.round((this._leftSide.length * Math.abs((_local_2.x - _local_3.x)))); - } - - public getDrawingDatas(geometry: IRoomGeometry): PlaneDrawingData[] - { - const drawingDatas: PlaneDrawingData[] = []; - - if(this._isVisible) - { - const maskData = this.resolveMasks(geometry); - const layers = this._rasterizer.getLayers(this._id); - - for(const layer of layers) - { - if(this._hasTexture && layer.getMaterial()) - { - const normal = geometry.getCoordinatePosition(this._normal); - const cellMatrix = layer.getMaterial().getMaterialCellMatrix(normal); - const data = new PlaneDrawingData(maskData, RoomPlane.blend(this._color, layer.getColor()), cellMatrix.isBottomAligned()); - - Randomizer.setSeed(this._randomSeed); - - for(const column of cellMatrix.getColumns(this.screenWidth(geometry))) - { - const assetNames: string[] = []; - - for(const cell of column.getCells()) - { - const name = cell.getAssetName(normal); - - if(name) assetNames.push(name); - } - - if(assetNames.length > 0) - { - if(!column.isRepeated()) assetNames.push(''); - - data.addAssetColumn(assetNames); - } - } - - if(data.assetNameColumns.length > 0) drawingDatas.push(data); - } - else - { - const data = new PlaneDrawingData(maskData, RoomPlane.blend(this._color, layer.getColor())); - - drawingDatas.push(data); - } - } - - if(!drawingDatas.length) drawingDatas.push(new PlaneDrawingData(maskData, this._color)); - } - - return drawingDatas; - } - - // private _Str_25956(k:PlaneBitmapData): void - // { - // } - - public update(geometry: IRoomGeometry, timeSinceStartMs: number): boolean - { - if(!geometry || this._disposed) return false; - - let geometryChanged = false; - - if(this._geometryUpdateId != geometry.updateId) geometryChanged = true; - - if(!geometryChanged || !this._canBeVisible) - { - if(!this.visible) return false; - } - - if(geometryChanged) - { - this._activeTexture = null; - - let cosAngle = 0; - - cosAngle = Vector3d.cosAngle(geometry.directionAxis, this.normal); - - if(cosAngle > -0.001) - { - if(this._isVisible) - { - this._isVisible = false; - return true; - } - - return false; - } - - let i = 0; - - while(i < this._secondaryNormals.length) - { - cosAngle = Vector3d.cosAngle(geometry.directionAxis, this._secondaryNormals[i]); - - if(cosAngle > -0.001) - { - if(this._isVisible) - { - this._isVisible = false; - return true; - } - - return false; - } - - i++; - } - - this.updateCorners(geometry); - - const originPos = geometry.getScreenPosition(this._origin); - const originZ = originPos.z; - - let relativeDepth = (Math.max(this._cornerA.z, this._cornerB.z, this._cornerC.z, this._cornerD.z) - originZ); - - if(this._type === RoomPlane.TYPE_FLOOR) - { - relativeDepth = (relativeDepth - ((this._location.z + Math.min(0, this._leftSide.z, this._rightSide.z)) * 8)); - } - - if(this._type === RoomPlane.TYPE_LANDSCAPE) - { - relativeDepth = (relativeDepth + 0.02); - } - - this._relativeDepth = relativeDepth; - this._isVisible = true; - this._geometryUpdateId = geometry.updateId; - } - - if(geometryChanged || this.needsNewTexture(geometry, timeSinceStartMs)) - { - if(!this._bitmapData || (this._width !== this._bitmapData.width) || (this._height !== this._bitmapData.height)) - { - if(this._bitmapData) - { - if((this._width !== this._bitmapData.width) || (this._height !== this._bitmapData.height)) - { - this._bitmapData.destroy(); - - this._bitmapData = null; - - if((this._width < 1) || (this._height < 1)) return true; - - this._bitmapData = TextureUtils.createAndFillRenderTexture(this._width, this._height); - } - else - { - if((this._width < 1) || (this._height < 1)) - { - this._bitmapData.destroy(); - - this._bitmapData = null; - - return true; - } - - TextureUtils.clearAndFillRenderTexture(this._bitmapData); - } - } - else - { - if((this._width < 1) || (this._height < 1)) return false; - - this._bitmapData = TextureUtils.createAndFillRenderTexture(this._width, this._height); - } - - if(!this._bitmapData) return false; - } - else - { - TextureUtils.clearAndFillRenderTexture(this._bitmapData); - } - - Randomizer.setSeed(this._randomSeed); - - const texture = this.getTexture(geometry, timeSinceStartMs); - - if(texture) - { - this.renderTexture(geometry, texture); - } - else - { - this.dispose(); - - return false; - } - - return ((texture !== null) || geometryChanged); - } - - return false; - } - - private updateCorners(geometry: IRoomGeometry): void - { - this._cornerA.assign(geometry.getScreenPosition(this._location)); - this._cornerB.assign(geometry.getScreenPosition(Vector3d.sum(this._location, this._rightSide))); - this._cornerC.assign(geometry.getScreenPosition(Vector3d.sum(Vector3d.sum(this._location, this._leftSide), this._rightSide))); - this._cornerD.assign(geometry.getScreenPosition(Vector3d.sum(this._location, this._leftSide))); - this._offset = geometry.getScreenPoint(this._origin); - this._cornerA.x = Math.round(this._cornerA.x); - this._cornerA.y = Math.round(this._cornerA.y); - this._cornerB.x = Math.round(this._cornerB.x); - this._cornerB.y = Math.round(this._cornerB.y); - this._cornerC.x = Math.round(this._cornerC.x); - this._cornerC.y = Math.round(this._cornerC.y); - this._cornerD.x = Math.round(this._cornerD.x); - this._cornerD.y = Math.round(this._cornerD.y); - this._offset.x = Math.round(this._offset.x); - this._offset.y = Math.round(this._offset.y); - - const minX = Math.min(this._cornerA.x, this._cornerB.x, this._cornerC.x, this._cornerD.x); - const maxX = Math.max(this._cornerA.x, this._cornerB.x, this._cornerC.x, this._cornerD.x) - minX; - const minY = Math.min(this._cornerA.y, this._cornerB.y, this._cornerC.y, this._cornerD.y); - const maxY = Math.max(this._cornerA.y, this._cornerB.y, this._cornerC.y, this._cornerD.y) - minY; - - this._offset.x = (this._offset.x - minX); - this._cornerA.x = (this._cornerA.x - minX); - this._cornerB.x = (this._cornerB.x - minX); - this._cornerC.x = (this._cornerC.x - minX); - this._cornerD.x = (this._cornerD.x - minX); - - this._offset.y = (this._offset.y - minY); - this._cornerA.y = (this._cornerA.y - minY); - this._cornerB.y = (this._cornerB.y - minY); - this._cornerC.y = (this._cornerC.y - minY); - this._cornerD.y = (this._cornerD.y - minY); - - this._width = maxX; - this._height = maxY; - } - - private getMatrixForDimensions(width: number, height: number): Matrix - { - let _local_3: number = (this._cornerD.x - this._cornerC.x); - let _local_4: number = (this._cornerD.y - this._cornerC.y); - let _local_5: number = (this._cornerB.x - this._cornerC.x); - let _local_6: number = (this._cornerB.y - this._cornerC.y); - - if((this._type === RoomPlane.TYPE_WALL) || (this._type === RoomPlane.TYPE_LANDSCAPE)) - { - if(Math.abs((_local_5 - width)) <= 1) _local_5 = width; - - if(Math.abs((_local_6 - width)) <= 1) _local_6 = width; - - if(Math.abs((_local_3 - height)) <= 1) _local_3 = height; - - if(Math.abs((_local_4 - height)) <= 1) _local_4 = height; - } - - const xScale: number = (_local_5 / width); - const ySkew: number = (_local_6 / width); - const xSkew: number = (_local_3 / height); - const yScale: number = (_local_4 / height); - - const matrix = new Matrix(xScale, ySkew, xSkew, yScale); - - matrix.translate(this._cornerC.x, this._cornerC.y); - - return matrix; - } - - private renderTexture(geometry: IRoomGeometry, _arg_2: Texture): void - { - if(((((((this._cornerA == null) || (this._cornerB == null)) || (this._cornerC == null)) || (this._cornerD == null)) || (_arg_2 == null)) || (this._bitmapData == null))) - { - return; - } - - TextureUtils.writeToTexture(new Sprite(_arg_2), this._bitmapData, true, this.getMatrixForDimensions(_arg_2.width, _arg_2.height)); - } - - public resetBitmapMasks(): void - { - if(this._disposed || !this._useMask || !this._bitmapMasks.length) return; - - this._maskChanged = true; - this._bitmapMasks = []; - } - - public addBitmapMask(maskType: string, leftSideLoc: number, rightSideLoc: number): boolean - { - if(!this._useMask) return false; - - for(const mask of this._bitmapMasks) - { - if(!mask) continue; - - if((((mask.type === maskType) && (mask.leftSideLoc === leftSideLoc)) && (mask.rightSideLoc === rightSideLoc))) return false; - } - - const mask = new RoomPlaneBitmapMask(maskType, leftSideLoc, rightSideLoc); - - this._bitmapMasks.push(mask); - this._maskChanged = true; - - return true; - } - - public resetRectangleMasks(): void - { - if(!this._useMask || !this._rectangleMasks.length) return; - - this._maskChanged = true; - this._rectangleMasks = []; - } - - public addRectangleMask(k: number, _arg_2: number, _arg_3: number, _arg_4: number): boolean - { - if(this._useMask) - { - for(const mask of this._rectangleMasks) - { - if(!mask) continue; - - if((((mask.leftSideLoc === k) && (mask.rightSideLoc === _arg_2)) && (mask.leftSideLength === _arg_3)) && (mask.rightSideLength === _arg_4)) return false; - } - - const _local_5 = new RoomPlaneRectangleMask(k, _arg_2, _arg_3, _arg_4); - - this._rectangleMasks.push(_local_5); - this._maskChanged = true; - - return true; - } - - return false; - } - - private updateMaskChangeStatus(): void - { - if(!this._maskChanged) return; - - let maskChanged = true; - - if(this._bitmapMasks.length === this._bitmapMasksOld.length) - { - for(const mask of this._bitmapMasks) - { - if(!mask) continue; - - let _local_6 = false; - - for(const plane of this._bitmapMasksOld) - { - if(!plane) continue; - - if(((plane.type === mask.type) && (plane.leftSideLoc === mask.leftSideLoc)) && (plane.rightSideLoc === mask.rightSideLoc)) - { - _local_6 = true; - - break; - } - } - - if(!_local_6) - { - maskChanged = false; - - break; - } - } - } - else - { - maskChanged = false; - } - - if(this._rectangleMasks.length > this._rectangleMasksOld.length) maskChanged = false; - - if(maskChanged) this._maskChanged = false; - } - - private updateMask(canvas: Texture, geometry: IRoomGeometry): void - { - if(!canvas || !geometry) return; - - if(!this._useMask || ((!this._bitmapMasks.length && !this._rectangleMasks.length) && !this._maskChanged) || !this._maskManager) return; - - const width = canvas.width; - const height = canvas.height; - - this.updateMaskChangeStatus(); - - if(!this._maskBitmapData || (this._maskBitmapData.width !== width) || (this._maskBitmapData.height !== height)) - { - this._maskBitmapData = TextureUtils.createAndFillRenderTexture(width, height); - this._maskChanged = true; - } - - if(this._maskChanged) - { - this._bitmapMasksOld = []; - this._rectangleMasksOld = []; - - if(this._maskBitmapData) TextureUtils.clearAndFillRenderTexture(this._maskBitmapData); - - this.resetTextureCache(); - - const normal = geometry.getCoordinatePosition(this._normal); - - let type: string = null; - let posX = 0; - let posY = 0; - let i = 0; - - while(i < this._bitmapMasks.length) - { - const mask = this._bitmapMasks[i]; - - if(mask) - { - type = mask.type; - posX = (this._maskBitmapData.width - ((this._maskBitmapData.width * mask.leftSideLoc) / this._leftSide.length)); - posY = (this._maskBitmapData.height - ((this._maskBitmapData.height * mask.rightSideLoc) / this._rightSide.length)); - - this._maskManager.updateMask(this._maskBitmapData, type, geometry.scale, normal, posX, posY); - this._bitmapMasksOld.push(new RoomPlaneBitmapMask(type, mask.leftSideLoc, mask.rightSideLoc)); - } - - i++; - } - - i = 0; - - while(i < this._rectangleMasks.length) - { - const rectMask = this._rectangleMasks[i]; - - if(rectMask) - { - posX = (this._maskBitmapData.width - ((this._maskBitmapData.width * rectMask.leftSideLoc) / this._leftSide.length)); - posY = (this._maskBitmapData.height - ((this._maskBitmapData.height * rectMask.rightSideLoc) / this._rightSide.length)); - - const wd = ((this._maskBitmapData.width * rectMask.leftSideLength) / this._leftSide.length); - const ht = ((this._maskBitmapData.height * rectMask.rightSideLength) / this._rightSide.length); - - const sprite = new Sprite(Texture.WHITE); - - sprite.tint = 0x000000; - sprite.width = wd; - sprite.height = ht; - sprite.position.set((posX - wd), (posY - ht)); - - TextureUtils.writeToTexture(sprite, this._maskBitmapData, false); - - this._rectangleMasksOld.push(new RoomPlaneRectangleMask(rectMask.leftSideLength, rectMask.rightSideLoc, rectMask.leftSideLength, rectMask.rightSideLength)); - } - - i++; - } - - this._maskPixels = TextureUtils.getPixels(this._maskBitmapData); - - this._maskChanged = false; - } - - this.combineTextureMask(canvas, this._maskPixels); - } - - private combineTextureMask(canvas: Texture, maskPixels: GetPixelsOutput): void - { - if(!canvas || !maskPixels) return; - - const canvasPixels = TextureUtils.getPixels(canvas); - const pixels = canvasPixels.pixels; - - for(let i = 0; i < pixels.length; i += 4) - { - const maskRed = maskPixels[i]; - const maskGreen = maskPixels[i + 1]; - const maskBlue = maskPixels[i + 2]; - const maskAlpha = maskPixels[i + 3]; - - if(!maskRed && !maskGreen && !maskBlue) pixels[i + 3] = 0; - } - - /* const canvaGLTexture = canvas.baseTexture._glTextures['1']?.texture; - const gl = (GetPixi().renderer as Renderer)?.gl; - - if(!canvaGLTexture || !gl) return; - - gl.bindTexture(gl.TEXTURE_2D, canvaGLTexture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, canvasPixels); - gl.bindTexture(gl.TEXTURE_2D, null); */ + this._hasTexture = flag; } } diff --git a/packages/room/src/object/visualization/room/RoomVisualization.ts b/packages/room/src/object/visualization/room/RoomVisualization.ts index 1b116f9e..cd9337fc 100644 --- a/packages/room/src/object/visualization/room/RoomVisualization.ts +++ b/packages/room/src/object/visualization/room/RoomVisualization.ts @@ -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(RoomObjectVariable.ROOM_PLANE_MASK_XML); - - if(planeMask !== this._maskData) - { - this.updatePlaneMasks(planeMask); - - this._maskData = planeMask; - - didUpdate = true; - } - - const backgroundColor = k.getValue(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(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(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); } diff --git a/packages/room/src/object/visualization/room/RoomVisualizationData.ts b/packages/room/src/object/visualization/room/RoomVisualizationData.ts index cf8a5d12..9059d981 100644 --- a/packages/room/src/object/visualization/room/RoomVisualizationData.ts +++ b/packages/room/src/object/visualization/room/RoomVisualizationData.ts @@ -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 diff --git a/packages/room/src/object/visualization/room/rasterizer/IPlaneRasterizer.ts b/packages/room/src/object/visualization/room/rasterizer/IPlaneRasterizer.ts deleted file mode 100644 index 82041259..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/IPlaneRasterizer.ts +++ /dev/null @@ -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; -} diff --git a/packages/room/src/object/visualization/room/rasterizer/animated/AnimationItem.ts b/packages/room/src/object/visualization/room/rasterizer/animated/AnimationItem.ts deleted file mode 100644 index 0866ace5..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/animated/AnimationItem.ts +++ /dev/null @@ -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); - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/animated/LandscapePlane.ts b/packages/room/src/object/visualization/room/rasterizer/animated/LandscapePlane.ts deleted file mode 100644 index 7cc3bca7..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/animated/LandscapePlane.ts +++ /dev/null @@ -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; - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/animated/LandscapeRasterizer.ts b/packages/room/src/object/visualization/room/rasterizer/animated/LandscapeRasterizer.ts deleted file mode 100644 index 97610d54..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/animated/LandscapeRasterizer.ts +++ /dev/null @@ -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('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); - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/animated/PlaneVisualizationAnimationLayer.ts b/packages/room/src/object/visualization/room/rasterizer/animated/PlaneVisualizationAnimationLayer.ts deleted file mode 100644 index 59ecfa89..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/animated/PlaneVisualizationAnimationLayer.ts +++ /dev/null @@ -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; - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/animated/index.ts b/packages/room/src/object/visualization/room/rasterizer/animated/index.ts deleted file mode 100644 index 185d1a60..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/animated/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './AnimationItem'; -export * from './LandscapePlane'; -export * from './LandscapeRasterizer'; -export * from './PlaneVisualizationAnimationLayer'; diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/FloorPlane.ts b/packages/room/src/object/visualization/room/rasterizer/basic/FloorPlane.ts deleted file mode 100644 index 8ec5e49f..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/FloorPlane.ts +++ /dev/null @@ -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); - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/FloorRasterizer.ts b/packages/room/src/object/visualization/room/rasterizer/basic/FloorRasterizer.ts deleted file mode 100644 index 016c1aa9..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/FloorRasterizer.ts +++ /dev/null @@ -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); - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/Plane.ts b/packages/room/src/object/visualization/room/rasterizer/basic/Plane.ts deleted file mode 100644 index 0ad54e69..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/Plane.ts +++ /dev/null @@ -1,112 +0,0 @@ -import { IRoomGeometry } from '@nitrots/api'; -import { PlaneVisualization } from './PlaneVisualization'; -import { PlaneVisualizationLayer } from './PlaneVisualizationLayer'; - -export class Plane -{ - private _planeVisualizations: Map; - 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(); - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterial.ts b/packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterial.ts deleted file mode 100644 index 09d01750..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterial.ts +++ /dev/null @@ -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); - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterialCell.ts b/packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterialCell.ts deleted file mode 100644 index 9d5f966d..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterialCell.ts +++ /dev/null @@ -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); - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterialCellColumn.ts b/packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterialCellColumn.ts deleted file mode 100644 index 3b35a386..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterialCellColumn.ts +++ /dev/null @@ -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; - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterialCellMatrix.ts b/packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterialCellMatrix.ts deleted file mode 100644 index 51c55af4..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneMaterialCellMatrix.ts +++ /dev/null @@ -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; - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneRasterizer.ts b/packages/room/src/object/visualization/room/rasterizer/basic/PlaneRasterizer.ts deleted file mode 100644 index 461a0009..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneRasterizer.ts +++ /dev/null @@ -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; - private _textures: Map; - private _planes: Map; - private _geometries: Map; - 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(); - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneTexture.ts b/packages/room/src/object/visualization/room/rasterizer/basic/PlaneTexture.ts deleted file mode 100644 index 763bb969..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneTexture.ts +++ /dev/null @@ -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; - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneTextureBitmap.ts b/packages/room/src/object/visualization/room/rasterizer/basic/PlaneTextureBitmap.ts deleted file mode 100644 index 78ab318b..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneTextureBitmap.ts +++ /dev/null @@ -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; - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneVisualization.ts b/packages/room/src/object/visualization/room/rasterizer/basic/PlaneVisualization.ts deleted file mode 100644 index 2ec37403..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneVisualization.ts +++ /dev/null @@ -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; - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneVisualizationLayer.ts b/packages/room/src/object/visualization/room/rasterizer/basic/PlaneVisualizationLayer.ts deleted file mode 100644 index 6586c612..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/PlaneVisualizationLayer.ts +++ /dev/null @@ -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; - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/WallPlane.ts b/packages/room/src/object/visualization/room/rasterizer/basic/WallPlane.ts deleted file mode 100644 index afd7663a..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/WallPlane.ts +++ /dev/null @@ -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); - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/WallRasterizer.ts b/packages/room/src/object/visualization/room/rasterizer/basic/WallRasterizer.ts deleted file mode 100644 index 5ef85d44..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/WallRasterizer.ts +++ /dev/null @@ -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); - } -} diff --git a/packages/room/src/object/visualization/room/rasterizer/basic/index.ts b/packages/room/src/object/visualization/room/rasterizer/basic/index.ts deleted file mode 100644 index 6f918391..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/basic/index.ts +++ /dev/null @@ -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'; diff --git a/packages/room/src/object/visualization/room/rasterizer/index.ts b/packages/room/src/object/visualization/room/rasterizer/index.ts deleted file mode 100644 index 11ffb821..00000000 --- a/packages/room/src/object/visualization/room/rasterizer/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './IPlaneRasterizer'; -export * from './animated'; -export * from './basic'; diff --git a/packages/room/src/renderer/utils/ExtendedSprite.ts b/packages/room/src/renderer/utils/ExtendedSprite.ts index 6b53865d..f9ddfffb 100644 --- a/packages/room/src/renderer/utils/ExtendedSprite.ts +++ b/packages/room/src/renderer/utils/ExtendedSprite.ts @@ -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;