user3332785
user3332785

Reputation: 1

How to update a GLScene TGLMeshObject without duplicating the image

I am using a variation of the IntensityMesh example under AdvDemos in the GLScene folder. It consists of a the following components: GLMaterialLibrary, GLScene (cube symbol), GLWindowsBitMapFont and GLUserShader on top of a GLSceneViewer with a GLCamera.

I am using the code below to draw the colored image and it works the first time. However, if I want to update the color values by reading a different set of Stress records, it redraws the whole image, slightly offset upwards and to the left, but on top of the previous image. Since it uses a slider to change the intensity without redrawing the whole image, I know it should be possible. Any action to free mo just leads to an access violation.

I am looking forward to hear how to fix this this!

Regards Dan

  mo := TGLMeshObject.CreateOwned(GLFreeForm.MeshObjects);
  mo.Mode := momFaceGroups;

    with NdesTable do
    begin
      First;
      i:=0;
      while not Eof do
      begin
        try
          if i=0 then
            mo.Vertices.Add(0.0,0.0,0.0); // not having this corrupts the whole mesh
          mo.Vertices.Add(
            FieldByName('X').AsSingle * 1000,
            FieldByName('Y').AsSingle * 1000,
            FieldByName('Z').AsSingle * 1000 );
          Next;
          inc(i);
        except
          on e: Exception do
          begin
            ShowMessage(e.Message);
          end;
        end;
      end;
    end;

    fgTris := TFGVertexIndexList.CreateOwned(mo.FaceGroups);
    fgTris.Mode := fgmmTriangles;
    with ElemsTable do
    begin
      First;
      while not Eof do
      begin
        try
          fgTris.VertexIndices.Add(
            FieldByName('N1').AsInteger,
            FieldByName('N2').AsInteger,
            FieldByName('N3').AsInteger);
        except
          on e: Exception do
          begin
            ShowMessage(e.Message);
          end;
        end;
        Next;
      end;
    end;

    with StressTable do
    begin
      First;
      i:=0;
      while not Eof do
      begin
        if i=0 then
        begin
          mo.TexCoords.Add(0.0, 0); // not sure if this is necessary
        end;
        v := FieldByName('V').AsSingle;
        mo.TexCoords.Add(v/100, 0);
        Next;
        inc(i);
      end;
    end;

I have also tried to clear the screen using a proxyobject (as advised somewhere on these pages) but I was just left with a blank screen, not accepting any actions.

I have tried to free the GLviewer object and recreate it before populating the mesh

If assigned(GLviewer1) then GLViewer1.destroy;
If assigned(GLviewer1) then GLViewer1.free; // access violation improper pointer op
If assigned(GLviewer1) then GLViewer1:=nil;

If assigned(mo) then mo.destroy;
If assigned(mo) then mo.free; // access violation improper pointer op
If assigned(mo) then mo:=nil;

Illustration of problem

Upvotes: 0

Views: 88

Answers (0)

Related Questions