Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Using TMesh in Firemonkey


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 7 - Last Post: Nov 7, 2016 10:19 PM Last Post By: Bennie Coetzer
Bennie Coetzer

Posts: 42
Registered: 12/2/03
Using TMesh in Firemonkey  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2016 1:32 AM
Hi, I am trying to display a terrain surface from a Digital Elevation Model in 3D in Firemonkey. The idea is to use an aerial image of the area to show the surface.
I am able to load the DEM and display the wireframe of the area but cannot get the texture right. I have tried unsuccessfully with many options from the few examples available but still have no success. Maybe someone can point me in the right direction.
The aerial surface is a bitmap that I intend to assign to the texturematerialsource - but at present no surface is visible. There is a light in the application.
Also if there are any detail tutorial resources for using TMesh available could someone direct me to them. A few very interesting Embarcadero videos are available but they are in Polish - would translation be possible?

I am using Delphi XE8
My code

procedure TForm1.WireFrameRenderer(Sender: TObject; Context: TContext3D);
begin
  if MapLoaded then
  begin
    with Mesh1.Data do
    begin
      Context.DrawLines(VertexBuffer, IndexBuffer, TMaterialSource.ValidMaterial(ColorMaterialSource1), 1);
    end;
  end;
 
end;
 
procedure TForm1.PopulateMesh;
var
  NumOfpoints: Integer;
  P : array [0..3] of TPoint3D;
  NP, NI : Integer;
  i, j: integer;
  row, col : integer;
  aVertex: TPoint3D;
  NColsOffset, NRowsOffset : integer;
  aScaleValue: Extended;
begin
  // Populate Mesh
  TextureMaterialSource1.Texture.LoadFromFile('aBMP.bmp');
  Mesh1.MaterialSource := TextureMaterialSource1;
  NumOfpoints := 0;
  Mesh1.Data.Clear;
  Mesh1.Data.VertexBuffer.Length := myDEMTool.DEMMap.NCols * myDEMTool.DEMMap.NRows * 4;
  Mesh1.Data.IndexBuffer.Length := myDEMTool.DEMMap.NCols * myDEMTool.DEMMap.NRows * 6;
  NColsOffset := myDEMTool.DEMMap.NCols div 2;
  NRowsOffset := myDEMTool.DEMMap.NRows div 2;
 
  aScaleValue := myDEMTool.DEMMap.CellSizeLong;  // In this case the height is same as width
  aScaleValue := 10;                             // exagerated height
 
  NP := 0;
  NI := 0;
  with Mesh1.Data do
  begin   // Set the points
    for row := 0 to myDEMTool.DEMMap.NCols-2 do
    begin
      for col := 0 to myDEMTool.DEMMap.NRows - 2 do
      begin
        // Set up the points in the XZ plane (4 points)
        P[0].z := row - NRowsOffset;
        P[0].x := col - NColsOffset;
        P[1].z := row + 1 - NRowsOffset;
        P[1].x := col - NColsOffset;
        P[2].z := row + 1 - NRowsOffset;
        P[2].x := col + 1 - NColsOffset;
        P[3].z := row - NRowsOffset;
        P[3].x := col + 1 - NColsOffset;
        // Allocate the elevation values as y
        P[0].y := -myDEMTool.DEMMap.DEMElevation[row, col] / aScaleValue;    // Scaled with row, col scale
        P[1].y := -myDEMTool.DEMMap.DEMElevation[row + 1, col] / aScaleValue;
        P[2].y := -myDEMTool.DEMMap.DEMElevation[row + 1, col + 1] / aScaleValue;
        P[3].y := -myDEMTool.DEMMap.DEMElevation[row, col + 1] / aScaleValue;
        with VertexBuffer do
        begin
          Vertices[NP + 0] := P[0];
          Vertices[NP + 1] := P[1];
          Vertices[NP + 2] := P[2];
          Vertices[NP + 3] := P[3];
        end;
 
        // map the colours
        with VertexBuffer do
        begin
          TexCoord0[NP+0] := PointF(0.5, 0.5);
          TexCoord0[NP+1] := PointF(0.5, 0.5);
          TexCoord0[NP+2] := PointF(0.5, 0.5);
          TexCoord0[NP+3] := PointF(0.5, 0.5);
        end;
        with IndexBuffer do
        begin
          // Map the triangles
          IndexBuffer[NI + 0] := NP + 1;
          IndexBuffer[NI + 1] := NP + 2;
          IndexBuffer[NI + 2] := NP + 3;
          IndexBuffer[NI + 3] := NP + 3;
          IndexBuffer[NI + 4] := NP + 0;
          IndexBuffer[NI + 5] := NP + 1;
        end;
        NP := NP + 4;
        NI := NI + 6;
      end;
    end;
 
  end;
  Mesh1.Data.CalcFaceNormals();    // Calculate the normals?
end;
 
Marc Bonnaud

Posts: 14
Registered: 7/1/16
Re: Using TMesh in Firemonkey  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2016 7:23 AM   in response to: Bennie Coetzer in response to: Bennie Coetzer
Bennie Coetzer wrote:

Also if there are any detail tutorial resources for using TMesh available could someone direct me to them. A few very interesting Embarcadero videos are available but they are in Polish - would translation be possible?

This Quark Cube video shows a nice example of how to deal with TMesh ; you need to watch in full screen mode and stop from time to time to take note of the code :
https://www.youtube.com/watch?v=KWKtM7TfdLM

There are comments in German beside the code, but you can use Google translate.
Bennie Coetzer

Posts: 42
Registered: 12/2/03
Re: Using TMesh in Firemonkey  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2016 12:28 PM   in response to: Marc Bonnaud in response to: Marc Bonnaud
Marc Bonnaud wrote:
Bennie Coetzer wrote:

Also if there are any detail tutorial resources for using TMesh available could someone direct me to them. A few very interesting Embarcadero videos are available but they are in Polish - would translation be possible?

This Quark Cube video shows a nice example of how to deal with TMesh ; you need to watch in full screen mode and stop from time to time to take note of the code :
https://www.youtube.com/watch?v=KWKtM7TfdLM

There are comments in German beside the code, but you can use Google translate.

Hi Thank you
I have built this model but it does not help with the texture build
Regards
Zoltan Karpati

Posts: 2
Registered: 10/8/12
Re: Using TMesh in Firemonkey  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2016 11:09 AM   in response to: Bennie Coetzer in response to: Bennie Coetzer
I don't understand why do you set all all UV vertices to (0.5, 0.5)!

        // map the colours
        with VertexBuffer do
        begin
          TexCoord0[NP+0] := PointF(0.5, 0.5);
          TexCoord0[NP+1] := PointF(0.5, 0.5);
          TexCoord0[NP+2] := PointF(0.5, 0.5);
          TexCoord0[NP+3] := PointF(0.5, 0.5);
        end;
Bennie Coetzer

Posts: 42
Registered: 12/2/03
Re: Using TMesh in Firemonkey  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 19, 2016 5:14 AM   in response to: Zoltan Karpati in response to: Zoltan Karpati
Zoltan Karpati wrote:
I don't understand why do you set all all UV vertices to (0.5, 0.5)!

        // map the colours
        with VertexBuffer do
        begin
          TexCoord0[NP+0] := PointF(0.5, 0.5);
          TexCoord0[NP+1] := PointF(0.5, 0.5);
          TexCoord0[NP+2] := PointF(0.5, 0.5);
          TexCoord0[NP+3] := PointF(0.5, 0.5);
        end;

This was just an attempt to map a single colour - not the final which should map a complete bitmap
Thanks
Peter Guth

Posts: 28
Registered: 2/11/05
Re: Using TMesh in Firemonkey  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 29, 2016 11:42 AM   in response to: Bennie Coetzer in response to: Bennie Coetzer
I've had the same kinds of issues with tMeshGrid, for a problem that is probably similar to yours (I have a pretty full blown freeware GIS program, which you can get at https://www.usna.edu/Users/oceano/pguth/website/microdem/microdemdown.htm). It written in VCL, but the 3D is FireMonkey that works well inside the VCL program). There is also a FireMonkey version that runs on Android, with a reduced set of capabilities. If you have common GIS data formats, it should do what you want.

I have gotten much better results with a point cloud (advantage that it also works with real lidar point clouds), even for the grid and overlaid image like you want to do.

If you're interested we can discuss collaboration. The code runs in Berlin, and I don't know how much effort it would take to run in an older version of Delphi, and the coordinate details and DEM formats impose a huge framework that you have to include before you can get the code to compile and work.
Bennie Coetzer

Posts: 42
Registered: 12/2/03
Re: Using TMesh in Firemonkey  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 7, 2016 10:19 PM   in response to: Peter Guth in response to: Peter Guth
Peter Guth wrote:
I've had the same kinds of issues with tMeshGrid, for a problem that is probably similar to yours (I have a pretty full blown freeware GIS program, which you can get at https://www.usna.edu/Users/oceano/pguth/website/microdem/microdemdown.htm). It written in VCL, but the 3D is FireMonkey that works well inside the VCL program). There is also a FireMonkey version that runs on Android, with a reduced set of capabilities. If you have common GIS data formats, it should do what you want.

I have gotten much better results with a point cloud (advantage that it also works with real lidar point clouds), even for the grid and overlaid image like you want to do.

If you're interested we can discuss collaboration. The code runs in Berlin, and I don't know how much effort it would take to run in an older version of Delphi, and the coordinate details and DEM formats impose a huge framework that you have to include before you can get the code to compile and work.

Thank you. I will download the tool and will come back regarding collaboration. We may well be very interested as we are not really into GIS development.
I will let you know.
regards
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02