Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 28

Thread: 3DS, wavefront obj and milkshape ascii loader for delphi

  1. #11

    3DS, wavefront obj and milkshape ascii loader for delphi

    Did you know that it is also possible to create meshes from scratch (if you know what you are doing)
    [pascal]
    //dynamic mesh creation example ...
    scene1.AddModel; //new model
    scene1.Models[1].AddMesh; //new mesh
    scene1.Models[1].AddMaterial; //new material
    scene1.Models[1].Material[0].DiffuseRed:= 1.0; //make it red
    scene1.Models[1].Material[0].DiffuseBlue:= 0.0;
    scene1.Models[1].Material[0].DiffuseGreen:= 0.0;
    scene1.Models[1].Material[0].AmbientRed:= 0.5; //make it red
    scene1.Models[1].Material[0].IsAmbient:=true;
    scene1.Models[1].Material[0].Name:='RedMat';

    scene1.Models[1].Mesh[0].NumVertex := 8; //number of vertexes
    v1.x := -1.0;
    v1.y := -1.0;
    v1.z := -1.0;
    scene1.Models[1].Mesh[0].Vertex[0]:=v1;
    v1.x := -1.0;
    v1.y := -1.0;
    v1.z := 1.0;
    scene1.Models[1].Mesh[0].Vertex[1]:=v1;
    v1.x := -1.0;
    v1.y := 1.0;
    v1.z := -1.0;
    scene1.Models[1].Mesh[0].Vertex[2]:=v1;
    v1.x := -1.0;
    v1.y := 1.0;
    v1.z := 1.0;
    scene1.Models[1].Mesh[0].Vertex[3]:=v1;
    v1.x := 1.0;
    v1.y := -1.0;
    v1.z := -1.0;
    scene1.Models[1].Mesh[0].Vertex[4]:=v1;
    v1.x := 1.0;
    v1.y := -1.0;
    v1.z := 1.0;
    scene1.Models[1].Mesh[0].Vertex[5]:=v1;
    v1.x := 1.0;
    v1.y := 1.0;
    v1.z := -1.0;
    scene1.Models[1].Mesh[0].Vertex[6]:=v1;
    v1.x := 1.0;
    v1.y := 1.0;
    v1.z := 1.0;
    scene1.Models[1].Mesh[0].Vertex[7]:=v1;

    scene1.Models[1].Mesh[0].NumVertexIndices := 36; //number of vertex indices
    scene1.Models[1].Mesh[0].Face[0]:=0;
    scene1.Models[1].Mesh[0].Face[1]:=2;
    scene1.Models[1].Mesh[0].Face[2]:=4;

    scene1.Models[1].Mesh[0].Face[3]:=4;
    scene1.Models[1].Mesh[0].Face[4]:=2;
    scene1.Models[1].Mesh[0].Face[5]:=6;

    scene1.Models[1].Mesh[0].Face[6]:=0;
    scene1.Models[1].Mesh[0].Face[7]:=4;
    scene1.Models[1].Mesh[0].Face[8]:=1;

    scene1.Models[1].Mesh[0].Face[9]:=1;
    scene1.Models[1].Mesh[0].Face[10]:=4;
    scene1.Models[1].Mesh[0].Face[11]:=5;

    scene1.Models[1].Mesh[0].Face[12]:=0;
    scene1.Models[1].Mesh[0].Face[13]:=1;
    scene1.Models[1].Mesh[0].Face[14]:=2;

    scene1.Models[1].Mesh[0].Face[15]:=2;
    scene1.Models[1].Mesh[0].Face[16]:=1;
    scene1.Models[1].Mesh[0].Face[17]:=3;

    scene1.Models[1].Mesh[0].Face[18]:=4;
    scene1.Models[1].Mesh[0].Face[19]:=6;
    scene1.Models[1].Mesh[0].Face[20]:=5;

    scene1.Models[1].Mesh[0].Face[21]:=5;
    scene1.Models[1].Mesh[0].Face[22]:=6;
    scene1.Models[1].Mesh[0].Face[23]:=7;

    scene1.Models[1].Mesh[0].Face[24]:=2;
    scene1.Models[1].Mesh[0].Face[25]:=3;
    scene1.Models[1].Mesh[0].Face[26]:=6;

    scene1.Models[1].Mesh[0].Face[27]:=6;
    scene1.Models[1].Mesh[0].Face[28]:=3;
    scene1.Models[1].Mesh[0].Face[29]:=7;

    scene1.Models[1].Mesh[0].Face[30]:=1;
    scene1.Models[1].Mesh[0].Face[31]:=5;
    scene1.Models[1].Mesh[0].Face[32]:=3;

    scene1.Models[1].Mesh[0].Face[33]:=3;
    scene1.Models[1].Mesh[0].Face[34]:=5;
    scene1.Models[1].Mesh[0].Face[35]:=7;

    //apply material
    scene1.Models[1].Mesh[0].MatName[0]:=scene1.Models[1].Material[0].Name;
    scene1.Models[1].Mesh[0].MatID[0]:=0;

    //add calculated normals ...
    scene1.Models[1].Mesh[0].NumNormals:=12; //for each face indices div 3
    scene1.Models[1].Mesh[0].NumNormalIndices:=36;
    scene1.Models[1].CalcVnormals;

    //add fake texture coords
    scene1.Models[1].Mesh[0].NumMappings:=1;
    scene1.Models[1].Mesh[0].NumMappingIndices:=36;
    map.tu:=0;
    map.tv:=0;
    scene1.Models[1].Mesh[0].Mapping[0]:=map;
    for tel:=0 to 35 do
    begin
    scene1.Models[1].Mesh[0].Map[tel]:=0;
    end;

    //make mesh visible
    scene1.Models[1].Mesh[0].Visible:=true;

    //calculate size for bounding box
    scene1.Models[1].CalculateSize;

    //determine render order even with one mesh
    scene1.Models[1].CalculateRenderOrder;

    //save test
    scene1.Models[1].SaveToFile('test.obj');
    [/pascal]

    Now this should be more 'programmer' friendly. So feedback is appreciated.

    nb: the scene1.Model[1] is one because it is the second model in my test application.

    Also normals calculation is once again in a rewrite cycle so you could expect a new release of glModel after some more testing. The new calculation method breaks current loaders that use it.
    http://3das.noeska.com - create adventure games without programming

  2. #12

    Re: 3DS, wavefront obj and milkshape ascii loader for delphi

    Doesn't seem to work with Delphi 2009, I get access violations when trying to load any 3ds file.
    If you develop an idiot proof system, the nature develops better idiots.

  3. #13

    Re: 3DS, wavefront obj and milkshape ascii loader for delphi

    Erm it should not do that. But i cannot test on delphi2009. Could you post one of your .3ds meshes though so i can rule them out (there are just to many 'wrong' .3ds files). Also could you post the access violation text. Also what kind of video card are you using?
    http://3das.noeska.com - create adventure games without programming

  4. #14

    Re: 3DS, wavefront obj and milkshape ascii loader for delphi

    It was my bad, I had not set all the class pointers...

    How are the faces stored in the TBaseMesh class? The Face property is a word value, is this the index for the first vertex of the face?
    If you develop an idiot proof system, the nature develops better idiots.

  5. #15

    Re: 3DS, wavefront obj and milkshape ascii loader for delphi

    they are the indices for the faces but not per face so 3 is the first vertex of the second face. So 0,1,2 make up the first face. This reminds me i should update the glMesh to use them.

    Could you provide some more detail on why you had to set the class pointers yourselves?
    http://3das.noeska.com - create adventure games without programming

  6. #16

    Re: 3DS, wavefront obj and milkshape ascii loader for delphi

    Because I use it just to load the mesh and convert to my own engine's internal format. But I maybe I'm doing something wrong?

    Like so:
    [pascal]
    function TMVMeshImporter.ImportMesh(const FileName: String): TMeshObject;
    var
    fe: String;
    m3ds: T3dsModel;
    begin
    fe := LowerCase(ExtractFileExt(FileName));
    if fe = '.3ds' then
    begin
    m3ds := T3dsModel.Create(nil);
    m3ds.MeshClass := TBaseMesh;
    m3ds.MaterialClass := TGLMaterial;
    m3ds.SkeletonClass := TGLSkeleton;
    m3ds.LoadFromFile(FileName);
    Result := ConvertMesh(m3ds);
    if Result.Name = '' then
    Result.Name := ExtractFileName(FileName);
    end;
    end;
    [/pascal]
    If you develop an idiot proof system, the nature develops better idiots.

  7. #17

    Re: 3DS, wavefront obj and milkshape ascii loader for delphi

    It is better to use TBaseModel in this case.
    The classes thing is back on the drawing board. As it should automaticly assign the base classes . The setting of TGLMesh, TGLMaterial, TGLSkeleton is only needed so the right class is used for rendering. In your case you should only have to use TBaseModel to load the .3ds model and then you could convert it to your own format.

    Better would be to make your own descendant from TBaseModel e.g. take a look ModelMsa on how to do that. You then would be able to do:

    MyModel.LoadFromFile('test.3ds');
    MyModel.SaveToFile('myformat.ext');

    I try to fix so it is easier to use tmodel/tbasemodel to load 3d model for conversion only.
    http://3das.noeska.com - create adventure games without programming

  8. #18

    Re: 3DS, wavefront obj and milkshape ascii loader for delphi

    The changes for TBaseModel are in the svn now. It did not even have an custom create.

    E.g. now you can do:
    [pascal]
    Model1 := TBaseModel.Create(nil);
    Model1.LoadFromFile('models\tulip.3ds');
    Model1.SaveToFile('tulip.txt');
    Model1.Free;
    [/pascal]

    If you need advice on how to write your own descendant from TBaseModel let me know.
    http://3das.noeska.com - create adventure games without programming

  9. #19

    Re: 3DS, wavefront obj and milkshape ascii loader for delphi

    Thanks, I'll try the new version.
    If you develop an idiot proof system, the nature develops better idiots.

  10. #20

    Re: 3DS, wavefront obj and milkshape ascii loader for delphi

    The new version works and I can load all my test models, as long as the file extensions are in lower case, you should change the extension to lower case when testing which loader to use.

    Thanks!
    If you develop an idiot proof system, the nature develops better idiots.

Page 2 of 3 FirstFirst 123 LastLast

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
  •