How to read the 3D chart data with directX?

Posted by MemoryLeak on Stack Overflow See other posts from Stack Overflow or by MemoryLeak
Published on 2010-04-05T00:25:26Z Indexed on 2010/04/05 0:33 UTC
Read the original article Hit count: 465

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about xda

Related posts about directx