# API Reference

## <kbd>MeshifAI API Reference</kbd>

### <kbd>Core API</kbd>

#### `Meshifai.GenerateModel`

The primary method for generating 3D models from text descriptions.

```csharp
public static object GenerateModel(
    string prompt,
    Action<GameObject> onComplete,
    Action<string> onError = null,
    Action<string, float> onStatus = null,
    float variance = 0.2f,
    bool applyDefaultMaterial = true
)
```

**Parameters**

| Parameter              | Type                   | Description                                                       |
| ---------------------- | ---------------------- | ----------------------------------------------------------------- |
| `prompt`               | string                 | Text description of the model to generate                         |
| `onComplete`           | Action\<GameObject>    | Callback when generation completes successfully                   |
| `onError`              | Action\<string>        | (Optional) Callback when an error occurs                          |
| `onStatus`             | Action\<string, float> | (Optional) Callback for status updates (message and progress 0-1) |
| `highRes`              | bool                   | (Optional) Controls the output quality of the genereted model     |
| `applyDefaultMaterial` | bool                   | (Optional) Whether to apply a default material                    |

**Returns**

* `object`: A handle that can be used to cancel the generation

**Example**

```csharp
var handle = Meshifai.GenerateModel(
    "A cyberpunk city building",
    model => {
        // Handle the completed model
    },
    error => {
        // Handle any errors
    },
    (status, progress) => {
        // Show generation progress
    },
    highRes: true
);
```

#### `Meshifai.CancelGeneration`

Cancels an in-progress model generation.

```csharp
public static void CancelGeneration(object handle)
```

**Parameters**

| Parameter | Type   | Description                          |
| --------- | ------ | ------------------------------------ |
| `handle`  | object | The handle returned by GenerateModel |

**Example**

```csharp
// Start generation and store the handle
var handle = Meshifai.GenerateModel("A dragon", OnModelGenerated);

// Later, cancel the generation if needed
Meshifai.CancelGeneration(handle);
```

#### `Meshifai.CloneModel`

Creates a copy of an existing MeshifAI-generated model, preserving all metadata.

```csharp
public static GameObject CloneModel(GameObject originalModel)
```

**Parameters**

| Parameter       | Type       | Description                |
| --------------- | ---------- | -------------------------- |
| `originalModel` | GameObject | The original model to copy |

**Returns**

* `GameObject`: A new copy of the model with all generation data preserved

**Example**

```csharp
// Clone an existing MeshifAI model
GameObject original = /* a MeshifAI-generated model */;
GameObject copy = Meshifai.CloneModel(original);
```

### <kbd>ModelGenerationData Component</kbd>

Each generated model has a `ModelGenerationData` component attached that contains information about how it was created.

#### Properties

| Property         | Type     | Description                                        |
| ---------------- | -------- | -------------------------------------------------- |
| `Prompt`         | string   | The text description used to generate the model    |
| `highRes`        | bool     | Controls the output quality of the genereted model |
| `GenerationTime` | DateTime | When the model was generated                       |

#### `Example`

```csharp
// Accessing generation data
ModelGenerationData data = model.GetComponent<ModelGenerationData>();
Debug.Log($"Generated from prompt: {data.Prompt}");
Debug.Log($"High resolution: {data.HighRes}");
Debug.Log($"At time: {data.GenerationTime}");
```

{% hint style="info" %}
Need Support? Feel free to reach out to us over `hello@0xretro.dev` or twitter on `@0xretrodev`
{% endhint %}
