I hope you can help me with this:
I’m trying to write a Milkshape3D model loader for Java.
I have found the Milkshape3D File Format Specification here
and following it I created my code as belows, Im missing some classes still, but this problem came by now; with a DataInputStream object I should be able to read the file by whatever data type I want, like with readChar() I should be able to read all of the chars in the file header, wich should be “MS3D000000”, but when I use readChar() to get only the “M”, it returns a weird symbol, and even if I skip the first 10 bytes to read the version number, it returns a number very different than 3!!
I dont know what to do, can you explain me what am I doing wrong?
The model can be found here
package milkshape3d_loader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
class ms3d_header_t {
char[] id; // always "MS3D000000"
int version; // 3
ms3d_header_t() {
id = new char[] {'M','S','3','D','0','0','0','0','0','0'};
version = 3;
}
}
public class Milkshape3D_Loader {
public static void main(String[] args) {
try {
File inFile = new File ("dy_joey.ms3d");
FileInputStream inStream = new FileInputStream (inFile);
DataInputStream input = new DataInputStream (inStream);
char id = input.readChar();
System.out.println (id);
}
catch (Exception e) {
System.out.println (e.getMessage());
e.printStackTrace();
}
}
}
readCharreads two bytes and interprets them as a singlechar– a 16 bit UTF-16 code unit. The “weird symbol” is presumably U+4D53, the Unicode character represented by the bytes corresponding to ASCII M and S. You probably need to read each byte individually using