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

View File

@ -87,9 +87,9 @@ private void writeNormalArray(TileModel model) throws IOException {
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 @@ private void writeNormalArray(TileModel model) throws IOException {
);
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 @@ private void writeFloat(float value) throws IOException {
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);