feat: closer tank models

This commit is contained in:
TrèsAbhi committed 2024-01-29 15:27:21 -06:00
1 parent 4da4cf5259
commit 428a0bbad5
5 files changed
+45 -25

No files matched your search

+2 -2
View File
@@ -10,7 +10,7 @@ import { buildScratchedFlags } from './scratchedFlags';
import { buildShellIcons } from './shellIcons';
import { buildTankArmors } from './tankArmors';
import { buildTankIcons } from './tankIcons';
import { buildTankModels } from './tankModels';
import { tankModels } from './tankModels';
config();
@@ -24,7 +24,7 @@ const production = argv.includes('--production');
if (!targets && !allTargets) throw new Error('No target(s) specified');
const methods = [
buildTankModels,
tankModels,
buildTankArmors,
definitions,
buildTankIcons,
+1 -1
View File
@@ -15,7 +15,7 @@ interface VehicleCustomization {
armorColor: string;
}
export async function buildTankModels(production: boolean) {
export async function tankModels(production: boolean) {
console.log('Building tank models...');
const nodeIO = new NodeIO();
@@ -1,3 +1,4 @@
import { Environment } from '@react-three/drei';
import { useModel } from '../../../../../hooks/useModel';
import { useDuel } from '../../../../../stores/duel';
@@ -7,7 +8,8 @@ export function Lighting() {
return (
<>
<directionalLight
<Environment preset="dawn" />
{/* <directionalLight
position={[1, 1, -1]}
intensity={hasPbr ? 3 : 5}
castShadow
@@ -18,8 +20,7 @@ export function Lighting() {
intensity={hasPbr ? 2 : 4}
castShadow
color={'rgb(240, 255, 240)'}
/>
<ambientLight intensity={0.25} />
/> */}
</>
);
}
+14
View File
@@ -124,6 +124,20 @@ export async function extractModel(
),
);
}
if (textures.miscMap) {
material.setOcclusionTexture(
document
.createTexture(node.materialName)
.setMimeType('image/png')
.setImage(
await readTexture(
`${data}/3d/${dirname(path)}/${textures.miscMap}`,
{ mutation: TextureMutation.Miscellaneous },
),
),
);
}
}
materials.set(node['#id'].readBigUInt64LE(), material);
+24 -19
View File
@@ -1,5 +1,4 @@
import { existsSync } from 'fs';
import { clamp } from 'lodash';
import sharp from 'sharp';
import { Vector3Tuple } from 'three';
import { readDVPLFile } from '../blitz/readDVPLFile';
@@ -10,11 +9,15 @@ export enum TextureMutation {
Normal,
RoughnessMetallicness,
BaseColor,
Miscellaneous,
}
type ReadTextureOptions =
| {
mutation: TextureMutation.Normal | TextureMutation.RoughnessMetallicness;
mutation:
| TextureMutation.Normal
| TextureMutation.RoughnessMetallicness
| TextureMutation.Miscellaneous;
}
| {
mutation: TextureMutation.BaseColor;
@@ -75,25 +78,27 @@ export async function readTexture(path: string, options?: ReadTextureOptions) {
break;
}
case TextureMutation.RoughnessMetallicness: {
for (let index = 0; index < channels; index += 4) {
/**
* Green is ambient occlusion and alpha is emissive. But very few tanks
* use emissive so I am ignoring it for now.
*/
const occlusion = raw.data[index + 1];
// const emissive = raw.data[index + 3];
raw.data[index] = occlusion;
raw.data[index + 1] = 0;
raw.data[index + 2] = 0;
raw.data[index + 3] = 255;
}
break;
}
case TextureMutation.BaseColor: {
for (let index = 0; index < channels; index += 4) {
// treating as pre multiplied but I can't fully confirm
const r = raw.data[index] / 255;
const g = raw.data[index + 1] / 255;
const b = raw.data[index + 2] / 255;
const a = raw.data[index + 3] / 255;
if (a === 0) continue;
const invA = 1 - a;
const rPrime = r + invA * options.baseColor[0];
const gPrime = g + invA * options.baseColor[1];
const bPrime = b + invA * options.baseColor[2];
raw.data[index] = Math.round(clamp(rPrime * 255, 0, 255));
raw.data[index + 1] = Math.round(clamp(gPrime * 255, 0, 255));
raw.data[index + 2] = Math.round(clamp(bPrime * 255, 0, 255));
// alpha map is specularity but I am ignoring it for now
raw.data[index + 3] = 255;
}