mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +02:00
fix: backwards vertex format
This commit is contained in:
1 parent
7235291e69
commit
1f378137f1
4 files changed
+40
-34
No files matched your search
Binary file not shown.
@@ -36,7 +36,7 @@ export async function buildTankArmors() {
|
||||
|
||||
const armor = await extractArmor(DATA, `${nation}-${tankKey}`);
|
||||
|
||||
// await nodeIO.write('temp/armor/index.gltf', armor);
|
||||
await nodeIO.write('temp/armor/index.gltf', armor);
|
||||
|
||||
// writeFile('test.sc2.json', JSON.stringify(sc2, null, 2));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Document, Node, Scene } from '@gltf-transform/core';
|
||||
import { writeFile } from 'fs/promises';
|
||||
import { range, times } from 'lodash';
|
||||
import {
|
||||
Matrix4,
|
||||
@@ -51,12 +50,8 @@ export async function extractArmor(
|
||||
const scene = document.createScene();
|
||||
const buffer = document.createBuffer();
|
||||
|
||||
writeFile('test.sc2.json', JSON.stringify(sc2, null, 2));
|
||||
|
||||
function parseHierarchies(hierarchies: Hierarchy[], parent: Scene | Node) {
|
||||
hierarchies.forEach((hierarchy) => {
|
||||
console.log(`hierarchy: ${hierarchy.name}`);
|
||||
|
||||
const node = document.createNode(hierarchy.name);
|
||||
const components = times(
|
||||
hierarchy.components.count,
|
||||
|
||||
+39
-28
@@ -1,4 +1,3 @@
|
||||
import { writeFile } from 'fs/promises';
|
||||
import { ScpgStream, VertexAttribute } from './scpg';
|
||||
|
||||
interface PolygonGroupRaw {
|
||||
@@ -67,7 +66,23 @@ export class ScgStream extends ScpgStream {
|
||||
polygonGroupsRaw.push(polygonGroupRaw);
|
||||
}
|
||||
|
||||
writeFile('test.scg.json', JSON.stringify({ polygonGroupsRaw }, null, 2));
|
||||
// writeFile(
|
||||
// 'test.scg.txt',
|
||||
// polygonGroupsRaw
|
||||
// .map((polygonGroupRaw) => {
|
||||
// const floats: number[] = [];
|
||||
// const stream = new BufferStream(polygonGroupRaw.vertices);
|
||||
|
||||
// while (stream.readRemainingLength()) {
|
||||
// floats.push(stream.float());
|
||||
// }
|
||||
|
||||
// return `format: ${polygonGroupRaw.vertexFormat.toString(
|
||||
// 2,
|
||||
// )}\n\n${floats.join('\n')}`;
|
||||
// })
|
||||
// .join('\n\n#####\n\n'),
|
||||
// );
|
||||
|
||||
polygonGroupsRaw.forEach((polygonGroupRaw) => {
|
||||
const indicesStream = new ScpgStream(polygonGroupRaw.indices);
|
||||
@@ -83,29 +98,21 @@ export class ScgStream extends ScpgStream {
|
||||
|
||||
const verticesStream = new ScpgStream(polygonGroupRaw.vertices);
|
||||
const vertices: BlitzkriegVertex[] = [];
|
||||
const stride =
|
||||
ScgStream.vertexStride(polygonGroupRaw.vertexFormat) *
|
||||
polygonGroupRaw.vertexCount;
|
||||
const { format, stride } = ScgStream.parseVertexFormat(
|
||||
polygonGroupRaw.vertexFormat,
|
||||
);
|
||||
const strideBasedSize = stride * polygonGroupRaw.vertexCount;
|
||||
|
||||
if (verticesStream.stream.length !== stride) {
|
||||
if (verticesStream.stream.length !== strideBasedSize) {
|
||||
console.warn(
|
||||
`Vertex stride mismatch; expected ${stride}, got ${verticesStream.stream.length}; skipping...`,
|
||||
`Vertex stride mismatch; expected ${strideBasedSize}, got ${verticesStream.stream.length}; skipping...`,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const vertexFormat = (
|
||||
polygonGroupRaw.vertexFormat
|
||||
.toString(2)
|
||||
.split('')
|
||||
.map((bitString, index) =>
|
||||
bitString === '1' ? index : null,
|
||||
) as VertexAttribute[]
|
||||
).filter((type) => type !== null);
|
||||
|
||||
for (let index = 0; index < polygonGroupRaw.vertexCount; index++) {
|
||||
vertices[index] = vertexFormat.map((attribute) => {
|
||||
vertices[index] = format.map((attribute) => {
|
||||
return {
|
||||
attribute,
|
||||
value: verticesStream.vectorN(
|
||||
@@ -128,18 +135,22 @@ export class ScgStream extends ScpgStream {
|
||||
return polygonGroups;
|
||||
}
|
||||
|
||||
static vertexStride(vertexFormat: number) {
|
||||
const flags = vertexFormat.toString(2);
|
||||
static parseVertexFormat(formatInt: number) {
|
||||
const format: VertexAttribute[] = [];
|
||||
let stride = 0;
|
||||
|
||||
return Object.values(VertexAttribute)
|
||||
Object.values(VertexAttribute)
|
||||
.filter((value) => typeof value === 'number')
|
||||
.reduce(
|
||||
(accumulator, attribute) =>
|
||||
flags[attribute as VertexAttribute] === '1'
|
||||
? accumulator +
|
||||
vertexAttributeVectorSizes[attribute as VertexAttribute] * 4
|
||||
: accumulator,
|
||||
0,
|
||||
);
|
||||
.forEach((attributeUntyped) => {
|
||||
const attribute = attributeUntyped as VertexAttribute;
|
||||
const mask = 1 << attribute;
|
||||
|
||||
if (formatInt & mask) {
|
||||
format.push(attribute);
|
||||
stride += vertexAttributeVectorSizes[attribute] * 4;
|
||||
}
|
||||
});
|
||||
|
||||
return { format, stride };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user