mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-20 20:35:43 +01:00
feat: r5g6b5a0 format compatibility
This commit is contained in:
1 parent
86fd714923
commit
a362301515
5 files changed
+43
-10
No files matched your search
@@ -20,7 +20,7 @@ export async function buildTankArmors() {
|
|||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
nations.map(async (nation) => {
|
nations.map(async (nation) => {
|
||||||
if (nation !== 'usa') return;
|
if (nation !== 'germany') return;
|
||||||
|
|
||||||
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
|
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
|
||||||
`${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
|
`${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export async function buildTankModels() {
|
|||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
nations.map(async (nation) => {
|
nations.map(async (nation) => {
|
||||||
if (nation !== 'usa') return;
|
if (nation !== 'germany') return;
|
||||||
|
|
||||||
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
|
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
|
||||||
`${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
|
`${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
|
||||||
|
|||||||
+2
-2
@@ -21,11 +21,11 @@ import { Options } from './components/Options';
|
|||||||
import { TankArmor } from './components/TankArmor';
|
import { TankArmor } from './components/TankArmor';
|
||||||
import { TankModel } from './components/TankModel';
|
import { TankModel } from './components/TankModel';
|
||||||
|
|
||||||
interface TankDisplayProps {
|
interface TankSandboxProps {
|
||||||
duel: Duel;
|
duel: Duel;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TankDisplay({ duel }: TankDisplayProps) {
|
export function TankSandbox({ duel }: TankSandboxProps) {
|
||||||
const canvas = useRef<HTMLCanvasElement>(null);
|
const canvas = useRef<HTMLCanvasElement>(null);
|
||||||
const awaitedModelDefinitions = use(modelDefinitions);
|
const awaitedModelDefinitions = use(modelDefinitions);
|
||||||
const canvasWrapper = useRef<HTMLDivElement>(null);
|
const canvasWrapper = useRef<HTMLDivElement>(null);
|
||||||
@@ -8,7 +8,7 @@ import { tankDefinitions } from '../../../../core/blitzkrieg/tankDefinitions';
|
|||||||
import mutateTankopedia, { DuelMember } from '../../../../stores/tankopedia';
|
import mutateTankopedia, { DuelMember } from '../../../../stores/tankopedia';
|
||||||
import { AntagonistBar } from './components/AntagonistBar';
|
import { AntagonistBar } from './components/AntagonistBar';
|
||||||
import { Configure } from './components/Configure';
|
import { Configure } from './components/Configure';
|
||||||
import { TankDisplay } from './components/Model/TankDisplay';
|
import { TankSandbox } from './components/Model/TankSandbox';
|
||||||
import { Title } from './components/Title';
|
import { Title } from './components/Title';
|
||||||
|
|
||||||
export interface Duel {
|
export interface Duel {
|
||||||
@@ -81,7 +81,7 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
<Flex gap="8" direction="column">
|
<Flex gap="8" direction="column">
|
||||||
<Flex gap="4" direction="column">
|
<Flex gap="4" direction="column">
|
||||||
<Title duel={duel} />
|
<Title duel={duel} />
|
||||||
<TankDisplay duel={duel} />
|
<TankSandbox duel={duel} />
|
||||||
<AntagonistBar duel={duel} setDuel={setDuel} />
|
<AntagonistBar duel={duel} setDuel={setDuel} />
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
|
|||||||
+37
-4
@@ -1,5 +1,4 @@
|
|||||||
import { clamp, isEqual, times } from 'lodash';
|
import { clamp, isEqual, times } from 'lodash';
|
||||||
import { Vector4Tuple } from 'three';
|
|
||||||
import { BufferStream } from './buffer';
|
import { BufferStream } from './buffer';
|
||||||
|
|
||||||
export enum PvrFlags {
|
export enum PvrFlags {
|
||||||
@@ -89,12 +88,13 @@ enum PvrChannelType {
|
|||||||
|
|
||||||
enum ResolvedBitRatePixelFormat {
|
enum ResolvedBitRatePixelFormat {
|
||||||
R4G4B4A4,
|
R4G4B4A4,
|
||||||
|
R5G6B5A0,
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PvrStream extends BufferStream {
|
export class PvrStream extends BufferStream {
|
||||||
pvr() {
|
pvr() {
|
||||||
const header = this.header();
|
const header = this.header();
|
||||||
const metadata = this.metadata();
|
this.metadata();
|
||||||
|
|
||||||
if (typeof header.pixelFormat === 'number') {
|
if (typeof header.pixelFormat === 'number') {
|
||||||
switch (header.pixelFormat) {
|
switch (header.pixelFormat) {
|
||||||
@@ -114,7 +114,6 @@ export class PvrStream extends BufferStream {
|
|||||||
switch (resolvedPixelFormat) {
|
switch (resolvedPixelFormat) {
|
||||||
case ResolvedBitRatePixelFormat.R4G4B4A4: {
|
case ResolvedBitRatePixelFormat.R4G4B4A4: {
|
||||||
const data = Buffer.alloc(pixelCount * 4);
|
const data = Buffer.alloc(pixelCount * 4);
|
||||||
let lastPixel: Vector4Tuple;
|
|
||||||
|
|
||||||
times(pixelCount, (index) => {
|
times(pixelCount, (index) => {
|
||||||
const buffer = this.consume(2);
|
const buffer = this.consume(2);
|
||||||
@@ -138,6 +137,31 @@ export class PvrStream extends BufferStream {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ResolvedBitRatePixelFormat.R5G6B5A0: {
|
||||||
|
const data = Buffer.alloc(pixelCount * 3);
|
||||||
|
|
||||||
|
times(pixelCount, (index) => {
|
||||||
|
const buffer = this.consume(2);
|
||||||
|
const bufferIndex = index * 4;
|
||||||
|
const r = ((buffer[1] & 0b11111000) >>> 3) / 31;
|
||||||
|
const g =
|
||||||
|
((buffer[1] & 0b111) << 3) |
|
||||||
|
(((buffer[0] & 0b11100000) >>> 5) / 31);
|
||||||
|
const b = buffer[0] & 0b11111;
|
||||||
|
|
||||||
|
data[bufferIndex] = Math.round(clamp(r * 255, 0, 255));
|
||||||
|
data[bufferIndex + 1] = Math.round(clamp(g * 255, 0, 255));
|
||||||
|
data[bufferIndex + 2] = Math.round(clamp(b * 255, 0, 255));
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
width: header.width,
|
||||||
|
height: header.height,
|
||||||
|
channels: 3 as const,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`Unhandled resolved pixel format ${resolvedPixelFormat} (${header.pixelFormat})`,
|
`Unhandled resolved pixel format ${resolvedPixelFormat} (${header.pixelFormat})`,
|
||||||
@@ -188,7 +212,16 @@ export class PvrStream extends BufferStream {
|
|||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`Unhandled rgba bit rate ${pixelFormat.bitRates.join(', ')}`,
|
`Unhandled rgba bit rate ${pixelFormat.bitRates.join(', ')}`,
|
||||||
);
|
);
|
||||||
} else throw new TypeError(`Unhandled pixel order ${pixelFormat.order}`);
|
} else if (pixelFormat.order === 'rgb\0') {
|
||||||
|
if (isEqual(pixelFormat.bitRates, [5, 6, 5, 0])) {
|
||||||
|
return ResolvedBitRatePixelFormat.R5G6B5A0;
|
||||||
|
} else
|
||||||
|
throw new TypeError(
|
||||||
|
`Unhandled rgb bit rate ${pixelFormat.bitRates.join(', ')}`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw new TypeError(`Unhandled pixel order ${pixelFormat.order}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
metadata() {
|
metadata() {
|
||||||
const fourCC = this.ascii(4);
|
const fourCC = this.ascii(4);
|
||||||
|
|||||||
Reference in new issue
Block a user