mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
Fix: calculate tank dimensions from collision models
This commit is contained in:
1 parent
7234c39ad8
commit
57d77bf2b4
9 files changed
+201
-82
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
normalizeBoundingBox,
|
||||
resolveDpm,
|
||||
unionBoundingBox,
|
||||
tankBoundingBox,
|
||||
type TankDefinition,
|
||||
} from "@blitzkit/core";
|
||||
import { useMemo } from "react";
|
||||
@@ -112,10 +112,7 @@ export function TankSearchCard({ tank, onSelect }: TankSearchCardProps) {
|
||||
return (tank.camouflage_still * gun.camouflage_loss * 100).toFixed(0);
|
||||
case "survivability.volume": {
|
||||
const dimensions = normalizeBoundingBox(
|
||||
unionBoundingBox(
|
||||
tankModelDefinition.bounding_box!,
|
||||
turretModelDefinition.bounding_box!,
|
||||
),
|
||||
tankBoundingBox(tankModelDefinition, turretModelDefinition),
|
||||
);
|
||||
|
||||
return (dimensions.x * dimensions.y * dimensions.z).toFixed(0);
|
||||
@@ -123,10 +120,7 @@ export function TankSearchCard({ tank, onSelect }: TankSearchCardProps) {
|
||||
|
||||
case "survivability.length": {
|
||||
const bounds = normalizeBoundingBox(
|
||||
unionBoundingBox(
|
||||
tankModelDefinition.bounding_box!,
|
||||
turretModelDefinition.bounding_box!,
|
||||
),
|
||||
tankBoundingBox(tankModelDefinition, turretModelDefinition),
|
||||
);
|
||||
|
||||
return Math.max(bounds.x, bounds.y, bounds.z).toFixed(0);
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
normalizeBoundingBox,
|
||||
resolveDpm,
|
||||
SEARCH_KEYS,
|
||||
unionBoundingBox,
|
||||
tankBoundingBox,
|
||||
type TankDefinition,
|
||||
} from "@blitzkit/core";
|
||||
import { literals } from "@blitzkit/i18n/src/literals";
|
||||
@@ -137,16 +137,10 @@ export const TankSearch = memo<TankSearchProps>(
|
||||
const bTurretModelDefinition =
|
||||
bTankModelDefinition.turrets[b.turrets.at(-1)!.id];
|
||||
const aSize = normalizeBoundingBox(
|
||||
unionBoundingBox(
|
||||
aTankModelDefinition.bounding_box!,
|
||||
aTurretModelDefinition.bounding_box!,
|
||||
),
|
||||
tankBoundingBox(aTankModelDefinition, aTurretModelDefinition),
|
||||
);
|
||||
const bSize = normalizeBoundingBox(
|
||||
unionBoundingBox(
|
||||
bTankModelDefinition.bounding_box!,
|
||||
bTurretModelDefinition.bounding_box!,
|
||||
),
|
||||
tankBoundingBox(bTankModelDefinition, bTurretModelDefinition),
|
||||
);
|
||||
const aVolume = aSize.x * aSize.y * aSize.z;
|
||||
const bVolume = bSize.x * bSize.y * bSize.z;
|
||||
@@ -164,16 +158,10 @@ export const TankSearch = memo<TankSearchProps>(
|
||||
const bTurretModelDefinition =
|
||||
bTankModelDefinition.turrets[b.turrets.at(-1)!.id];
|
||||
const aSize = normalizeBoundingBox(
|
||||
unionBoundingBox(
|
||||
aTankModelDefinition.bounding_box!,
|
||||
aTurretModelDefinition.bounding_box!,
|
||||
),
|
||||
tankBoundingBox(aTankModelDefinition, aTurretModelDefinition),
|
||||
);
|
||||
const bSize = normalizeBoundingBox(
|
||||
unionBoundingBox(
|
||||
bTankModelDefinition.bounding_box!,
|
||||
bTurretModelDefinition.bounding_box!,
|
||||
),
|
||||
tankBoundingBox(bTankModelDefinition, bTurretModelDefinition),
|
||||
);
|
||||
const aLength = Math.max(aSize.x, aSize.y, aSize.z);
|
||||
const bLength = Math.max(bSize.x, bSize.y, bSize.z);
|
||||
|
||||
@@ -8,8 +8,8 @@ import {
|
||||
resolvePenetrationCoefficient,
|
||||
ShellType,
|
||||
sum,
|
||||
tankBoundingBox,
|
||||
TankClass,
|
||||
unionBoundingBox,
|
||||
type EngineDefinition,
|
||||
type EquipmentDefinitions,
|
||||
type GunDefinition,
|
||||
@@ -335,10 +335,7 @@ export function tankCharacteristics(
|
||||
);
|
||||
|
||||
const size = normalizeBoundingBox(
|
||||
unionBoundingBox(
|
||||
tankModelDefinition.bounding_box!,
|
||||
turretModelDefinition.bounding_box!,
|
||||
),
|
||||
tankBoundingBox(tankModelDefinition, turretModelDefinition),
|
||||
);
|
||||
const weightKg =
|
||||
tank.weight + engine.weight + track.weight + turret.weight + gun.weight;
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import {
|
||||
parseHierarchies,
|
||||
Sc2ReadStream,
|
||||
ScgReadStream,
|
||||
toUniqueId,
|
||||
VertexAttribute,
|
||||
vertexAttributeVectorSizes,
|
||||
type Hierarchy,
|
||||
type VehicleDefinitionList,
|
||||
} from "@blitzkit/core";
|
||||
import type { AbstractVFS } from "@blitzkit/core/src/blitzkit/vfs/abstract";
|
||||
import { Accessor, Document, Node, NodeIO, Scene } from "@gltf-transform/core";
|
||||
import type { APIContext } from "astro";
|
||||
import { times } from "lodash-es";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
|
||||
export { getStaticPaths } from "./_index";
|
||||
@@ -56,13 +55,10 @@ async function extractArmor(vfs: AbstractVFS, fileName: string) {
|
||||
const scene = document.createScene();
|
||||
const buffer = document.createBuffer();
|
||||
|
||||
function parseHierarchies(hierarchies: Hierarchy[], parent: Scene | Node) {
|
||||
hierarchies.forEach((hierarchy) => {
|
||||
const components = times(
|
||||
hierarchy.components.count,
|
||||
(index) => hierarchy.components[index.toString().padStart(4, "0")],
|
||||
);
|
||||
|
||||
parseHierarchies<Scene | Node>(
|
||||
sc2["#hierarchy"],
|
||||
scene,
|
||||
(hierarchy, components, parent) => {
|
||||
components.forEach((component) => {
|
||||
switch (component["comp.typename"]) {
|
||||
case "TransformComponent":
|
||||
@@ -163,13 +159,9 @@ async function extractArmor(vfs: AbstractVFS, fileName: string) {
|
||||
}
|
||||
});
|
||||
|
||||
if (hierarchy["#hierarchy"]) {
|
||||
parseHierarchies(hierarchy["#hierarchy"], parent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
parseHierarchies(sc2["#hierarchy"], scene);
|
||||
return parent;
|
||||
},
|
||||
);
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import {
|
||||
bufferToBigInt,
|
||||
DdsReadStream,
|
||||
parseHierarchies,
|
||||
PvrReadStream,
|
||||
Sc2ReadStream,
|
||||
ScgReadStream,
|
||||
toUniqueId,
|
||||
VertexAttribute,
|
||||
type ConfigArchive,
|
||||
type Hierarchy,
|
||||
type TankParameters,
|
||||
type Textures,
|
||||
type VehicleDefinitionList,
|
||||
@@ -240,8 +240,10 @@ async function extractModel(vfs: AbstractVFS, path: string) {
|
||||
materials.set(id, resolvedMaterial);
|
||||
});
|
||||
|
||||
function parseHierarchies(hierarchies: Hierarchy[], parent: Scene | Node) {
|
||||
hierarchies.forEach((hierarchy) => {
|
||||
parseHierarchies<Scene | Node>(
|
||||
sc2["#hierarchy"],
|
||||
scene,
|
||||
(hierarchy, components, parent) => {
|
||||
if (
|
||||
omitMeshNames.start.some((omit) => hierarchy.name.startsWith(omit)) ||
|
||||
omitMeshNames.end.some((omit) => hierarchy.name.endsWith(omit))
|
||||
@@ -249,10 +251,6 @@ async function extractModel(vfs: AbstractVFS, path: string) {
|
||||
return;
|
||||
|
||||
const node = document.createNode(hierarchy.name);
|
||||
const components = times(
|
||||
hierarchy.components.count,
|
||||
(index) => hierarchy.components[index.toString().padStart(4, "0")],
|
||||
);
|
||||
|
||||
components.forEach((component) => {
|
||||
switch (component["comp.typename"]) {
|
||||
@@ -361,15 +359,11 @@ async function extractModel(vfs: AbstractVFS, path: string) {
|
||||
}
|
||||
});
|
||||
|
||||
if (hierarchy["#hierarchy"]) {
|
||||
parseHierarchies(hierarchy["#hierarchy"], node);
|
||||
}
|
||||
|
||||
parent.addChild(node);
|
||||
});
|
||||
}
|
||||
|
||||
parseHierarchies(sc2["#hierarchy"], scene);
|
||||
return node;
|
||||
},
|
||||
);
|
||||
|
||||
scene.addChild(document.createNode("test"));
|
||||
|
||||
|
||||
Reference in new issue
Block a user