> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/how-vision-works.md).

# 视觉的工作原理

了解 Unreal 视觉组件如何被发现、启动、限流，以及如何在 Convai 会话期间用于发送场景帧。

视觉功能会将场景图像添加到 Convai 对话中。角色上的帧源组件会捕获关卡画面，而 **Convai 聊天机器人** 组件会在会话处于活动状态时将这些帧发送到 Convai。

### 运行时的工作方式

内置流程包含三个部分：

1. **帧源** — **环境摄像头** (`UEnvironmentWebcam`) 通过 `USceneCaptureComponent2D` 捕获场景，并将画面写入 `UTextureRenderTarget2D`.
2. **视觉接口约定** — `IConvaiVisionInterface` 定义了聊天机器人对任意帧源所要求的方法。
3. **聊天机器人发送组件** — `UConvaiChatbotComponent` 会在同一个 `Actor`上查找帧源，按配置的频率读取帧，并通过当前活动会话发送。

```mermaid
flowchart LR
    subgraph frameSourceLayer["帧源"]
        environmentWebcam["UEnvironmentWebcam"]
    end

    visionInterface["IConvaiVisionInterface"]
    chatbot["UConvaiChatbotComponent"]
    sendImage["SendImage"]
    sessionProxy["UConvaiConnectionSessionProxy"]
    convai["Convai"]

    environmentWebcam -->|"实现"| visionInterface
    visionInterface --> chatbot
    chatbot --> sendImage
    sendImage --> sessionProxy
    sessionProxy --> convai
```

视觉功能附加在 **聊天机器人角色**上，而不是玩家 Pawn 上。玩家组件负责启动对话；聊天机器人组件负责查找并上传帧。

### 关键概念

| 概念        | 含义                                                                |
| --------- | ----------------------------------------------------------------- |
| **帧源**    | 聊天机器人 `Actor` 上的一个组件，实现了 `IConvaiVisionInterface` 并提供图像数据。        |
| **环境摄像头** | 随附的帧源。它会通过场景捕获将画面写入渲染目标。它不是实体设备摄像头。                               |
| **渲染目标**  | 分配给 `UTextureRenderTarget2D` 的是 **Convai 渲染目标**。捕获组件会将场景像素写入此资源。  |
| **视觉状态**  | `EVisionState` 用于跟踪捕获是否处于活动状态。已发布的实现仅设置 `Stopped` 和 `Capturing` 。 |
| **帧速率限制** | 聊天机器人根据源组件的 **最大 FPS** (`m_MaxFPS`) 发送帧，上传期间会限制在 `1`–`60` 之间。     |
| **视频连接**  | 会话设置会在支持视觉功能或项目设置中启用 `video` 作为连接类型 `AlwaysAllowVision` 时使用。      |

### 组件发现

在 `BeginPlay`, `UConvaiChatbotComponent` 会搜索所属 `Actor` 中实现了 `UConvaiVisionInterface` 的组件，并注册第一个匹配项。

* **设置视觉组件** 如果同一个 `Actor`.
* **上存在多个帧源，此设置会替换自动发现的源。** 返回 `true` 表示已注册有效源。如果尚未注册，聊天机器人会先搜索一次 `Actor` ，然后再返回。
* 将普通的 `USceneCaptureComponent2D` 传递给 **设置视觉组件** 会返回 `false`。该捕获组件不是 Convai 帧源。

`Set Vision Component` 和 **Supports Vision** 由 `UConvaiPlayerComponent`继承，但它们在此处返回 `false` ，因为只有 `UConvaiChatbotComponent` 会启用视觉注册。请在聊天机器人组件上使用这些节点。

### 捕获并上传

当 **Environment Webcam** 处于 `Capturing` 状态时：

1. 其内部的 `USceneCaptureComponent2D` 会将场景渲染到 **Convai Render Target**.
2. 每次聊天机器人 tick 都会累积时间，直到达到 `GetMaxFPS()` 所对应的间隔。
3. 聊天机器人会在活动源上调用 `CaptureRaw()` ，并通过 `SendImage`.
4. 将 RGBA 字节发送出去。Convai 会通过活动视频连接接收这些帧。

默认发送间隔为 `1.0f / 15.f`。如果 `GetMaxFPS()` 返回 `0` 或返回无效值，聊天机器人会使用 `15` FPS 作为上传计时的回退值。

### 视觉状态和事件

`EVisionState` 包含 `Stopped`, `Starting`, `Capturing`, `Stopping`和 `Paused`。在当前发布的实现中， **Environment Webcam** 只会在 `Stopped` 和 `Capturing`.

蓝图用户可以绑定 **帧就绪时** 在帧源上。当组件处于 `Capturing` 状态且该事件至少绑定了一个处理程序时，它会在每个 tick 期间广播。

C++ 集成也可以使用 `FOnVisionStateChanged`, `FOnFirstFrameCaptured`和 `FOnFramesStopped` （位于 `IConvaiVisionInterface`中）。这些委托无法在 Blueprint 中赋值。

### 延迟设置视觉功能

常规的 Blueprint 设置会在 **环境摄像头** 放到聊天机器人 `Actor` 上，且在 `BeginPlay`之前完成。在这种情况下， **支持视觉功能** 就足以让会话设置选择 `video` 连接。

仅当项目在初始连接设置之后注册或替换视觉组件时，才在 `AlwaysAllowVision` 中启用 **Edit > Project Settings > Plugins > Convai** （高级类别）。

### 后续步骤

{% content-ref url="/pages/ffb5a5d9ba2394107ce64c0b07938a181186f763" %}
[视觉快速开始](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-quick-start.md)
{% endcontent-ref %}

{% content-ref url="/pages/a5aa237a7b13fb2c8d46ff004c1de14a2c4cda2a" %}
[视觉帧源](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-frame-sources.md)
{% endcontent-ref %}

{% content-ref url="/pages/ec5b9bfb145ddc8145050976e8e8db28d33fc076" %}
[视觉 Blueprint 参考](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-blueprint-reference.md)
{% endcontent-ref %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/how-vision-works.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
