Results 1 to 10 of 10

Thread: Tiny 3DS loader

  1. #1

    Tiny 3DS loader

    hi
    a tiny 3ds warpper draw 1 object wih 1 texture
    in fact this is my translation of a c++ code has been found in www.codesampler.com

    Code:
    Unit Mini3ds;
    
    interface
    
    uses windows,opengl;
    
    
    const
       MAX_GEO = 10000;
    type
    
    // Vertex
       Vertex  = record
            x,
            y,
            z : single;
            end;
    
    // texture
       mapcoord = record
            u,
            v : single;
            end;
    
    // index
       polygon = record
            a,
            b,
            c : integer;
            end;
    
    // 3d object structure
       _object = record
            name : array[0..21] of char;
            numVerts : integer;
            numPolys : integer;
            v : array [0..MAX_GEO] of vertex;
            p : array [0..MAX_GEO] of polygon;
            m : array [0..MAX_GEO] of mapcoord;
            end;
    
    // 3ds object
      T3DS = object
       public
        procedure Load(_fn : string);
        procedure Draw();
        procedure free();
       public
        obj : _object;
       end;
    
    
    implementation
    
    { T3DS }
    
    procedure T3DS.Load(_fn: string);
    var
    _file : file of byte;
     i  : integer;
     chunkID : short;
     chunkLength  : integer;
     tmp       : char;
     useless  : short;
     from      : integer;
    _fsize     : integer;
     label begincase;
    begin
    
        AssignFile(_file,_fn);
        Reset(_file);
      _fsize := filesize(_file);
    
      while ( filepos(_file) < _fsize) do
      begin
         begincase:
         BlockRead(_file,chunkID,2);
         BlockRead(_file,chunkLength,4);
    
        case chunkID of
    
         $4d4d : begin end;
         $3d3d : begin end;
         $4000 :
      	for i:=0 to 20-1 do
    	 begin
    	       Blockread (_file,tmp, 1);
                           obj.name[i]:=tmp;
                    if pointer(tmp) = NIL then
                  goto begincase;
          end;
    
         $3f80 :begin end;
         $4100 :begin end;
         $4110 :
             begin
       	BlockRead(_file,obj.numVerts,2);
        	for i:=0 to obj.numVerts - 1 do
                        begin
    	         BlockRead (_file, obj.v[i].x,4);
                             BlockRead (_file, obj.v[i].y,4);
        	         BlockRead (_file, obj.v[i].z,4);
     	    end;
            end;
    
         $4120 :
          begin
    	BlockRead (_file,obj.numPolys, 2);
                      for i:=0 to obj.numPolys - 1 do
                         begin
    	        BlockRead (_file,obj.p[i].a, 2);
        	        BlockRead (_file,obj.p[i].b, 2);
    	        BlockRead (_file,obj.p[i].c, 2);
    	        BlockRead (_file,useless, 2);
    	     end;
          end;
    
         $4140 :
          begin
       	BlockRead (_file , useless, 2);
        	  for i:=0 to obj.numVerts - 1 do
    	     begin
    	         BlockRead (_file , obj.m[i].u , 4);
                             BlockRead (_file , obj.m[i].v , 4);
    	     end;
          end;
        else
        begin
             from := filePos(_file);
             seek(_file,from + chunkLength-6);
         end;
        end;
      end;
     closefile(_file);
    end;
    
    procedure T3DS.Draw();
    var i : integer;
    begin
    
       glBegin(GL_TRIANGLES);
         for i:=0 to obj.numPolys - 1 do
            begin
                 glTexCoord2f( obj.m[ obj.p[i].a ].u,obj.m[ obj.p[i].a ].v);
                 glVertex3f( obj.v[ obj.p[i].a ].x,
                                  obj.v[ obj.p[i].a ].y,
                                  obj.v[ obj.p[i].a ].z);
    
                 glTexCoord2f( obj.m[ obj.p[i].b ].u,obj.m[ obj.p[i].b ].v);
                 glVertex3f( obj.v[ obj.p[i].b ].x,
                                  obj.v[ obj.p[i].b ].y,
                                  obj.v[ obj.p[i].b ].z);
    
                 glTexCoord2f( obj.m[ obj.p[i].c ].u,obj.m[ obj.p[i].c ].v);
                 glVertex3f( obj.v[ obj.p[i].c ].x,
                                  obj.v[ obj.p[i].c ].y,
                                  obj.v[ obj.p[i].c ].z);
            end;
    
     glEnd();
    
    end;
    
    procedure T3DS.free;
    begin
     //
    end.
    virtual
    Last edited by virtual; 14-09-2010 at 07:36 PM.

  2. #2
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Re: Tiny 3DS loader

    Cool. Is this something that you will be continually updating?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  3. #3

    Re: Tiny 3DS loader

    this way we don't need to update

  4. #4

    Re: Tiny 3DS loader

    I was hoping it'd have bone structure i could learn from Useful regardless.

  5. #5

    Re: Tiny 3DS loader

    Oh another 3ds loader for pascal and opengl :-)

    Have a look at mine too: http://www.noeska.com/dogl/glmodel.aspx . That also does bone animation for milkshape ascii files. But afaik mine might have lost its tinyness...
    http://3das.noeska.com - create adventure games without programming

  6. #6
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Wow, I just realized just how tiny this little loader really is. Now you called it a wrapper, but in reality it's just a mini library for use with OpenGL, right? From the source code above it doesn't seem to need an extra API file to work.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  7. #7
    Don't take it as a criticism, but I'd really love to see the code more Delphi-like ("objects" were deprecated a long time ago). Plus, just like User137 said, animations would be most welcome, too. Also, some normal calculation code can fit in too, if you ask me.

    Enough bitchin, nice piece of work, virtual. Keep up the great work, hope you can expand the code.

  8. #8
    glad that you like it

    i think this is the most minimal 3ds loader , i used it to draw low res objects. ( i use another loader for other purposes)
    another thing can benefit is to write your own simple 3d file format based on the previous data structure

  9. #9
    Can you point me to a 3ds file for which this loader works? I have tried it on some, but they seem to include multiple sets of vertices, which overwrite each other in this loader. I suppose these are complex shapes, unsupported by this code, right?

  10. #10
    Quote Originally Posted by Ingemar View Post
    Can you point me to a 3ds file for which this loader works? I have tried it on some, but they seem to include multiple sets of vertices, which overwrite each other in this loader. I suppose these are complex shapes, unsupported by this code, right?
    I found one answer in my own notes (after trying the C++ original of this code):

    "62standing-woman.3ds"

    I don't know where I got that, but that one works - but most others I have tried fail. That limits the usage quite a bit.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •