mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +02:00
feat: moved to blitzkrieg assets
This commit is contained in:
1 parent
f9ccb06d1f
commit
6aa4686c30
21 files changed
+55
-99
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,18 +1,18 @@
|
||||
import { NodeIO } from '@gltf-transform/core';
|
||||
import { readdir, writeFile } from 'fs/promises';
|
||||
import { readdir } from 'fs/promises';
|
||||
import { extractArmor } from '../../src/core/blitz/extractArmor';
|
||||
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
|
||||
import { toUniqueId } from '../../src/core/blitz/toUniqueId';
|
||||
import commitMultipleFiles, {
|
||||
FileChange,
|
||||
} from '../../src/core/blitzkrieg/commitMultipleFiles';
|
||||
import { DATA, DOI } from './constants';
|
||||
import { VehicleDefinitionList } from './definitions';
|
||||
|
||||
BigInt.prototype.toJSON = function () {
|
||||
return this.toString();
|
||||
};
|
||||
|
||||
export async function buildTankArmors() {
|
||||
console.log('Building tank armors...');
|
||||
|
||||
const changes: FileChange[] = [];
|
||||
const nodeIO = new NodeIO();
|
||||
const nations = await readdir(`${DATA}/${DOI.vehicleDefinitions}`).then(
|
||||
(nations) => nations.filter((nation) => nation !== 'common'),
|
||||
@@ -36,10 +36,23 @@ export async function buildTankArmors() {
|
||||
|
||||
const model = await extractArmor(DATA, `${nation}-${tankKey}`);
|
||||
|
||||
writeFile(`temp/armor/${id}.glb`, await nodeIO.writeBinary(model));
|
||||
|
||||
// writeFile('test.sc2.json', JSON.stringify(sc2, null, 2));
|
||||
changes.push({
|
||||
path: `3d/tanks/armor/${id}.glb`,
|
||||
encoding: 'base64',
|
||||
content: Buffer.from(await nodeIO.writeBinary(model)).toString(
|
||||
'base64',
|
||||
),
|
||||
});
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
await commitMultipleFiles(
|
||||
'tresabhi',
|
||||
'blitzkrieg-assets',
|
||||
'main',
|
||||
'tank armor',
|
||||
changes,
|
||||
true,
|
||||
);
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
import { NodeIO } from '@gltf-transform/core';
|
||||
import { readdir, writeFile } from 'fs/promises';
|
||||
import { readdir } from 'fs/promises';
|
||||
import { Vector3Tuple } from 'three';
|
||||
import { extractModel } from '../../src/core/blitz/extractModel';
|
||||
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
|
||||
import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL';
|
||||
import { toUniqueId } from '../../src/core/blitz/toUniqueId';
|
||||
import commitMultipleFiles, {
|
||||
FileChange,
|
||||
} from '../../src/core/blitzkrieg/commitMultipleFiles';
|
||||
import { DATA, DOI } from './constants';
|
||||
import { VehicleDefinitionList } from './definitions';
|
||||
import { TankParameters } from './tankIcons';
|
||||
@@ -16,6 +19,7 @@ interface VehicleCustomization {
|
||||
export async function buildTankModels() {
|
||||
console.log('Building tank models...');
|
||||
|
||||
const changes: FileChange[] = [];
|
||||
const nodeIO = new NodeIO();
|
||||
const nations = await readdir(`${DATA}/${DOI.vehicleDefinitions}`).then(
|
||||
(nations) => nations.filter((nation) => nation !== 'common'),
|
||||
@@ -45,10 +49,10 @@ export async function buildTankModels() {
|
||||
// if (id !== 7425) continue; // isu 152
|
||||
// if (id !== 10369) continue; // mino
|
||||
// if (id !== 4417) continue; // amx m4 mle
|
||||
// if (id !== 7297) continue; // 60tp
|
||||
if (id !== 7297) continue; // 60tp
|
||||
// if (id !== 1) continue; // t-34
|
||||
// if (id !== 6753) continue; // type 71
|
||||
if (id !== 5137) continue; // tiger ii
|
||||
// if (id !== 5137) continue; // tiger ii
|
||||
// if (id !== 11633) continue; // forest witch
|
||||
// if (id !== 6225) continue; // fv215b
|
||||
// if (id !== 4481) continue; // kran
|
||||
@@ -67,8 +71,23 @@ export async function buildTankModels() {
|
||||
baseColor,
|
||||
);
|
||||
|
||||
writeFile(`public/test/${id}.glb`, await nodeIO.writeBinary(model));
|
||||
changes.push({
|
||||
path: `3d/tanks/models/${id}.glb`,
|
||||
encoding: 'base64',
|
||||
content: Buffer.from(await nodeIO.writeBinary(model)).toString(
|
||||
'base64',
|
||||
),
|
||||
});
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
await commitMultipleFiles(
|
||||
'tresabhi',
|
||||
'blitzkrieg-assets',
|
||||
'main',
|
||||
'tank models',
|
||||
changes,
|
||||
true,
|
||||
);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
import { Group, Vector3 } from 'three';
|
||||
import { GLTFLoader } from 'three-stdlib';
|
||||
import { X_AXIS } from '../../../../../../../constants/axis';
|
||||
import { asset } from '../../../../../../../core/blitzkrieg/asset';
|
||||
import {
|
||||
ModelDefinitions,
|
||||
modelDefinitions,
|
||||
@@ -33,7 +34,10 @@ export const TankModel = forwardRef<Group>((_props, ref) => {
|
||||
|
||||
if (!protagonist) return null;
|
||||
|
||||
const gltf = useLoader(GLTFLoader, `/test/${protagonist.tank.id}.glb`);
|
||||
const gltf = useLoader(
|
||||
GLTFLoader,
|
||||
asset(`3d/tanks/models/${protagonist.tank.id}.glb`),
|
||||
);
|
||||
const model = useTankopedia((state) => state.model);
|
||||
const hullContainer = useRef<Group>(null);
|
||||
const turretContainer = useRef<Group>(null);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Accessor, Document, Node, Scene } from '@gltf-transform/core';
|
||||
import { times } from 'lodash';
|
||||
import { Matrix4, Quaternion, Vector3, Vector4Tuple } from 'three';
|
||||
import { Hierarchy, Sc2Stream } from '../streams/sc2';
|
||||
import { ScgStream } from '../streams/scg';
|
||||
import { VertexAttribute } from '../streams/scpg';
|
||||
@@ -25,7 +24,6 @@ export async function extractArmor(data: string, fileName: string) {
|
||||
|
||||
function parseHierarchies(hierarchies: Hierarchy[], parent: Scene | Node) {
|
||||
hierarchies.forEach((hierarchy) => {
|
||||
const node = document.createNode(hierarchy.name);
|
||||
const components = times(
|
||||
hierarchy.components.count,
|
||||
(index) => hierarchy.components[index.toString().padStart(4, '0')],
|
||||
@@ -33,32 +31,8 @@ export async function extractArmor(data: string, fileName: string) {
|
||||
|
||||
components.forEach((component) => {
|
||||
switch (component['comp.typename']) {
|
||||
case 'TransformComponent': {
|
||||
const translation = new Vector3();
|
||||
const rotation = new Quaternion();
|
||||
const scale = new Vector3();
|
||||
|
||||
new Matrix4()
|
||||
.multiplyMatrices(
|
||||
new Matrix4().compose(
|
||||
new Vector3().fromArray(component['tc.worldTranslation']),
|
||||
new Quaternion().fromArray(component['tc.worldRotation']),
|
||||
new Vector3().fromArray(component['tc.worldScale']),
|
||||
),
|
||||
new Matrix4().compose(
|
||||
new Vector3().fromArray(component['tc.localTranslation']),
|
||||
new Quaternion().fromArray(component['tc.localRotation']),
|
||||
new Vector3().fromArray(component['tc.localScale']),
|
||||
),
|
||||
)
|
||||
.decompose(translation, rotation, scale);
|
||||
|
||||
node.setTranslation(translation.toArray());
|
||||
node.setRotation(rotation.toArray() as Vector4Tuple);
|
||||
node.setScale(scale.toArray());
|
||||
|
||||
case 'TransformComponent':
|
||||
break;
|
||||
}
|
||||
|
||||
case 'RenderComponent': {
|
||||
const batch = component['rc.renderObj']['ro.batches']['0000'];
|
||||
@@ -116,8 +90,8 @@ export async function extractArmor(data: string, fileName: string) {
|
||||
});
|
||||
|
||||
hardJointIndices.forEach((hardJointIndex) => {
|
||||
const hardJointNode = document.createNode(
|
||||
`armor_${hardJointIndex}`,
|
||||
const node = document.createNode(
|
||||
`${hierarchy.name}_armor_${hardJointIndex}`,
|
||||
);
|
||||
const mesh = document.createMesh(batch['##name']);
|
||||
const indicesAccessor = document
|
||||
@@ -148,8 +122,8 @@ export async function extractArmor(data: string, fileName: string) {
|
||||
});
|
||||
|
||||
mesh.addPrimitive(primitive);
|
||||
hardJointNode.setMesh(mesh);
|
||||
node.addChild(hardJointNode);
|
||||
node.setMesh(mesh);
|
||||
parent.addChild(node);
|
||||
});
|
||||
|
||||
break;
|
||||
@@ -163,10 +137,8 @@ export async function extractArmor(data: string, fileName: string) {
|
||||
});
|
||||
|
||||
if (hierarchy['#hierarchy']) {
|
||||
parseHierarchies(hierarchy['#hierarchy'], node);
|
||||
parseHierarchies(hierarchy['#hierarchy'], parent);
|
||||
}
|
||||
|
||||
parent.addChild(node);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import { exec } from 'child_process';
|
||||
import { mkdir, readFile, rm, writeFile } from 'fs/promises';
|
||||
import { generateUUID } from 'three/src/math/MathUtils';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const execPromise = promisify(exec);
|
||||
|
||||
type Channel = 'red' | 'green' | 'blue' | 'alpha';
|
||||
|
||||
export interface ToJpgOptions {
|
||||
format: string;
|
||||
swap: [Channel, Channel][];
|
||||
invert: boolean;
|
||||
}
|
||||
|
||||
const toJpgDefaultOptions: ToJpgOptions = {
|
||||
format: 'dds',
|
||||
swap: [],
|
||||
invert: false,
|
||||
};
|
||||
|
||||
export async function toJpg(
|
||||
inputBuffer: Buffer,
|
||||
options?: Partial<ToJpgOptions>,
|
||||
) {
|
||||
const mergedOptions = { ...toJpgDefaultOptions, ...options };
|
||||
const id = generateUUID();
|
||||
const input = `temp/toJpg/${id}.${mergedOptions.format}`;
|
||||
const output = `temp/toJpg/${id}.jpg`;
|
||||
const command = `PVRTexToolCLI -noout -i ${input} ${
|
||||
mergedOptions.swap.length === 0
|
||||
? ''
|
||||
: mergedOptions.swap
|
||||
.map(
|
||||
(swapChannels) => `-${swapChannels[1]} ${input},${swapChannels[0]}`,
|
||||
)
|
||||
.join(' ')
|
||||
} ${
|
||||
mergedOptions.invert ? `-diff ${input},DIFFINVERT,255` : ''
|
||||
} -d ${output}`;
|
||||
|
||||
await mkdir('temp/toJpg', { recursive: true });
|
||||
await writeFile(`temp/toJpg/${id}.${mergedOptions.format}`, inputBuffer);
|
||||
await execPromise(command);
|
||||
|
||||
const jpgBuffer = await readFile(`temp/toJpg/${id}.jpg`);
|
||||
|
||||
rm(`temp/toJpg/${id}.${mergedOptions.format}`);
|
||||
rm(`temp/toJpg/${id}.jpg`);
|
||||
|
||||
return jpgBuffer;
|
||||
}
|
||||
Reference in new issue
Block a user