Pack normals into one byte instead of 4 to save space :)

This commit is contained in:
Lukas Rieger (Blue) 2024-02-23 18:02:29 +01:00
parent 6e68a8f0e0
commit 40119127ee
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6
1 changed files with 10 additions and 5 deletions

View File

@ -87,9 +87,9 @@ public class PRBMWriter implements Closeable {
writeString("normal");
out.write(
ATTRIBUTE_TYPE_FLOAT |
ATTRIBUTE_NOT_NORMALIZED |
ATTRIBUTE_NORMALIZED |
ATTRIBUTE_CARDINALITY_3D_VEC |
ATTRIBUTE_ENCODING_SIGNED_32BIT_FLOAT
ATTRIBUTE_ENCODING_SIGNED_8BIT_INT
);
writePadding();
@ -105,9 +105,9 @@ public class PRBMWriter implements Closeable {
);
for (j = 0; j < 3; j++) { // all 3 points
writeFloat(normal.x);
writeFloat(normal.y);
writeFloat(normal.z);
writeNormalizedSignedByteValue(normal.x);
writeNormalizedSignedByteValue(normal.y);
writeNormalizedSignedByteValue(normal.z);
}
}
}
@ -283,6 +283,11 @@ public class PRBMWriter implements Closeable {
write4byteValue(Float.floatToIntBits(value));
}
private void writeNormalizedSignedByteValue(float value) throws IOException {
byte normalized = (byte) (value * 0x80 - 0.5);
out.write(normalized & 0xFF);
}
private void writeNormalizedUnsignedByteValue(float value) throws IOException {
int normalized = (int) (value * 0xFF);
out.write(normalized & 0xFF);