Hi,I'm trying to make a little 3DS file loader. For best performances, i want to use NIO.The problem is i can't load a simple file (text or hexa as 3DS files) and show it. I've tried many solutions and i always get...nothing, or only numbers (what are these numbers, i don't know...).So it will be very helpful for me if you would give me a little code which loads and shown a file with NIO, because i've searched on Google and...i found nothing

And are the chunks (0x4D4D, 0x4000...) in 3DS files one per line or ones following the others on the same line, and maybe without space ?

All files on your hard disk are stored as numbers, because computers dont understand letters. You have to manually convert from those numbers into some language - which you have to choose. If you're loading files written by Americans, it's likely you need charset "ISO-8859-1". Have a look at the Charset class and the CharBuffer classes (these are how you convert raw NIO bytes into characters)

For the 2nd part, sounds like you might need to go and read about the actual file-format - there are plenty of googleable sites that give full info on .3DS.

I always read the documentation first but i don't understand english very well, and they didn't explain the APIs uses and give no examples..I must know the basics of NIO,whithout that it's a bit difficult to understand the javadoc.And my search results didn't help anymore. I've found nothing on a simple file reading and showing it. Reading with a channel, that's ok, but i can get the length of the buffer or text (remaigning() always gives me 0) for the while() to traverse the file. And i can't get the caracteres and the 3DS hexa bytes.

All the tutorials i've found always give me another way , but no one gives me a solutions to read and show a file as with standard IO.

3DS files are binary files. You do not want to read it as text. Hex data is a way of describing binary data as text. 0x4D4D says that there is 2 bytes with the values 77, 77 (unless it's 4 or more bytes where the high bytes are 0). To learn more about binary data and hex values, buy a Java teaching book. Read it a couple of times before starting on your loader.

I've two Java books and only one deals with binary datas, it shows how to read a binary file with IO in one very short examples which is almost the same as the text file reading example.My last luck are internet examples and this forum.So, a little help would be very helpful for me.

If i load a binary file, convert it to int (is it possible ?) and then convert it to a string representation with the 16 base, i suppose that can work.But the question is how to convert binary file to int ?

Ok, atleast you've got a book. Shows you have put some effort into it. I'll try to help.

Hex numbers are numbers written in base 16 number system. We usually use the decimal system wich uses the base 10 number system. Hex has 16 symbols representing the 16 values. The 10 first is the same as the decimal system with 0-9. The last uses the characters A-F to sombolise the values 10-15. "C" written has hex means 12 written as decimal. When you've got more than one symbol you've got to multiply with 16 instead of 10. So "C4" means (12*16)+4=196. A hex symbol represents a 4 bit number. That is why they are usally written in pairs to represent bytes. "0xC4" represents a single byte, "0xC400" represents 2 bytes etc. Look through your books again to read about hex, oct and binary representation of data. It might be in a appendix named "number formats".

So when the 3ds docs says "0x4000" it means you need to read 2 bytes, one with the value "0x40" and one "0x00. You can use the windows scientific calculator to switch between hex and decimal number.

In your code you could use the l_bytes array directly, or wrap it in a DataInputStream. In any case you need to know what endian is used by the file format. Be also aware that java bates are signed wich you don't wan't. So to check for "0x4000" you could write:

If i load a binary file, convert it to int (is it possible ?) and then convert it to a string representation with the 16 base, i suppose that can work.But the question is how to convert binary file to int ?

Forget about strings. You will not use it when doing a 3ds loader (with the exception of reading text lumps like material names).ut it.

Why the while (hex.lenght() < 2)) ? It makes the while infinite and always return 00.If i remove this "while" it seems to work, i get on each line 2 caracteres (hex). But the while is very long, i had to kill it...

Quote

Hex numbers are numbers written in base 16 number system. We usually use the decimal system wich uses the base 10 number system. Hex has 16 symbols representing the 16 values. The 10 first is the same as the decimal system with 0-9. The last uses the characters A-F to sombolise the values 10-15. "C" written has hex means 12 written as decimal. When you've got more than one symbol you've got to multiply with 16 instead of 10. So "C4" means (12*16)+4=196. A hex symbol represents a 4 bit number. That is why they are usally written in pairs to represent bytes. "0xC4" represents a single byte, "0xC400" represents 2 bytes etc. Look through your books again to read about hex, oct and binary representation of data. It might be in a appendix named "number formats".

So when the 3ds docs says "0x4000" it means you need to read 2 bytes, one with the value "0x40" and one "0x00.

Thanks for your little lesson, now it's clearly in my head. But my two books doesn't have any explication on number formats, binary, hexadecimal, decimal...and yet they were quite expensive...

If you're at the stage where binary files are an unknown concept you might want to start somewhere a little easier going. Writing a 3DS loader isn't the easiest place to start.

Kev

Thanks, but i already know this loader. And someone on this forum are the new maintainer of the loader. But wehre are the sources ? I can't found them. Not the sources of the applet, but the sources of the 3ds loader.

Quote

In your code you could use the l_bytes array directly, or wrap it in a DataInputStream. In any case you need to know what endian is used by the file format. Be also aware that java bates are signed wich you don't wan't. So to check for "0x4000" you could write:Code:if ( (l_bytes[0] & 0xff) == 0x00 && (l_bytes[1] & 0xff) == 0x40) { // marker at index 0 eqals 0x4000}

What's the gain if i wrap it in a DataInputStream ? And 3ds files use little-endian. Must i do something particular ?

And great thank tom ! Thanks to your help, i've succeeded to find the Main Chunk of my 3ds files .

Why the while (hex.lenght() < 2)) ? It makes the while infinite and always return 00.If i remove this "while" it seems to work, i get on each line 2 caracteres (hex). But the while is very long, i had to kill it...

You must have typed it in wrong. The while makes sure that the string always ends up with 2 characters. That is important so you don't drop zeros.

What's the gain if i wrap it in a DataInputStream ? And 3ds files use little-endian. Must i do something particular ?

DataInputStream makes it easy to read in primitives like unsigned shorts, float etc. But I don't think you can use it beacause java is big endian? ByteBuffer has got something similar, and you can set the endian on the buffer. So instead of:

Now i can't get the length of the chunks, the strings data, and the vertex list...I've passed many hours today in it, but i found nothing that could help me on internet, and there is nothing in my books. But all are java and bytes problems.

First for the length, it's on 4 byte just after the chunk's id. But to get 4 bytes, it's getFloat(). But i've tried buffer.getFloat & 0xffffffff (8 f because of 4 bytes).but that's wrong...so how can i get the 4 bytes after the id chunk and convert it to int ?

Then the string data, per exemple, for the object name.I've found this code on internet :

And it returns me 16656.Is it possible 16656 vertices for a 24824 bytes file ? And there is many 0x4110 in the file...

My basic function is on the previous post.

PS : where are the source of the vrmi-3ds loader on this site http://games.swizel-studios.com/tutorials.html ? I didn't found it in the library section and ine the jar and in the tutorial section there is only the applet source code.

You don't need the source, you have the jar file and the javadoc available. This will get you a loaded .3ds file into memory, then all you have to do is write a simple renderer. Beta v0.3 on my site is an example of a very simple renderer.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org