Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
terrain [2019/05/02 14:03] – [Resolution] admin | terrain [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Loading terrain ====== | ||
- | Gorilla3D provides a simple terrain component for generation from height-map image. Besides the default usage, different procedural builders are available: diamond square, mandelbrot, perlin-noise (linear, cosine and cubic), plateau algorithms. The resolution / number of vertices is configurable. | ||
- | |||
- | |||
- | For detailed information about the component and its methods, check out: Gorilla.Terrain | ||
- | |||
- | |||
- | ===== Creating a terrain at runtime from heightmap ===== | ||
- | |||
- | <file pascal Form1.pas> | ||
- | uses | ||
- | Gorilla.Terrain, | ||
- | Gorilla.Material.Lambert; | ||
- | |||
- | procedure TForm1.FormCreate(Sender: | ||
- | var LTexturePath : String; | ||
- | begin | ||
- | LTexturePath := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))); | ||
- | | ||
- | FTerrain := TGorillaTerrain.Create(fGorilla); | ||
- | FTerrain.Parent := FGorillaViewport; | ||
- | | ||
- | // set resolution of terrain to 256 x 256 sections | ||
- | // this generates 65.536 cells with 131.072 triangles and 393.216 vertices. | ||
- | FTerrain.ResolutionX := 256; | ||
- | FTerrain.ResolutionY := 256; | ||
- | | ||
- | // here we load the height map image | ||
- | FTerrain.HeightMap.LoadFromFile(LTexturePath + ' | ||
- | | ||
- | // adjust terrain size and scaling | ||
- | FTerrain.HeightScale := 10; | ||
- | FTerrain.Scale.X := 100; | ||
- | FTerrain.Scale.Y := 10; | ||
- | FTerrain.Scale.Z := 100; | ||
- | |||
- | // build terrain mesh from previously loaded heightmap | ||
- | // 1st param: static buffering for large number of vertices. | ||
- | // 2nd param: decimation disabled | ||
- | FTerrain.RebuildTerrain(true, | ||
- | |||
- | // apply a material as texture to it | ||
- | FTerrainMaterial := TGorillaLambertMaterial.Create(FTerrain); | ||
- | FTerrainMaterial.Parent := FTerrain; | ||
- | FTerrainMaterial.Texture.LoadFromFile(LTexturePath + ' | ||
- | FTerrain.Mesh.MaterialSource := FTerrainMaterial; | ||
- | end; | ||
- | </ | ||
- | |||
- | |||
- | ===== Creating a terrain at runtime by procedural method ===== | ||
- | |||
- | <file pascal Form1.pas> | ||
- | uses | ||
- | Gorilla.Terrain, | ||
- | Gorilla.Material.Lambert; | ||
- | |||
- | procedure TForm1.FormCreate(Sender: | ||
- | var LTexturePath : String; | ||
- | begin | ||
- | LTexturePath := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))); | ||
- | | ||
- | FTerrain := TGorillaTerrain.Create(fGorilla); | ||
- | FTerrain.Parent := FGorillaViewport; | ||
- | | ||
- | // set resolution of terrain to 256 x 256 sections | ||
- | // this generates 65.536 cells with 131.072 triangles and 393.216 vertices. | ||
- | FTerrain.ResolutionX := 256; | ||
- | FTerrain.ResolutionY := 256; | ||
- | | ||
- | // adjust terrain size and scaling | ||
- | FTerrain.HeightScale := 10; | ||
- | FTerrain.Scale.X := 100; | ||
- | FTerrain.Scale.Y := 10; | ||
- | FTerrain.Scale.Z := 100; | ||
- | |||
- | // build a random terrain by a predefined procedural algorithm | ||
- | FTerrain.RandomTerrain(TRandomTerrainAlgorithmType.DiamondSquare); | ||
- | |||
- | // apply a material as texture to it | ||
- | FTerrainMaterial := TGorillaLambertMaterial.Create(FTerrain); | ||
- | FTerrainMaterial.Parent := FTerrain; | ||
- | FTerrainMaterial.Texture.LoadFromFile(LTexturePath + ' | ||
- | FTerrain.Mesh.MaterialSource := FTerrainMaterial; | ||
- | end; | ||
- | </ | ||
- | |||
- | __NOTICE:__ Once you build a random terrain, you are able to store the heightmap bitmap and reload later. | ||
- | |||
- | ===== Creating an individual procedural terrain algorithm ===== | ||
- | |||
- | You can also develop your own procedural algorithm by extending TRandomTerrainAlgorithm or any descendant. In the example below, we generate a random terrain: | ||
- | |||
- | <file pascal MyTerrainAlg.pas> | ||
- | type | ||
- | TMyTerrainAlgorithm = class(TRandomTerrainAlgorithm) | ||
- | protected | ||
- | procedure Generate(); | ||
- | public | ||
- | function GetHeightMap() : TBitmap; override; | ||
- | end; | ||
- | | ||
- | { TMyTerrainAlgorithm } | ||
- | |||
- | |||
- | procedure TMyTerrainAlgorithm.Generate(); | ||
- | var x, z: Integer; | ||
- | i : Integer; | ||
- | begin | ||
- | System.SetLength(FData, | ||
- | for i := 0 to High(FData) do | ||
- | System.SetLength(FData[i], | ||
- | | ||
- | for x := 0 to 255 do | ||
- | for z := 0 to 255 do | ||
- | begin | ||
- | FData[x, z] := Random(100) / 100; | ||
- | end; | ||
- | end; | ||
- | |||
- | function TMyTerrainAlgorithm.GetHeightMap() : TBitmap; | ||
- | begin | ||
- | Generate(); | ||
- | |||
- | result := inherited; | ||
- | end; | ||
- | |||
- | LMyTerrainAlgorithm := TMyTerrainAlgorithm.Create(); | ||
- | try | ||
- | FTerrain.RandomTerrain(LMyTerrainAlgorithm); | ||
- | finally | ||
- | FreeAndNil(LMyTerrainAlgorithm); | ||
- | end; | ||
- | </ | ||
- | |||
- | ===== Resolution ===== | ||
- | It is recommend to use 2 ^ X resolution sizes for your terrain. | ||
- | Set resolution by the published properties " | ||
- | |||
- | The table below lists common terrain sizes and their resulting vertices. | ||
- | |||
- | ^ Size ^ Vertex-Count ^ Index-Count ^ Triangles ^ Memory-Size ^ | ||
- | | 16 x 16 | | | | | ||
- | | 32 x 32 | 1089 | 6144 | 2048 | | ||
- | | 64 x 64| | | | | ||
- | | 128 x 128 | | | | | ||
- | | 256 x 256 | | | | | ||
- | | 512 x 512 | | | | | ||
- | | 1024 x 1024 | | | | | ||
- | | 2048 x 2048 | | | | | ||
- | | 4096 x 4096 | | | | | ||
- | ===== Smoothing ===== | ||
- | |||
- | |||
- | Next step: [[skybox|Skybox]] |