I am going to answer my own question as I found I had to do what I proposed
and I am sure others will too.  Here are the two functions/methods I made:

// read 4 bytes and returns it as an int given order of bytes least to most
significant
private int readInt(DataInputStream dis) throws java.io.IOException {
        byte a,b,c,d;
        a=dis.readByte();b=dis.readByte();c=dis.readByte();d=dis.readByte();
        return( ((d & 0xff) << 24) | ((c & 0xff) << 16) | ((b & 0xff) << 8)
| (a & 0xff) );
}

// read 4 bytes and returns it as an float given order of bytes least to
most significant
private float readFloat(DataInputStream dis) throws java.io.IOException {
        byte a,b,c,d;
        a=dis.readByte();b=dis.readByte();c=dis.readByte();d=dis.readByte();
        int i= ( ((d & 0xff) << 24) | ((c & 0xff) << 16) | ((b & 0xff) << 8)
| (a & 0xff) );
        return(Float.intBitsToFloat(i));
}

NOTE: if you convert the ordering by:
int i =( (d  << 24) | (c << 16) | (b << 8) | a  );
you get some odd results!  Don't ask my why, I'm too busy to puzzle that
sort of stuff out!

I would still appreciate hereing from anyone who has made an STL loader
already, or knows where one is.
John

P.S. Thanks to all who may have written back already with answers!


-----Original Message-----
From: Dickinson, John [mailto:[EMAIL PROTECTED]]
Sent: January 5, 2000 2:53 PM
To: [EMAIL PROTECTED]
Subject: [JAVA3D] reading binary data files


I know I could post this to a general java list but the problem came up
while looking at building a loader for STL files (used for faceted
descriptions of 3D objects to be built using rapid prototyping processes).

Questions:
1) though I have started building a loader for STL files if there is one
already out there then please let me know!!
I have searched through multiple archives of loaders with no luck.
2) I can load ascii STL file but binary ones (more common) are a bit of a
problem due to byte ordering!
e.g. my file has encoded in it the number 12 (in four bytes written by a
C++/C program on a PC writting out an int)
the binary coding looks like: 0C 00 00 00
When using a DataStreamInput method readInt() gives me 201326592!
What java expects is that the number 12 would be encoded as 00 00 00 0C
instead!

Though I can read these byte by byte and reconstruct integers manually I
hate to think what I would have to do in order to read floats written by the
same C program!

Any suggestions, alternative apporaches?
John

--
-((Insert standard disclaimer here))-|- Washington Irving (1783-1859) -
John Kenneth Dickinson               |   "A sharp tongue is the only
Research Council Officer  IMTI-NRC   |    edge tool that grows keener
email: [EMAIL PROTECTED]         |    with constant use."

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to