Menu

TFGIndexTexCoordList.Reverse doesn't reverse TExCoords

Help
2014-05-07
2014-05-19
  • Alexandre Guilleme

    All is in the title !
    The vertices indexes are reversed, but the texcoords are not.
    Here's a patch to fix it

    Index: GLVectorFileObjects.pas
    ===================================================================
    --- GLVectorFileObjects.pas (révision 6451)
    +++ GLVectorFileObjects.pas (copie de travail)
    @@ -1249,6 +1249,7 @@
         procedure WriteToFiler(writer: TVirtualWriter); override;
         procedure ReadFromFiler(reader: TVirtualReader); override;
    
    +    procedure Reverse; override;
         procedure BuildList(var mrci: TRenderContextInfo); override;
         procedure AddToTriangles(aList: TAffineVectorList;
           aTexCoords: TAffineVectorList = nil;
    @@ -6984,6 +6985,16 @@
       FTexCoords.Assign(val);
     end;
    
    +// Reverse
    +//
    +
    +procedure TFGIndexTexCoordList.Reverse;
    +begin
    +  inherited;
    +
    +  TexCoords.Reverse;
    +end;
    +
     // BuildList
     //
    
     
  • Alexandre Guilleme

    Maybe this function should be more "intelligent" than juste reversing lists.
    if the Mode of TFGVertexIndexList (TFGIndexTexCoordList's parent) is fgmmTriangleFan, this Reverse function is not correct if the goal is to see the mesh from the other side.

    In this mode, the first vertex is common to all triangles. If the list is just reversed, this vertex is swapped with the last one, which becomes the common one.
    I think the Reverse function should contain a piece of code like this :

      VertexIndices.Reverse; // <- existing code
      if (Self.Mode = fgmmTriangleFan) and (VertexIndices.Count > 0) then
        VertexIndices.Move(VertexIndices.Count-1, 0); //Put the first vertex back to its place
    

    and so on for the TexCoords in TFGIndexTexCoordList

    PS: This change will not work until the Move function bug is fixed

     

    Last edit: Alexandre Guilleme 2014-05-07
  • Alexandre Guilleme

    The reverse function doesn't work anymore in fgmmTriangleStrip with an even number of vertices (the normal keeps the same direction).

    Here is a new version of the patch (also in attachment)

    Index: Source/GLVectorFileObjects.pas
    ===================================================================
    --- Source/GLVectorFileObjects.pas  (révision 6451)
    +++ Source/GLVectorFileObjects.pas  (copie de travail)
    @@ -1162,6 +1162,7 @@
         procedure AddToList(source, destination: TAffineVectorList;
           indices: TIntegerList);
    
    +    procedure ReverseListByMode(AList: TBaseList);
       public
         { Public Declarations }
         constructor Create; override;
    @@ -1253,6 +1254,7 @@
         procedure AddToTriangles(aList: TAffineVectorList;
           aTexCoords: TAffineVectorList = nil;
           aNormals: TAffineVectorList = nil); override;
    +    procedure Reverse; override;
    
         procedure Add(idx: Integer; const texCoord: TAffineVector); overload;
         procedure Add(idx: Integer; const s, t: Single); overload;
    @@ -6529,6 +6531,34 @@
       InvalidateVBO;
     end;
    
    +// ReverseListByMode
    +//
    +
    +procedure TFGVertexIndexList.ReverseListByMode(AList: TBaseList);
    +begin
    +  if AList.Count = 0 then
    +    Exit; //<<<<<<<<<< Exit >>>>>>>>>>
    +
    +  case Mode of
    +    fgmmTriangleFan : begin
    +      //0-1-2-3-4-5 => 0-5-4-3-2-1
    +      AList.Reverse;
    +      AList.Move(AList.Count-1, 0);
    +    end;
    +    fgmmTriangleStrip : begin
    +      //0-1-2-3-4-5 => 0-0-1-2-3-4-5 (duplicating 1st vertex inverts normal)
    +      AList.InsertNulls(0, 1);
    +      AList.Copy(1, 0);
    +    end;
    +    fgmmTriangles, fgmmFlatTriangles, fgmmQuads : begin
    +      //0-1-2-3-4-5 => 5-4-3-2-1-0
    +      AList.Reverse;
    +    end;
    +  else
    +    Assert(False);
    +  end;
    +end;
    +
     // BuildList
     //
    
    @@ -6676,7 +6706,7 @@
    
     procedure TFGVertexIndexList.Reverse;
     begin
    -  VertexIndices.Reverse;
    +  ReverseListByMode(VertexIndices);
       InvalidateVBO;
     end;
    
    @@ -6984,6 +7014,16 @@
       FTexCoords.Assign(val);
     end;
    
    +// Reverse
    +//
    +
    +procedure TFGIndexTexCoordList.Reverse;
    +begin
    +  inherited;
    +
    +  ReverseListByMode(TexCoords);
    +end;
    +
     // BuildList
     //
    
    Index: Source/VectorLists.pas
    ===================================================================
    --- Source/VectorLists.pas  (révision 6451)
    +++ Source/VectorLists.pas  (copie de travail)
    @@ -134,6 +134,7 @@
         procedure DeleteItems(Index: Integer; nbVals: Cardinal);
         procedure Exchange(index1, index2: Integer);
         procedure Move(curIndex, newIndex: Integer);
    +    procedure Copy(srcIndex, dstIndex: Integer);
         procedure Reverse;
    
             {: Nb of items in the list.<p>
    @@ -1214,6 +1215,22 @@
       end;
     end;
    
    +// Copy
    +//
    +procedure TBaseList.Copy(srcIndex, dstIndex: Integer);
    +begin
    +   if srcIndex<>dstIndex then begin
    +{$IFOPT R+}
    +    Assert(Cardinal(srcIndex)<Cardinal(Count));
    +    Assert(Cardinal(dstIndex)<Cardinal(Count));
    +{$ENDIF}
    +    if FItemSize=4 then
    +       PInteger(@FBaseList[dstIndex*FItemSize])^ := PInteger(@FBaseList[srcIndex*FItemSize])^
    +    else
    +      System.Move(FBaseList[srcIndex*FItemSize], FBaseList[dstIndex*FItemSize], FItemSize);
    +  end;
    +end;
    +
     // Reverse
     //
     procedure TBaseList.Reverse;
    
     

    Last edit: Alexandre Guilleme 2014-05-19

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.