properly parse models with 32bit indices

This commit is contained in:
Skillbert
2024-06-12 13:49:58 +02:00
parent c84114dc0c
commit 18bdbb314b
3 changed files with 22 additions and 7 deletions

View File

@@ -69,7 +69,7 @@ export type models = {
unkint: number,
materialArgument: number,
unkbyte2: number,
buf: Uint16Array,
buf: (Uint16Array|Uint32Array),
}[],
} | null,
unk1Buffer: Uint8Array[],

View File

@@ -277,14 +277,25 @@ export function parseOb3Model(modelfile: Buffer, source: CacheFileSource) {
for (let render of mesh.renders) {
if (render.isHidden) { continue; }
if (render.buf.length == 0) { continue; }
let minindex = render.buf[0];
let maxindex = render.buf[0];
for (let i = 0; i < render.buf.length; i++) {
let v = render.buf[i];
let buf = render.buf;
if (buf.BYTES_PER_ELEMENT == 4) {
//flip endianness, only u32 variant of the index buffer is BE...
//need to copy because the original file is still cached
let newbuf = new Uint32Array(buf.length);
for (let i = 0; i < buf.length; i++) {
let v = buf[i];
newbuf[i] = ((v >> 24) & 0xff) | ((v >> 8) & 0xff00) | ((v << 8) & 0xff0000) | ((v << 24) & 0xff000000);
}
buf = newbuf;
}
let minindex = buf[0];
let maxindex = buf[0];
for (let i = 0; i < buf.length; i++) {
let v = buf[i];
if (v < minindex) { minindex = v; }
if (v > maxindex) { maxindex = v; }
}
let index = new THREE.BufferAttribute(render.buf, 1);
let index = new THREE.BufferAttribute(buf, 1);
meshes.push({
indices: index,
vertexstart: minindex,

View File

@@ -92,7 +92,11 @@
["unkint","uint"],
["materialArgument","ushort le"],
["unkbyte2","ubyte"],
["buf",["buffer","ushort le","ushort"]]
//this might be groupflags&0x80 for uint indexbuffer
["buf",["match",{
"vertexCount<=0xffff":["buffer","ushort le","ushort"],//u16 little endian
"other":["buffer","ushort le","uint"]//u32 big endian?????
}]]
]]]
]]],