fix: negative hard joint handling... correctly this time

This commit is contained in:
TrèsAbhi committed 2024-01-12 20:20:51 -06:00
1 parent 062e6e9626
commit 0582339332
4 files changed
+30 -20

No files matched your search

@@ -14,6 +14,7 @@ import {
modelDefinitions, modelDefinitions,
} from '../../../../../../../core/blitzkrieg/modelDefinitions'; } from '../../../../../../../core/blitzkrieg/modelDefinitions';
import { nameToArmorId } from '../../../../../../../core/blitzkrieg/nameToArmorId'; import { nameToArmorId } from '../../../../../../../core/blitzkrieg/nameToArmorId';
import { resolveArmor } from '../../../../../../../core/blitzkrieg/resolveThickness';
import { useTankopedia } from '../../../../../../../stores/tankopedia'; import { useTankopedia } from '../../../../../../../stores/tankopedia';
import { Lighting } from '../../Lighting'; import { Lighting } from '../../Lighting';
@@ -109,15 +110,17 @@ export function TankArmor({ ...props }: TankArmorProps) {
> >
{armorNodes.map((node) => { {armorNodes.map((node) => {
const isHull = node.name.startsWith('hull_'); const isHull = node.name.startsWith('hull_');
const armorId = nameToArmorId(node.name);
const isVisible = isHull; const isVisible = isHull;
const thickness = tankModelDefinition.armor.thickness[armorId]; const armorId = nameToArmorId(node.name);
const isSpaced = tankModelDefinition.armor.spaced?.includes(armorId); const { spaced, thickness } = resolveArmor(
tankModelDefinition.armor,
armorId,
);
if ( if (
!isVisible || !isVisible ||
thickness === undefined || thickness === undefined ||
(isSpaced && !showSpacedArmor) (spaced && !showSpacedArmor)
) )
return null; return null;
@@ -128,7 +131,7 @@ export function TankArmor({ ...props }: TankArmorProps) {
caliber={antagonist.shell.caliber} caliber={antagonist.shell.caliber}
canSplash={splashCapable} canSplash={splashCapable}
isExplosive={explosiveCapable} isExplosive={explosiveCapable}
isSpaced={isSpaced ?? false} isSpaced={spaced ?? false}
normalization={normalization} normalization={normalization}
penetration={penetration} penetration={penetration}
thickness={thickness} thickness={thickness}
@@ -172,14 +175,15 @@ export function TankArmor({ ...props }: TankArmorProps) {
); );
const isVisible = isCurrentTurret; const isVisible = isCurrentTurret;
const armorId = nameToArmorId(node.name); const armorId = nameToArmorId(node.name);
const thickness = turretModelDefinition.armor.thickness[armorId]; const { spaced, thickness } = resolveArmor(
const isSpaced = turretModelDefinition.armor,
turretModelDefinition.armor.spaced?.includes(armorId); armorId,
);
if ( if (
!isVisible || !isVisible ||
thickness === undefined || thickness === undefined ||
(isSpaced && !showSpacedArmor) (spaced && !showSpacedArmor)
) )
return null; return null;
@@ -191,7 +195,7 @@ export function TankArmor({ ...props }: TankArmorProps) {
caliber={antagonist.shell.caliber} caliber={antagonist.shell.caliber}
canSplash={splashCapable} canSplash={splashCapable}
isExplosive={explosiveCapable} isExplosive={explosiveCapable}
isSpaced={isSpaced ?? false} isSpaced={spaced ?? false}
normalization={normalization} normalization={normalization}
penetration={penetration} penetration={penetration}
thickness={thickness} thickness={thickness}
@@ -216,14 +220,15 @@ export function TankArmor({ ...props }: TankArmorProps) {
); );
const isVisible = isCurrentGun; const isVisible = isCurrentGun;
const armorId = nameToArmorId(node.name); const armorId = nameToArmorId(node.name);
const thickness = gunModelDefinition.armor.thickness[armorId]; const { spaced, thickness } = resolveArmor(
const isSpaced = gunModelDefinition.armor,
gunModelDefinition.armor.spaced?.includes(armorId); armorId,
);
if ( if (
!isVisible || !isVisible ||
thickness === undefined || thickness === undefined ||
(isSpaced && !showSpacedArmor) (spaced && !showSpacedArmor)
) )
return null; return null;
@@ -235,7 +240,7 @@ export function TankArmor({ ...props }: TankArmorProps) {
caliber={antagonist.shell.caliber} caliber={antagonist.shell.caliber}
canSplash={splashCapable} canSplash={splashCapable}
isExplosive={explosiveCapable} isExplosive={explosiveCapable}
isSpaced={isSpaced ?? false} isSpaced={spaced ?? false}
normalization={normalization} normalization={normalization}
penetration={penetration} penetration={penetration}
thickness={thickness} thickness={thickness}
+1 -4
View File
@@ -58,10 +58,7 @@ export async function extractArmor(data: string, fileName: string) {
attributes.get(attribute)!.push(value); attributes.get(attribute)!.push(value);
if ( if (attribute === VertexAttribute.HARD_JOINTINDEX) {
attribute === VertexAttribute.HARD_JOINTINDEX &&
value[0] !== -1
) {
hardJointIndices.add(value[0]); hardJointIndices.add(value[0]);
vertexHardJointIndices.set(index, value[0]); vertexHardJointIndices.set(index, value[0]);
} }
+1 -1
View File
@@ -1,5 +1,5 @@
export function nameToArmorId(name: string) { export function nameToArmorId(name: string) {
const match = name.match(/.+_armor_(\d+)/); const match = name.match(/.+_armor_(-?\d+)/);
const group1 = match![1]; const group1 = match![1];
return parseInt(group1); return parseInt(group1);
+8
View File
@@ -0,0 +1,8 @@
import { ModelArmor } from './modelDefinitions';
export function resolveArmor(armor: ModelArmor, index: number) {
const spaced = armor.spaced?.includes(index) ?? false;
const thickness = index === -1 ? 0 : armor.thickness[index] ?? 0;
return { spaced, thickness };
}