This commit is contained in:
billsonnn 2024-04-03 18:25:57 -04:00
parent 8d7fc1e9b4
commit 1df42159a7
4 changed files with 59 additions and 38 deletions

View File

@ -1,5 +1,11 @@
export class AvatarFigurePartType export class AvatarFigurePartType
{ {
public static MALE: string = 'M';
public static FEMALE: string = 'F';
public static UNISEX: string = 'U';
public static SCALE: string = 'h';
public static STD: string = 'std';
public static DEFAULT_FRAME: number = 0;
public static BODY: string = 'bd'; public static BODY: string = 'bd';
public static SHOES: string = 'sh'; public static SHOES: string = 'sh';
public static LEGS: string = 'lg'; public static LEGS: string = 'lg';

View File

@ -1,25 +1,25 @@
export class FigureDataContainer export class FigureDataContainer
{ {
private static MALE: string = 'M'; public static MALE: string = 'M';
private static FEMALE: string = 'F'; public static FEMALE: string = 'F';
private static UNISEX: string = 'U'; public static UNISEX: string = 'U';
private static SCALE: string = 'h'; public static SCALE: string = 'h';
private static STD: string = 'std'; public static STD: string = 'std';
private static DEFAULT_FRAME: string = '0'; public static DEFAULT_FRAME: string = '0';
private static HD: string = 'hd'; public static HD: string = 'hd';
private static HAIR: string = 'hr'; public static HAIR: string = 'hr';
private static HAT: string = 'ha'; public static HAT: string = 'ha';
private static HEAD_ACCESSORIES: string = 'he'; public static HEAD_ACCESSORIES: string = 'he';
private static EYE_ACCESSORIES: string = 'ea'; public static EYE_ACCESSORIES: string = 'ea';
private static FACE_ACCESSORIES: string = 'fa'; public static FACE_ACCESSORIES: string = 'fa';
private static JACKET: string = 'cc'; public static JACKET: string = 'cc';
private static SHIRT: string = 'ch'; public static SHIRT: string = 'ch';
private static CHEST_ACCESSORIES: string = 'ca'; public static CHEST_ACCESSORIES: string = 'ca';
private static CHEST_PRINTS: string = 'cp'; public static CHEST_PRINTS: string = 'cp';
private static TROUSERS: string = 'lg'; public static TROUSERS: string = 'lg';
private static SHOES: string = 'sh'; public static SHOES: string = 'sh';
private static TROUSER_ACCESSORIES: string = 'wa'; public static TROUSER_ACCESSORIES: string = 'wa';
private static BLOCKED_FX_TYPES: number[] = [28, 29, 30, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 68]; public static BLOCKED_FX_TYPES: number[] = [28, 29, 30, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 68];
private _data: Map<string, number>; private _data: Map<string, number>;
private _colors: Map<string, number[]>; private _colors: Map<string, number[]>;

View File

@ -11,6 +11,7 @@
"main": "./index", "main": "./index",
"dependencies": { "dependencies": {
"@nitrots/api": "1.0.0", "@nitrots/api": "1.0.0",
"@nitrots/assets": "1.0.0",
"@nitrots/configuration": "1.0.0", "@nitrots/configuration": "1.0.0",
"@nitrots/eslint-config": "1.0.0", "@nitrots/eslint-config": "1.0.0",
"@nitrots/events": "1.0.0", "@nitrots/events": "1.0.0",

View File

@ -1,6 +1,6 @@
import { AlphaTolerance } from '@nitrots/api'; import { AlphaTolerance } from '@nitrots/api';
import { GetRenderer } from '@nitrots/utils'; import { GetRenderer, TextureUtils } from '@nitrots/utils';
import { GlRenderTarget, Point, Sprite, Texture, TextureSource, WebGLRenderer } from 'pixi.js'; import { GlRenderTarget, Point, RendererType, Sprite, Texture, TextureSource, WebGPURenderer } from 'pixi.js';
const BYTES_PER_PIXEL = 4; const BYTES_PER_PIXEL = 4;
@ -56,7 +56,9 @@ export class ExtendedSprite extends Sprite
if((!textureSource || !textureSource.hitMap) && !ExtendedSprite.generateHitMapForTextureSource(textureSource)) return false; if((!textureSource || !textureSource.hitMap) && !ExtendedSprite.generateHitMapForTextureSource(textureSource)) return false;
//@ts-ignore //@ts-ignore
const hitMap = (textureSource.hitMap as U8intclampedArray); const hitMap = (textureSource.hitMap as Uint8Array);
if(!hitMap) return false;
let dx = (point.x + texture.frame.x); let dx = (point.x + texture.frame.x);
let dy = (point.y + texture.frame.y); let dy = (point.y + texture.frame.y);
@ -79,28 +81,40 @@ export class ExtendedSprite extends Sprite
{ {
if(!textureSource) return false; if(!textureSource) return false;
const renderer = GetRenderer();
const width = Math.max(Math.round(textureSource.width * textureSource.resolution), 1); const width = Math.max(Math.round(textureSource.width * textureSource.resolution), 1);
const height = Math.max(Math.round(textureSource.height * textureSource.resolution), 1); const height = Math.max(Math.round(textureSource.height * textureSource.resolution), 1);
const pixels = new Uint8Array(BYTES_PER_PIXEL * width * height);
const renderer = GetRenderer() as WebGLRenderer; let pixels: Uint8ClampedArray = null;
const renderTarget = renderer.renderTarget.getRenderTarget(textureSource); if(renderer instanceof WebGPURenderer)
const glRenterTarget = renderer.renderTarget.getGpuRenderTarget(renderTarget) as GlRenderTarget; {
pixels = TextureUtils.getPixels(new Texture(textureSource))?.pixels ?? null;
}
const gl = renderer.gl; else if(renderer.type === RendererType.WEBGL)
{
pixels = new Uint8ClampedArray(BYTES_PER_PIXEL * width * height);
gl.bindFramebuffer(gl.FRAMEBUFFER, glRenterTarget.resolveTargetFramebuffer); const renderTarget = renderer.renderTarget.getRenderTarget(textureSource);
const glRenderTarget = renderer.renderTarget.getGpuRenderTarget(renderTarget) as GlRenderTarget;
gl.readPixels( const gl = renderer.gl;
0,
0, gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.resolveTargetFramebuffer);
width,
height, gl.readPixels(
gl.RGBA, 0,
gl.UNSIGNED_BYTE, 0,
pixels width,
); height,
gl.RGBA,
gl.UNSIGNED_BYTE,
pixels
);
}
if(!pixels) return false;
//@ts-ignore //@ts-ignore
textureSource.hitMap = pixels; textureSource.hitMap = pixels;