You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 15:06:20 +00:00
🆙 added latest changes
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": [ "@nitrots/eslint-config" ]
|
||||
}
|
||||
@@ -5,18 +5,16 @@
|
||||
"type": "module",
|
||||
"license": "GPL-3.0",
|
||||
"scripts": {
|
||||
"compile": "tsc --project ./tsconfig.json --noEmit false",
|
||||
"eslint": "eslint ./src --fix"
|
||||
"compile": "tsc --project ./tsconfig.json --noEmit false"
|
||||
},
|
||||
"main": "./index",
|
||||
"dependencies": {
|
||||
"@nitrots/api": "1.0.0",
|
||||
"@nitrots/assets": "1.0.0",
|
||||
"@nitrots/configuration": "1.0.0",
|
||||
"@nitrots/eslint-config": "1.0.0",
|
||||
"@nitrots/events": "1.0.0",
|
||||
"@nitrots/utils": "1.0.0",
|
||||
"pixi.js": "^8.1.0"
|
||||
"pixi.js": "^8.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "~5.4.2"
|
||||
|
||||
@@ -3,19 +3,13 @@ import { GetAssetManager } from '@nitrots/assets';
|
||||
import { GetConfiguration } from '@nitrots/configuration';
|
||||
import { GetEventDispatcher, RoomCameraWidgetManagerEvent } from '@nitrots/events';
|
||||
import { TextureUtils } from '@nitrots/utils';
|
||||
import { BLEND_MODES, ColorMatrix, ColorMatrixFilter, Container, Sprite, Texture } from 'pixi.js';
|
||||
import { BLEND_MODES, ColorMatrix, ColorMatrixFilter, Container, Filter, Sprite, Texture } from 'pixi.js';
|
||||
import { RoomCameraWidgetEffect } from './RoomCameraWidgetEffect';
|
||||
|
||||
export class RoomCameraWidgetManager implements IRoomCameraWidgetManager
|
||||
{
|
||||
private _effects: Map<string, IRoomCameraWidgetEffect>;
|
||||
private _isLoaded: boolean;
|
||||
|
||||
constructor()
|
||||
{
|
||||
this._effects = new Map();
|
||||
this._isLoaded = false;
|
||||
}
|
||||
private _effects: Map<string, IRoomCameraWidgetEffect> = new Map();
|
||||
private _isLoaded: boolean = false;
|
||||
|
||||
public async init(): Promise<void>
|
||||
{
|
||||
@@ -52,7 +46,7 @@ export class RoomCameraWidgetManager implements IRoomCameraWidgetManager
|
||||
GetEventDispatcher().dispatchEvent(new RoomCameraWidgetManagerEvent(RoomCameraWidgetManagerEvent.INITIALIZED));
|
||||
}
|
||||
|
||||
public async applyEffects(texture: Texture, selectedEffects: IRoomCameraWidgetSelectedEffect[], isZoomed: boolean): Promise<HTMLImageElement>
|
||||
public async applyEffects(texture: Texture, effects: IRoomCameraWidgetSelectedEffect[], isZoomed: boolean): Promise<HTMLImageElement>
|
||||
{
|
||||
const container = new Container();
|
||||
const sprite = new Sprite(texture);
|
||||
@@ -61,7 +55,34 @@ export class RoomCameraWidgetManager implements IRoomCameraWidgetManager
|
||||
|
||||
if(isZoomed) sprite.scale.set(2);
|
||||
|
||||
for(const selectedEffect of selectedEffects)
|
||||
const filters: Filter[] = [];
|
||||
|
||||
const getColorMatrixFilter = (matrix: ColorMatrix, flag: boolean, strength: number): ColorMatrixFilter =>
|
||||
{
|
||||
const filter = new ColorMatrixFilter();
|
||||
|
||||
if(flag)
|
||||
{
|
||||
filter.matrix = matrix;
|
||||
}
|
||||
else
|
||||
{
|
||||
//@ts-ignore
|
||||
const newMatrix: ColorMatrix = [];
|
||||
const otherMatrix: ColorMatrix = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
|
||||
|
||||
for(let i = 0; i < matrix.length; i++)
|
||||
{
|
||||
newMatrix.push((matrix[i] * strength) + (otherMatrix[i] * (1 - strength)));
|
||||
}
|
||||
|
||||
filter.matrix = newMatrix;
|
||||
}
|
||||
|
||||
return filter;
|
||||
};
|
||||
|
||||
for(const selectedEffect of effects)
|
||||
{
|
||||
const effect = selectedEffect.effect;
|
||||
|
||||
@@ -69,26 +90,24 @@ export class RoomCameraWidgetManager implements IRoomCameraWidgetManager
|
||||
|
||||
if(effect.colorMatrix)
|
||||
{
|
||||
const filter = new ColorMatrixFilter();
|
||||
const filter = getColorMatrixFilter(effect.colorMatrix, false, selectedEffect.strength);
|
||||
|
||||
filter.matrix = effect.colorMatrix;
|
||||
filter.alpha = selectedEffect.alpha;
|
||||
|
||||
if(!Array.isArray(sprite.filters)) sprite.filters = [];
|
||||
|
||||
sprite.filters.push(filter);
|
||||
filters.push(filter);
|
||||
}
|
||||
else
|
||||
{
|
||||
const effectSprite = new Sprite(effect.texture);
|
||||
effectSprite.alpha = selectedEffect.alpha;
|
||||
|
||||
effectSprite.alpha = selectedEffect.strength;
|
||||
effectSprite.blendMode = effect.blendMode;
|
||||
|
||||
container.addChild(effectSprite);
|
||||
}
|
||||
}
|
||||
|
||||
return await TextureUtils.generateImage(container);
|
||||
container.filters = filters;
|
||||
|
||||
return await TextureUtils.generateImage(sprite);
|
||||
}
|
||||
|
||||
public get effects(): Map<string, IRoomCameraWidgetEffect>
|
||||
|
||||
@@ -3,12 +3,12 @@ import { IRoomCameraWidgetEffect } from '@nitrots/api';
|
||||
export class RoomCameraWidgetSelectedEffect
|
||||
{
|
||||
private _effect: IRoomCameraWidgetEffect;
|
||||
private _alpha: number;
|
||||
private _strength: number;
|
||||
|
||||
constructor(effect: IRoomCameraWidgetEffect, alpha: number)
|
||||
constructor(effect: IRoomCameraWidgetEffect, strength: number)
|
||||
{
|
||||
this._effect = effect;
|
||||
this._alpha = alpha;
|
||||
this._strength = strength;
|
||||
}
|
||||
|
||||
public get effect(): IRoomCameraWidgetEffect
|
||||
@@ -16,8 +16,8 @@ export class RoomCameraWidgetSelectedEffect
|
||||
return this._effect;
|
||||
}
|
||||
|
||||
public get alpha(): number
|
||||
public get strength(): number
|
||||
{
|
||||
return this._alpha;
|
||||
return this._strength;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,5 @@
|
||||
"ESNext"
|
||||
],
|
||||
"module": "ES6"
|
||||
},
|
||||
"include": [
|
||||
"src" ]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user