Share this post

Link to post

Share on other sites

Original post by The ImpHello,I'm wondering if it's possible to check how many variables there is in a file since I'm trying to load a .raw model for my opengl project and I need to know how many faces there is.

You can check the length of a file if objects are the same size, or you can include an information block in the file that has a count of the objects / variables.

I don't know about the .raw model format, it might or might not keep a count inside it.

0

Share this post

Link to post

Share on other sites

Files don't contain "variables"; they contain data. Any file can be looked at as just a sequence of bytes; the file size (length) is simply the total number of bytes. However, just reading in a file into a single chunk of memory (like a char[] in C++ or byte[] in Java) is rarely useful.

The file format (this is documentation, not something embedded in the file) explains the *meaning* of the data, and how it is logically organized - including how many "units" of whatever type there are.

It is common, whenever a file is allowed (according to the format) to contain a non-constant (i.e. differing between files of that type) number of some "thing", to include as well a count of the number of "things" that are represented. However, there are a few different ways to represent the count itself, and it isn't always included (sometimes it is considered to be implicit, because you can deduce that x-many bytes of the file represent "things", and every "thing" is represented in the same number y of bytes - it is not always possible or feasible to represent things like that, though).

So you need to know the format of the data in question.

BUT - depending on your implementation language, you should be able to load a set of data of the same type from a file without knowing in advance how many items there are. In C++ this is most effectively done with one of the standard library containers - typically std::vector.

Share this post

Link to post

Share on other sites

There is evidently no header, and the numbers are apparently given in text (human-readable) format.

If those are *spaces* in between the numbers, and there are *always* 9 numbers (one triangle) per line (or if there aren't any returns at all and you're just wrapping it for display), then you may be in luck: count the total file length, calculate the expected line length (I get 90 bytes including one for the return - but to count file length I think you will need to open in binary mode, and then you will need to know how the line endings are encoded, as CRLF or just CR), and then you know how many triangles there are.

Just for the hell of it - in C++, using a std::vector you can avoid worrying about the count like this:

Share this post

Link to post

Share on other sites

I'm pretty sure the file is stored as text, so sizeof(float) isn't going to be of any use.However, you'll notice that every float in the file takes up the same number of characters. If the number is negative it has a minus sign, and it positive, a space is put there instead.I count exactly 10 characters per float, so I would declare a constant to equal ten and use that. I would also assume it's not a unicode file?

One last thing though, a carriage return at the end of each line might muck that up, so you may instead have to work out the number of characters per line and use that instead.Even if what you end up with is only an estimate, then as long as you always only ever overestimate, then everything should be okay.

0

Share this post

Link to post

Share on other sites

You might also consider only reading in unique points, and storing indexes to them in the triangles. I.e. as an indexed buffer format, which may reduce memory usage.Though if you do that you'll want to use a hash table for duplicate detection.