views:

33

answers:

1

I am reading a open source project, and I found there is a function which read 3D data(let's say a character) from obj file, and draw it . the source code:

    List<Vertex3f> verts=new List<Vertex3f>();
        List<Vertex3f> norms=new List<Vertex3f>();
        Groups=new List<ToothGroup>();
        //ArrayList ALf=new ArrayList();//faces always part of a group
        List<Face> faces=new List<Face>();
        MemoryStream stream=new MemoryStream(buffer);
        using(StreamReader sr = new StreamReader(stream)){
            String line;
            Vertex3f vertex;
            string[] items;
            string[] subitems;
            Face face;
            ToothGroup group=null;
            while((line = sr.ReadLine()) != null) {
                if(line.StartsWith("#")//comment
                    || line.StartsWith("mtllib")//material library.  We build our own.
                    || line.StartsWith("usemtl")//use material
                    || line.StartsWith("o")) {//object. There's only one object 
                    continue;
                }
                if(line.StartsWith("v ")) {//vertex
                    items=line.Split(new char[] { ' ' });
                    vertex=new Vertex3f();//float[3];
                    if(flipHorizontally) {
                        vertex.X=-Convert.ToSingle(items[1],CultureInfo.InvariantCulture);
                    }
                    else {
                        vertex.X=Convert.ToSingle(items[1],CultureInfo.InvariantCulture);
                    }
                    vertex.Y=Convert.ToSingle(items[2],CultureInfo.InvariantCulture);
                    vertex.Z=Convert.ToSingle(items[3],CultureInfo.InvariantCulture);
                    verts.Add(vertex);
                    continue;
                }

And why it need to read the data manually in directX? As far as I know, in XDA programming, we just need to call a function a load the resource.

Is this because it is in DirectX, there is no function to read resource? If yes, then how to prepare the 3D resource ? in XDA we just need to use other software draw the 3D picture and then export. but what should I do in DirectX?

+1  A: 

The code above is for loading a SPECIFIC file format. Its not one that is supported. XNA allows loading of .X and FBX files. DirectX supports loading .X files but .FBX files have to be built using the FBX SDK.

To render a .FBX using the DXSDK load up the SDK and transfer all the information to a relevant set of hardware data structure :)

Goz
Thanks, Dif we want to write a 3D application, why we need to load the specific data instead of follow the standard, is there any benefits ?
MemoryLeak
I'm not entirely sure what you mean? Are you suggesting it would be easier to convert some data to the X-File format than to just load it into the relevant vertex buffers and index buffers? Sure post-translation loading would be faster but it all depends on what you want to do with the data ...
Goz