feat: float

This commit is contained in:
TrèsAbhi committed 2023-12-07 23:36:46 -06:00
1 parent 81826d0549
commit 610c75d274
1 file changed
+8 -6
+8 -6
View File
@@ -73,7 +73,7 @@ const VECTOR_SIZES = [
// vector 3; 3d vector // vector 3; 3d vector
VertexType.VERTEX, VertexType.VERTEX,
VertexType.NORMAL, VertexType.NORMAL,
VertexType.TANGENT, // VertexType.TANGENT, MOVED TO 4
VertexType.BINORMAL, VertexType.BINORMAL,
VertexType.CUBETEXCOORD0, VertexType.CUBETEXCOORD0,
VertexType.CUBETEXCOORD1, VertexType.CUBETEXCOORD1,
@@ -82,6 +82,7 @@ const VECTOR_SIZES = [
], ],
[ [
// vector 4; 4d vector or something more complex // vector 4; 4d vector or something more complex
VertexType.TANGENT, // UNCONFIRMED
VertexType.PIVOT4, VertexType.PIVOT4,
VertexType.JOINTINDEX, VertexType.JOINTINDEX,
VertexType.JOINTWEIGHT, VertexType.JOINTWEIGHT,
@@ -160,6 +161,10 @@ class SCPGStream {
const buffer = this.consume(4); const buffer = this.consume(4);
return { buffer, value: buffer.readUInt32LE() }; return { buffer, value: buffer.readUInt32LE() };
} }
consumeFloat() {
const buffer = this.consume(4);
return { buffer, value: buffer.readFloatLE() };
}
consumeSCGHeader() { consumeSCGHeader() {
return { return {
@@ -203,16 +208,13 @@ class SCPGStream {
const vertices: { type: VertexType; value: number[] }[] = []; const vertices: { type: VertexType; value: number[] }[] = [];
for (let index = 0; index < polygonGroupRaw.vertexCount.value; index++) { for (let index = 0; index < polygonGroupRaw.vertexCount.value; index++) {
// skipping 4 everytime stops leaving some garbage
verticesStream.skip(4);
vertexFormat.forEach((type) => { vertexFormat.forEach((type) => {
const resolved = VECTOR_SIZES.some((types, size) => { const resolved = VECTOR_SIZES.some((types, size) => {
if (types.includes(type)) { if (types.includes(type)) {
vertices.push({ vertices.push({
type, type,
value: range(size + 1).map( value: range(size + 1).map(
() => verticesStream.consumeUInt32().value, () => verticesStream.consumeFloat().value,
), ),
}); });
@@ -239,7 +241,7 @@ class SCPGStream {
.map( .map(
(e) => (e) =>
`${VertexType[e.type].padEnd(16, ' ')} ${e.value `${VertexType[e.type].padEnd(16, ' ')} ${e.value
.map((j) => j.toString(16).padStart(8, '0')) .map((j) => j.toString(10).padStart(32, ' '))
.join(' ')}`, .join(' ')}`,
) )
.join('\n'), .join('\n'),