3D vertex saving lazarus / 21-General ---------------------------------------------------------------------- lazboy10 · 2021-03-14 10:42 Hi there! i have been working on a 3d modeler software and i have a problem with saving the model to file. the model is built with 2 arrays one for vertices and one for faces. All deleted vertices have a "Deleted" value. So when i try to save and skip the deleted vertices the face vertex indexes get all mixed up resulting in a total mess. I have tried to loop through all faces and change the indexes but it just doesn't work. i have tried everything i can think of to get it working but nothing works. So im asking here if anyone knows how to do it, and if you would provide some simple code to do it that would be awesome. cheers. ---------------------------------------------------------------------- dseligo · 2021-03-14 10:57 Try to save array with "Deleted" value and see if that works. Can you show array declaration and code you use to save arrays? ---------------------------------------------------------------------- lazboy10 · 2021-03-14 11:06 It works if i keep the deleted vertices but i need to skip them... here is some code that i tried for skipping the deleted vertices: VertCount := 0; for I := 0 to Length(ModelData.Groups[0].Vertices)-1 do if ModelData.Groups[0].Vertices.Deleted = False then begin   SetLength(TempVertices, VertCount+1);   TempVertices[VertCount] := ModelData.Groups[0].Vertices;   Inc(VertCount); end; this is for trying to decrease the face list indexes.     FCount := 0;     for V := 0 to Length(TempVertices)-1 do     begin       Vert := TempVertices[V];       if Vert.Deleted = True then       begin         Index := V;         for F := FCount to Length(ModelData.Groups[0].Faces) -1 do         begin           Face := ModelData.Groups[0].Faces[F];           if Face.V1 = Index then             Dec(Face.V1);           if Face.V2 = Index then             Dec(Face.V2);           if Face.V3 = Index then             Dec(Face.V3);           ModelData.Groups[0].Faces[F] := Face;         end;         Inc(FCount);       end;     end; ---------------------------------------------------------------------- marcov · 2021-03-14 11:21 If you are not against throwing an array of integers to it Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var indexmapping : array of integer; setlength(indexmapping,Length(ModelDa ta.Groups[0].Vertices));VertCount := 0;for I := 0 to Length(ModelData.Groups[0].Vertices)-1 dobeginif ModelData.Groups[0].Vertices.Deleted = False thenbegin  SetLength(TempVertices, VertCount+1);  TempVertices[VertCount] := ModelData.Groups[0].Vertices;  indexmapping[i]:=vertcount; // i is now at current value of "vertcount"  Inc(VertCount);endelse  indexmapping[i]:=-1; // signal deleted vertex for double checking if neededend; then walk the faces and just do if indexmapping=-1 remove it. This also reduces a two dimensional (O(n^2)) walk into two linear (O(n) ) ones. ---------------------------------------------------------------------- speter · 2021-03-14 22:24 I'd suggest simply saving the faces (after the scene settings etc), with each face including its points (and colours etc). Then when loading the scene rebuild the points list. Have a look at https://forum.lazarus.freepascal.org/index.php/topic,52 526.msg387685.html#msg387685 there is a link to a project which loads a (text file) with a 3d model; it doesn't include 'save' but it does include 'readfromdisk()'; it might also be of interest to see a more object oriented approach. Look at "sceneu.pas" and "hut.per". cheers S. ---------------------------------------------------------------------- lazboy10 · 2021-03-16 19:07 Quote from: marcov on March 14, 2021, 12:21:49 pmIf you are not against throwing an array of integers to it Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var indexmapping : array of integer; setlength(indexmapping,Length(ModelDa ta.Groups[0].Vertices));VertCount := 0;for I := 0 to Length(ModelData.Groups[0].Vertices)-1 dobeginif ModelData.Groups[0].Vertices.Deleted = False thenbegin  SetLength(TempVertices, VertCount+1);  TempVertices[VertCount] := ModelData.Groups[0].Vertices;  indexmapping[i]:=vertcount; // i is now at current value of "vertcount"  Inc(VertCount);endelse  indexmapping[i]:=-1; // signal deleted vertex for double checking if neededend; then walk the faces and just do if indexmapping=-1 remove it. This also reduces a two dimensional (O(n^2)) walk into two linear (O(n) ) ones. Hey, What do you mean by "then walk the faces and just do if indexmapping=-1 remove it." can you show me with code how do it? i have tried a few things with the integer list, but nothing that's worked.