Skip to content

Instantly share code, notes, and snippets.

@johantiden
Last active April 15, 2021 09:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johantiden/a9ec7bc4dfeb9ebc23260d6c0a159317 to your computer and use it in GitHub Desktop.
Save johantiden/a9ec7bc4dfeb9ebc23260d6c0a159317 to your computer and use it in GitHub Desktop.
Showcase of reading a Photoshop liquify .msh file
public static void main(String[] args) throws IOException {
byte[] bytes = Files.readAllBytes(new File("distortedmesh.msh").toPath());
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
byteBuffer.position(64);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
int HEIGHT = 8;
int WIDTH = 8;
for (int row = 0; row < HEIGHT; row++) {
System.out.println("row " + row);
boolean nextIsEmpties = true;
int sumRead = 0;
while (sumRead < WIDTH) {
if (nextIsEmpties) {
int numEmpties = byteBuffer.getInt();
System.out.println(numEmpties + " empties");
sumRead += numEmpties;
} else {
int nums = byteBuffer.getInt();
System.out.println(nums + " non empty");
for (int i = 0; i < nums; i++) {
int x = sumRead + i;
float dx = byteBuffer.getFloat();
float dy = byteBuffer.getFloat();
System.out.println("* x:" + x + " dx:" + dx +", dy:"+ dy);
}
sumRead += nums;
}
nextIsEmpties = !nextIsEmpties;
}
System.out.println("end of row");
System.out.println("");
System.out.println("");
}
}
@johantiden
Copy link
Author

Sample output:

row 0
8 empties
end of row


row 1
2 empties
3 non empty
*  x:2 dx:0.004172363, dy:-0.0055631506
*  x:3 dx:0.06935779, dy:-0.10359027
*  x:4 dx:0.032121338, dy:-0.047441643
3 empties
end of row


row 2
0 empties
6 non empty
*  x:0 dx:-0.39320424, dy:0.007829409
*  x:1 dx:-0.6301713, dy:0.035328105
*  x:2 dx:-0.18079452, dy:-0.15965866
*  x:3 dx:0.15873107, dy:-0.24775742
*  x:4 dx:0.13291335, dy:-0.20692879
*  x:5 dx:0.020055639, dy:-0.031713974
2 empties
end of row


row 3
0 empties
8 non empty
*  x:0 dx:-0.74627185, dy:0.033267353
*  x:1 dx:-0.8675832, dy:0.048824273
*  x:2 dx:-0.4686415, dy:-0.17670925
*  x:3 dx:0.09273655, dy:-0.25928968
*  x:4 dx:0.16222468, dy:-0.23500547
*  x:5 dx:0.097237326, dy:-0.044668403
*  x:6 dx:0.25927028, dy:0.026348565
*  x:7 dx:0.14216769, dy:0.024174895
end of row


row 4
0 empties
8 non empty
*  x:0 dx:-0.63617367, dy:0.026834618
*  x:1 dx:-0.8039161, dy:0.05380975
*  x:2 dx:-0.59308237, dy:-0.03335828
*  x:3 dx:0.07688038, dy:-0.18638472
*  x:4 dx:0.23024529, dy:-0.14183214
*  x:5 dx:0.5724449, dy:0.025610998
*  x:6 dx:0.8161359, dy:0.058070872
*  x:7 dx:0.842724, dy:0.09314164
end of row


row 5
0 empties
8 non empty
*  x:0 dx:-0.100841425, dy:0.023473598
*  x:1 dx:-0.45618898, dy:0.15141228
*  x:2 dx:-0.31868953, dy:0.17020775
*  x:3 dx:-0.0069539384, dy:0.0027815753
*  x:4 dx:0.17704602, dy:-0.009575358
*  x:5 dx:0.68439287, dy:0.034437668
*  x:6 dx:0.9099028, dy:0.063314326
*  x:7 dx:0.91899097, dy:0.089261
end of row


row 6
0 empties
8 non empty
*  x:0 dx:-0.28261968, dy:0.17449692
*  x:1 dx:-0.41927585, dy:0.25475022
*  x:2 dx:-0.42613676, dy:0.25969
*  x:3 dx:-0.15874313, dy:0.09177879
*  x:4 dx:5.9240044E-4, dy:-0.014278429
*  x:5 dx:0.35195252, dy:0.0026739172
*  x:6 dx:0.61429036, dy:0.038913693
*  x:7 dx:0.5622655, dy:0.07386957
end of row


row 7
0 empties
4 non empty
*  x:0 dx:-0.23705038, dy:0.14796394
*  x:1 dx:-0.40063614, dy:0.24370362
*  x:2 dx:-0.4074999, dy:0.24851985
*  x:3 dx:-0.10276147, dy:0.058118954
4 empties
end of row

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment