feat: more game parity

This commit is contained in:
TrèsAbhi committed 2023-12-29 12:41:21 -06:00
1 parent 7b136e61a1
commit b90938108a
2 files changed
+21 -20

No files matched your search

+3
View File
@@ -514,8 +514,11 @@ if (allTargets || targets?.includes('tankModels')) {
const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1; const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1;
if (id !== 15697) continue; // chieftain TODO: investigate vertices stream over read if (id !== 15697) continue; // chieftain TODO: investigate vertices stream over read
// if (id !== 24609) continue; // concept 1b
// if (id !== 4417) continue; // amx m4 mle // if (id !== 4417) continue; // amx m4 mle
// if (id !== 7297) continue; // 60tp // if (id !== 7297) continue; // 60tp
// if (id !== 1) continue; // t-34
console.log(`Building model ${id} @ ${nation}/${tankIndex}`); console.log(`Building model ${id} @ ${nation}/${tankIndex}`);
const parameters = await readYAMLDVPL<TankParameters>( const parameters = await readYAMLDVPL<TankParameters>(
+18 -20
View File
@@ -1,3 +1,4 @@
import { clamp } from 'lodash';
import sharp from 'sharp'; import sharp from 'sharp';
import { Vector3Tuple } from 'three'; import { Vector3Tuple } from 'three';
import { readDVPLFile } from '../blitz/readDVPLFile'; import { readDVPLFile } from '../blitz/readDVPLFile';
@@ -35,20 +36,15 @@ export async function readTexture(path: string, options?: ReadTextureOptions) {
switch (options?.mutation) { switch (options?.mutation) {
case TextureMutation.Normal: { case TextureMutation.Normal: {
for (let index = 0; index < channels; index += 4) { for (let index = 0; index < channels; index += 4) {
let x = dds.data[index + 3] / 255; // TODO: this math is pretty sus and looks very goofy when rendered
let y = dds.data[index + 1] / 255; let x = dds.data[index + 3] * (2 / 255) - 1;
let z = Math.sqrt(1 - x ** 2 - y ** 2); let y = dds.data[index + 1] * (2 / 255) - 1;
const hypot = Math.sqrt(x ** 2 + y ** 2 + z ** 2); const underSqrt = 1 - x ** 2 - y ** 2;
let z = underSqrt > 0 ? Math.sqrt(underSqrt) : -Math.sqrt(-underSqrt);
if (isFinite(hypot)) { dds.data[index] = Math.round((x + 1) * (255 / 2));
x /= hypot; dds.data[index + 1] = Math.round((y + 1) * (255 / 2));
y /= hypot; dds.data[index + 2] = Math.round((z + 1) * (255 / 2));
z /= hypot;
}
dds.data[index] = Math.round(x * 255);
dds.data[index + 1] = Math.round(y * 255);
dds.data[index + 2] = Math.round(z * 255);
dds.data[index + 3] = 255; dds.data[index + 3] = 255;
} }
@@ -71,18 +67,20 @@ export async function readTexture(path: string, options?: ReadTextureOptions) {
case TextureMutation.BaseColor: { case TextureMutation.BaseColor: {
for (let index = 0; index < channels; index += 4) { for (let index = 0; index < channels; index += 4) {
// treating as pre multiplied but I can't fully confirm
const r = dds.data[index] / 255; const r = dds.data[index] / 255;
const g = dds.data[index + 1] / 255; const g = dds.data[index + 1] / 255;
const b = dds.data[index + 2] / 255; const b = dds.data[index + 2] / 255;
const a = dds.data[index + 3] / 255; const a = dds.data[index + 3] / 255;
const inverseA = 1 - a; const invA = 1 - a;
const mixedR = a * r + inverseA * options.baseColor[0]; const rPrime = invA * options.baseColor[0] + r;
const mixedG = a * g + inverseA * options.baseColor[1]; const gPrime = invA * options.baseColor[1] + g;
const mixedB = a * b + inverseA * options.baseColor[2]; const bPrime = invA * options.baseColor[2] + b;
dds.data[index] = mixedR * 255; dds.data[index] = Math.round(clamp(rPrime * 255, 0, 255));
dds.data[index + 1] = mixedG * 255; dds.data[index + 1] = Math.round(clamp(gPrime * 255, 0, 255));
dds.data[index + 2] = mixedB * 255; dds.data[index + 2] = Math.round(clamp(bPrime * 255, 0, 255));
dds.data[index + 3] = 255; dds.data[index + 3] = 255;
} }