diff --git a/scripts/buildAssets/index.ts b/scripts/buildAssets/index.ts index 59a77eef3..0e48d0bbb 100644 --- a/scripts/buildAssets/index.ts +++ b/scripts/buildAssets/index.ts @@ -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, diff --git a/scripts/buildAssets/tankModels.ts b/scripts/buildAssets/tankModels.ts index b6309a8cd..02b37b258 100644 --- a/scripts/buildAssets/tankModels.ts +++ b/scripts/buildAssets/tankModels.ts @@ -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(); diff --git a/src/app/tools/tankopedia/[id]/components/Lighting.tsx b/src/app/tools/tankopedia/[id]/components/Lighting.tsx index b2f7f49f8..237d2cc62 100644 --- a/src/app/tools/tankopedia/[id]/components/Lighting.tsx +++ b/src/app/tools/tankopedia/[id]/components/Lighting.tsx @@ -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 ( <> - + {/* - + /> */} ); } diff --git a/src/core/blitz/extractModel.ts b/src/core/blitz/extractModel.ts index ff186d095..e06c7f97a 100644 --- a/src/core/blitz/extractModel.ts +++ b/src/core/blitz/extractModel.ts @@ -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); diff --git a/src/core/blitzkrieg/readTexture.ts b/src/core/blitzkrieg/readTexture.ts index b418344fd..5dcf10346 100644 --- a/src/core/blitzkrieg/readTexture.ts +++ b/src/core/blitzkrieg/readTexture.ts @@ -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; }