mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 03:29:51 +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
@@ -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