I have a lot of trouble reading binary files I created in a Javascript-app.
The scenario is this: I use a ThreeJS app to create a polysphere model with over 100K points. The model can with no problems at all be exported to a GLB and imported in my JME3 app.
I also create some typed arrays with meta-data about every point and it’s relations to neighbouring points. This is needed for navigation on the sphere. I dumped this data into a binary file and put it in the asset ‘Models’ folder.
The JS Code:
downloadBlob = function(data, fileName, mimeType) {
var blob, url;
blob = new Blob([data], {
type: mimeType
});
url = window.URL.createObjectURL(blob);
downloadURL(url, fileName);
setTimeout(function() {
return window.URL.revokeObjectURL(url);
}, 1000);
};
But I can not figure out how to load it from my assets and use it in my JME3 app.
This is my loading code:
int[] readIntData(String _file) {
//Read objects or arrays from binary file "o.dat":
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream( _file));
try {
utils.LOG("Read "+ois.toString()) ;
return (int[]) (ois.readObject());
} catch (ClassNotFoundException e) {
utils.LOG("Class not found:"+e.getMessage());
return null;
}
} catch (IOException e) {
utils.LOG("IO Error:"+e.getMessage());
return null;
}
}
I need to feed it an absolute address, otherwise it dies on File not found. But when the file is found, it still dies on ‘invalid stream header: 01000000’.
I figured there is a mismatch with the way I dump binary stuff in JS and the way Java wants it. So I am sort of back at square one… so how could I get this scenario to work?
And how do I get the data to load like an asset, from the asset folders?