Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

reading model files with c#...

This topic is 5190 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I want to read this file:
MDXVersion 1
nummeshes 1
mesh 0 {
	name "mesh0"
	position 0.000000 0.000000 0.000000
	shader "fatty"
 	numfaces 1274
	0 1 2
	1 3 2
	4 5 6
	7 5 4
	2 8 7
	7 8 5
	2 3 8
..........
 
In c/c++ I would do, for example to read the first line: fscanf(file, "MDXVersion %d\n", &m_iVersion); but in c# I can''t find a way to store the values like this... how can I do it? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Looks basically like the doom 3 format.. I just used a few regular expressions, it didn''t take very long to through together. Regex are currently pretty slow, instead you may want to manually parse the files. Unfortunately .NET doesn''t have a simple fscanf-like method in the BCL.

Share this post


Link to post
Share on other sites
How can I do it manually?... (small example, please.)

[edited by - xyz on March 5, 2004 1:32:35 PM]

Share this post


Link to post
Share on other sites
Use a StreamReader to read the data in one line at a time and write your own function to split the line into separate tokens. Or if you''re feeling lazy, use a compiled regular expression, hopefully you won''t be calling it all that often anyway.

Share this post


Link to post
Share on other sites
My problem is storing the vertices and faces... in c++ I would create something like this (for example for face indexes):

typedef struct face_s
{
int vertIndex[3];
};

and then just:

myFace = new face_s[numFaces];


But I''m not being able to do it!!!

Share this post


Link to post
Share on other sites
quote:
How can I do it manually?... (small example, please.)


Ugly, assumption-laden code follows:

System.IO.StreamReader input = System.IO.File.OpenText( "model.mdl" )
string line = null;
while ( (line = input.ReadLine()) != null )
{
string [] parts = line.Trim().Split( ' ' );
if ( parts[0].Equals( "MDXVersion" ) )
version = int.Parse( parts[1] );
...
}


edit: replace angle brackets on source with square brackets...



[edited by - mauman on March 5, 2004 2:33:59 PM]

Share this post


Link to post
Share on other sites
quote:

My problem is storing the vertices and faces... in c++ I would create something like this (for example for face indexes):

typedef struct face_s
{
int vertIndex[3];
};

and then just:

myFace = new face_s[numFaces];



Something like:


class Face
{
public int [] vertIndex = new int[3] { -1, -1, -1 };
}

...

Face [] faces = new Face[numFaces];


Share this post


Link to post
Share on other sites
thanks! thats it!

just one more thing: does anyone know why I get an ''Object reference not set to an instance of an object'' in the 7th line?


numFaces = Int32.Parse(line.Substring(line.LastIndexOf(" ")));
faces = new Face[numFaces];
for(int i=0; i {
line = sr.ReadLine();
string[] curr = line.Split('' '');
faces.vertIndex[0] = Int32.Parse(curr[0]);
faces[i].vertIndex[1] = Int32.Parse(curr[1]);
faces[i].vertIndex[2] = Int32.Parse(curr[2]);
}


thanks

Share this post


Link to post
Share on other sites
If you''re ever looking for .NET equivalents of C runtime function, this is a nice reference:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/vclrfRun-TimeRoutinesNETFrameworkEquivalents.asp

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!