> For the complete documentation index, see [llms.txt](https://amazing-assets.gitbook.io/terrain-to-obj/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://amazing-assets.gitbook.io/terrain-to-obj/run-time-api.md).

# Run-time API

**Terrain To OBJ** extension methods can be brought into scope with this using directive:

```
using AmazingAssets.TerrainToOBJ;
```

Unity [TerrainData](https://docs.unity3d.com/Documentation/ScriptReference/TerrainData.html) class now will have two additional methods **ToOBJ** and **ToOBJStreamWriter**:

### ToOBJ

```csharp
string ToOBJ (int vertexCountHorizontal, int vertexCountVertical, 
              Normal normalReconstruction, Vector3 originPosition)
```

Converts [TerrainData](https://docs.unity3d.com/ScriptReference/TerrainData.html) object into **OBJ** mesh and returns result as a **string**.&#x20;

{% hint style="warning" %}
Depending on the number of vertex counts used, the **string** size can reach hundreds of megabytes or even gigabytes. Be careful.&#x20;
{% endhint %}

```csharp
string ToOBJ (int vertexCountHorizontal, int vertexCountVertical, 
              int chunkCountHorizontal, int chunkCountVertical, 
              bool perChunkUV, Normal normalReconstruction, Vector3 originPosition)
```

Splits generated terrain mesh into multi-chunk 2D grid and return result a **string**.

If *<mark style="color:blue;">perChunkUV</mark>* property is enabled, each mesh inside 2D grid array has normalized UVs in the range of \[0, 1].&#x20;

<div><figure><img src="/files/GS6rHIu1W2m8RR5SHdUB" alt=""><figcaption><p>Per chunk UV - <strong>False</strong></p></figcaption></figure> <figure><img src="/files/ExO5HyrnDlTTqVqXKqjO" alt=""><figcaption><p>Per chunk UV - <strong>True</strong></p></figcaption></figure></div>

```csharp
string ToOBJ (int vertexCountHorizontal, int vertexCountVertical, 
              int chunkCountHorizontal, int chunkCountVertical, 
              int positionX, int positionY, 
              bool perChunkUV, Normal normalReconstruction, Vector3 originPosition)
```

Splits generated terrain mesh into multi-chunk 2D grid and exports one mesh with index of *<mark style="color:blue;">positionX</mark>* and *<mark style="color:blue;">positionY</mark>*.

### ToOBJStreamWriter

```csharp
void ToOBJStreamWriter (System.IO.StreamWriter streamWriter, 
                        int vertexCountHorizontal, int vertexCountVertical, 
                        Normal normalReconstruction, Vector3 originPosition)
```

[TerrainData](https://docs.unity3d.com/ScriptReference/TerrainData.html) is converted into OBJ file as a single mesh and using *<mark style="color:blue;">streamWriter</mark>* is instantly saved into a file.

```csharp
void ToOBJStreamWriter (System.IO.StreamWriter streamWriter, 
                        int vertexCountHorizontal, int vertexCountVertical, 
                        int chunkCountHorizontal, int chunkCountVertical, 
                        bool perChunkUV, Normal normalReconstruction, Vector3 originPosition)
```

Splits generated terrain mesh into multi-chunk 2D grid and using *<mark style="color:blue;">streamWriter</mark>* is instantly\
saved into a file.

```csharp
void ToOBJStreamWriter (System.IO.StreamWriter streamWriter, 
                        int vertexCountHorizontal, int vertexCountVertical, 
                        int chunkCountHorizontal, int chunkCountVertical, 
                        int positionX, int positionY, 
                        bool perChunkUV, Normal normalReconstruction, Vector3 originPosition)
```

Splits generated terrain mesh into multi-chunk 2D grid, but only mesh with index of *<mark style="color:blue;">positionX</mark>* and *<mark style="color:blue;">positionY</mark>* is exported and using *<mark style="color:blue;">streamWriter</mark>* is instantly saved into a file.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://amazing-assets.gitbook.io/terrain-to-obj/run-time-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
