fix: streak lod

This commit is contained in:
TrèsAbhi committed 2024-01-03 19:18:31 -06:00
1 parent c10060decc
commit 35d03c9e21
3 files changed
+24 -7

No files matched your search

Binary file not shown.
+2 -2
View File
@@ -593,9 +593,9 @@ if (allTargets || targets?.includes('tankModels')) {
// if (id !== 15697) continue; // chieftain TODO: investigate vertices stream over read
// if (id !== 24609) continue; // concept 1b
if (id !== 16401) continue; // waffle
// if (id !== 16401) continue; // waffle
// if (id !== 7425) continue; // isu 152
// if (id !== 10369) continue; // mino
if (id !== 10369) continue; // mino
// if (id !== 4417) continue; // amx m4 mle
// if (id !== 7297) continue; // 60tp
// if (id !== 1) continue; // t-34
+22 -5
View File
@@ -1,4 +1,5 @@
import { Document, Material, Node, Scene } from '@gltf-transform/core';
import { writeFile } from 'fs/promises';
import { range, times } from 'lodash';
import { dirname } from 'path';
import {
@@ -14,9 +15,9 @@ import { ScgStream, vertexAttributeVectorSizes } from '../streams/scg';
import { VertexAttribute } from '../streams/scpg';
import { readDVPLFile } from './readDVPLFile';
// BigInt.prototype.toJSON = function () {
// return this.toString();
// };
BigInt.prototype.toJSON = function () {
return this.toString();
};
const MAX_FLOAT32 = 2 ** 127 * (2 - 2 ** -23);
@@ -58,6 +59,8 @@ export async function extractModel(
const buffer = document.createBuffer();
const materials = new Map<bigint, Material | bigint>();
writeFile('test.sc2.json', JSON.stringify(sc2, null, 2));
// create materials
await Promise.all(
sc2['#dataNodes'].map(async (node) => {
@@ -208,7 +211,7 @@ export async function extractModel(
}
case 'RenderComponent': {
let minLODDistanceBatchId: undefined | number = undefined;
let minLODDistanceBatchId: undefined | number;
if (component['rc.renderObj']['rb0.lodIndex'] === -1) {
minLODDistanceBatchId = 0;
@@ -226,6 +229,8 @@ export async function extractModel(
let minLODDistance = Infinity;
let isFirstMaxFloat = true;
let lodIndexStreak = 0;
let lodIndexStreakIndex: undefined | number = undefined;
range(component['rc.renderObj']['ro.batchCount']).forEach(
(id) => {
@@ -234,8 +239,16 @@ export async function extractModel(
const lodDistance =
lodList['lc.loddist'][`distance${lodIndex}`];
if (lodIndexStreakIndex === lodIndex) {
lodIndexStreak++;
} else {
lodIndexStreak = 0;
lodIndexStreakIndex = lodIndex;
}
if (
lodDistance <= minLODDistance ||
lodDistance < minLODDistance ||
(lodDistance === minLODDistance && lodIndexStreak > 0) ||
(lodDistance === MAX_FLOAT32 && isFirstMaxFloat)
) {
if (lodDistance === MAX_FLOAT32) isFirstMaxFloat = false;
@@ -246,6 +259,10 @@ export async function extractModel(
);
}
if (hierarchy.name === 'chassis_track_L') {
console.log(minLODDistanceBatchId);
}
const batch =
component['rc.renderObj']['ro.batches'][
minLODDistanceBatchId!.toString().padStart(4, '0')