您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

快速入门:转换用于渲染的模型Quickstart: Convert a model for rendering

快速入门:使用 Unity 渲染模型中,你已了解如何使用 Unity 示例项目来渲染某个内置模型。In Quickstart: Render a model with Unity, you learned how to use the Unity sample project to render a built-in model. 本指南介绍如何转换你自己的模型。This guide shows how to convert your own models.

将了解如何执行以下操作:You'll learn how to:

  • 设置用于输入和输出的 Azure Blob 存储帐户Set up an Azure blob storage account for input and output
  • 上传并转换一个用于 Azure 远程渲染的 3D 模型Upload and convert a 3D model for use with Azure Remote Rendering
  • 在应用程序中包含要渲染的已转换 3D 模型Include the converted 3D model in an application for rendering

先决条件Prerequisites

概述Overview

服务器上的渲染器无法直接处理 FBX 或 GLTF 等源模型格式。The renderer on the server can't work directly with source model formats such as FBX or GLTF. 它要求模型采用专属的二进制格式。Instead, it requires the model to be in a proprietary binary format. 转换服务将使用 Azure Blob 存储中的模型,并将转换后的模型写回到所提供的 Azure Blob 存储容器。The conversion service consumes models from Azure blob storage and writes converted models back to a provided Azure blob storage container.

需要:You need:

  • Azure 订阅An Azure subscription
  • 订阅中的“StorageV2”帐户A 'StorageV2' account in your subscription
  • 输入模型的 Blob 存储容器A blob storage container for your input model
  • 输出数据的 Blob 存储容器A blob storage container for your output data
  • 要转换的模型,具体请参阅示例模型A model to convert, see sample models
    • 查看支持的源格式列表See the list of supported source formats
    • 要使用示例转换脚本,请确保准备好一个包含模型和所有外部依赖项(例如外部纹理或几何结构)的输入文件夹To use the sample conversion script, make sure you prepare an input folder that contains the model and all external dependencies (like external textures or geometry)

Azure 设置Azure setup

如果你没有 Azure 帐户,请转到 https://azure.microsoft.com/get-started/,单击“免费帐户”选项,然后按照说明创建一个帐户。If you do not have an account yet, go to https://azure.microsoft.com/get-started/, click on the free account option, and follow the instructions.

有了 Azure 帐户后,请转到 https://ms.portal.azure.com/#homeOnce you have an Azure account, go to https://ms.portal.azure.com/#home.

创建存储帐户Storage account creation

若要创建 Blob 存储,首先需要一个存储帐户。To create blob storage, you first need a storage account. 若要创建一个存储帐户,请单击“创建资源”按钮:To create one, click on the "Create a resource" button:

Azure - 添加资源

在新屏幕中,选择左侧的“存储”,然后在下一列中选择“存储帐户 - Blob、文件、表、队列”: From the new screen, choose Storage on the left side and then Storage account - blob, file, table, queue from the next column:

Azure - 添加存储

单击此按钮会显示以下屏幕,其中包含要填写的存储属性:Clicking this button will bring up the following screen with storage properties to fill out:

Azure 设置

按如下方式填写表单:Fill out the form in the following manner:

  • 通过下拉框下方的链接创建一个新的资源组,并将其 命名为 ARR_TutorialCreate a new Resource Group from the link below the drop-down box and name this ARR_Tutorial
  • 对于“存储帐户名称”,请输入唯一名称。For the Storage account name, enter a unique name here. 此名称必须全局唯一,否则会出现一条提示,告知该名称已被使用。This name must be globally unique, otherwise there will be a prompt that informs you that the name is already taken. 对于本快速入门,我们将存储帐户命名为 arrtutorialstorage。In the scope of this quickstart, we name it arrtutorialstorage. 如果你在本快速入门中使用了其他名称,则需要相应地将上述名称替换为自己的名称。Accordingly, you need to replace it with your name for any occurrence in this quickstart.
  • 选择靠近自己的位置。Select a location close to you. 最好是使用在其他快速入门中设置渲染时所用的同一位置。Ideally use the same location as used for setting up the rendering in the other quickstart.
  • 将“性能”设为“标准”Performance set to 'Standard'
  • 将“帐户类型”设为“StorageV2 (常规用途 v2)”Account kind set to 'StorageV2 (general purpose v2)'
  • 将“复制”设为“读取访问权限异地冗余存储(RA-GRS)”Replication set to 'Read-access geo-redundant storage (RA-GRS)'
  • 将“访问层”设为“热”Access tier set to 'Hot'

不必更改其他选项卡中的属性,因此可以继续选择“查看 + 创建”,然后按照相应的步骤完成设置。None of the properties in other tabs have to be changed, so you can proceed with "Review + create" and then follow the steps to complete the setup.

现在,网站会告知部署进度,并且最终会报告“部署已完成”。The website now informs you about the progress of your deployment and reports "Your deployment is complete" eventually. 单击“转到资源”按钮来完成后续步骤:Click on the "Go to resource" button for the next steps:

Azure 存储创建完成

创建 Blob 存储Blob storage creation

接下来,需要两个 Blob 容器,一个用于输入,一个用于输出。Next we need two blob containers, one for input and one for output.

按前面所述单击“转到资源”按钮后,会进入一个页面,其左侧显示了一个包含列表菜单的面板。From the "Go to resource" button above, you get to a page with a panel on the left that contains a list menu. 在该列表中的“Blob 服务”类别下,单击“容器”按钮: In that list under the "Blob service" category, click on the "Containers" button:

Azure - 添加容器

按“+ 容器”按钮创建输入 Blob 存储容器。 Press the "+ Container" button to create the input blob storage container. 创建该容器时,请使用以下设置:Use the following settings when creating it:

  • 名称 = arrinputName = arrinput
  • 公共访问级别 = 私有Public access level = Private

创建该容器后,再次单击“+ 容器”,并针对输出容器重复使用这些设置: After the container has been created, click + Container again and repeat with these settings for the output container:

  • 名称 = arroutputName = arroutput
  • 公共访问级别 = 私有Public access level = Private

现在应已有两个 Blob 存储容器:You should now have two blob storage containers:

Blob 存储设置

运行转换Run the conversion

可通过三种不同的方法来触发模型转换:There are three distinct ways to trigger a model conversion:

1.通过 ARRT 工具转换1. Conversion via the ARRT tool

可通过一个名为 ARRT 的基于 UI 的工具开始转换并与呈现的结果交互。There is a UI-based tool called ARRT to start conversions and interact with the rendered result. ARRTARRT

2.通过 PowerShell 脚本转换2. Conversion via a PowerShell script

为了便于调用资产转换服务,我们提供了一个实用工具脚本。To make it easier to call the asset conversion service, we provide a utility script. 该脚本位于 Scripts 文件夹中,其名称为 Conversion.ps1。It is located in the Scripts folder and is called Conversion.ps1.

具体而言,此脚本In particular, this script

  1. 将给定目录中的所有文件从本地磁盘上传到输入存储容器uploads all files in a given directory from local disk to the input storage container
  2. 调用资产转换 REST API,以便从输入存储容器中检索数据并启动转换,该转换会返回转换 IDcalls the the asset conversion REST API, which will retrieve the data from the input storage container and start a conversion, which will return a conversion ID
  3. 使用检索到的转换 ID 轮询转换状态 API,直到转换过程以成功或失败状态终止poll the conversion status API with the retrieved conversion ID until the conversion process terminates with success or failure
  4. 在输出存储中检索已转换资产的链接retrieves a link to the converted asset in the output storage

该脚本从 Scripts\arrconfig.json 文件中读取其配置。The script reads its configuration from the file Scripts\arrconfig.json. 在文本编辑器中打开该 JSON 文件。Open that JSON file in a text editor.

{
    "accountSettings": {
        "arrAccountId": "8*******-****-****-****-*********d7e",
        "arrAccountKey": "R***************************************l04=",
        "region": "<your-region>"
    },
    "renderingSessionSettings": {
        "vmSize": "standard",
        "maxLeaseTime": "1:00:00"
    },
    "assetConversionSettings": {
        "localAssetDirectoryPath": "D:\\tmp\\robot",
        "resourceGroup": "ARR_Tutorial",
        "storageAccountName": "arrexamplestorage",
        "blobInputContainerName": "arrinput",
        "inputFolderPath": "robotConversion",
        "inputAssetPath": "robot.fbx",
        "blobOutputContainerName": "arroutput",
        "outputFolderPath":"converted/robot",
        "outputAssetFileName": "robot.arrAsset"
    }
}

应该以类似于使用 Unity 渲染模型快速入门中所述的凭据填写 accountSettings 组中的配置(帐户 ID 和密钥)。The configuration within the accountSettings group (account ID and key) should be filled out analogous to the credentials in the Render a model with Unity quickstart.

在 assetConversionSettings 组中,请确保按上面所示更改 resourceGroup、blobInputContainerName和 blobOutputContainerName。 Inside the assetConversionSettings group, make sure to change resourceGroup, blobInputContainerName, and blobOutputContainerName as seen above. 请注意,需将 arrtutorialstorage 的值替换为在创建存储帐户期间选取的唯一名称。Note that the value for arrtutorialstorage needs to be replaced with the unique name you picked during storage account creation.

将 localAssetDirectoryPath 更改为指向磁盘上包含要转换的模型的目录。Change localAssetDirectoryPath to point to the directory on your disk, which contains the model you intend to convert. 请小心使用双反斜杠(“\\”)来正确转义路径中的反斜杠(“\”)。Be careful to properly escape backslashes ("\") in the path using double backslashes ("\\").

localAssetDirectoryPath 指定的路径中的所有数据,将上传到 blobInputContainerName Blob 容器中由 inputFolderPath 指定的子路径下。 All data from the path given in localAssetDirectoryPath will be uploaded to the blobInputContainerName blob container under a subpath given by inputFolderPath. 因此,在上述示例配置中,“D:\tmp\robot”目录的内容将上传到存储帐户“arrtutorialstorage”的 Blob 容器“arrinput”中的路径“robotConversion”下。So in the example configuration above the content of the "D:\tmp\robot" directory will be uploaded to the blob container "arrinput" of the storage account "arrtutorialstorage" under the path "robotConversion". 已存在的文件将被覆盖。Already existing files will be overwritten.

将 inputAssetPath 更改为要转换的模型的路径 - 该路径是 localAssetDirectoryPath 的相对路径。Change inputAssetPath to the path of the model to be converted - the path is relative to localAssetDirectoryPath. 使用“/”而不是“\”作为路径分隔符。Use "/" instead of "\" as the path separator. 因此,对于直接位于“D:\tmp\robot”中的“robot.fbx”文件,请使用“robot.fbx”。So for a "robot.fbx" file, which is located directly in "D:\tmp\robot", use "robot.fbx".

转换模型后,它将写回到 blobOutputContainerName 指定的存储容器。Once the model was converted, it will be written back to the storage container given by blobOutputContainerName. 可通过提供可选的 outputFolderPath 来指定子路径。A subpath can be specified by providing the optional outputFolderPath. 在上述示例中,生成的“robot.arrAsset”将复制到输出 Blob 容器中的“converted/robot”下。In the example above, the resulting "robot.arrAsset" will be copied to the output blob container under "converted/robot".

配置设置“outputAssetFileName”决定了已转换资产的名称 - 此参数是可选项,如果不使用此参数,将从输入文件名推导输出文件名。The config setting outputAssetFileName determines the name of the converted asset - the parameter is optional and the output filename will be deduced from the input file name otherwise.

打开 PowerShell,并确保已根据先决条件中所述安装了 Azure PowerShell。Open a PowerShell, make sure you installed the Azure PowerShell as mentioned in the prerequisites. 然后,使用以下命令登录到订阅,并按照屏幕上的说明进行操作:Then log into your subscription with the following command and follow the on-screen directions:

Connect-AzAccount

备注

如果你的组织有多个订阅,你可能需要指定 SubscriptionId 和 Tenant 参数。In case your organization has more than one subscription you might need to specify the SubscriptionId and Tenant arguments. Connect-AzAccount 文档中可以找到详细信息。Find details in the Connect-AzAccount documentation.

切换到 azure-remote-rendering\Scripts 目录并运行转换脚本:Change to the azure-remote-rendering\Scripts directory and run the conversion script:

.\Conversion.ps1 -UseContainerSas

应看到与下面类似的内容:Conversion.ps1You should see something like this: Conversion.ps1

3.通过 API 调用转换3. Conversion via API calls

C# 和 C++ API 都提供了用于与服务进行交互的入口点:Both the C# and the C++ API provide an entry point to interact with the service:

向快速入门示例应用中插入新模型Insert new model into Quickstart Sample App

转换脚本将为转换后的模型生成共享访问签名 (SAS) URI。The conversion script generates a Shared Access Signature (SAS) URI for the converted model. 现在,可将此 URI 作为“模型名称”复制到快速入门示例应用(请参阅快速入门:使用 Unity 渲染模型)。You can now copy this URI as the Model Name into the quickstart sample app (see Quickstart: Render a model with Unity).

在 Unity 中替换模型

现在,该示例应会加载并渲染你的自定义模型!The sample should now load and render your custom model!

可选:重新创建 SAS URIOptional: Re-creating a SAS URI

转换脚本创建的 SAS URI 仅在 24 小时内有效。The SAS URI created by the conversion script will only be valid for 24 hours. 不过,在此 URI 过期之后,你不需要再次转换模型。However, after it expired you do not need to convert your model again. 而可以根据后续步骤中所述,在门户中创建新的 SAS:Instead, you can create a new SAS in the portal as described in the next steps:

  1. 转到 Azure 门户Go to the Azure portal
  2. 单击“存储帐户”资源:屏幕截图突出显示所选存储帐户资源。Click on your Storage account resource: Screenshot that highlights the selected Storage account resource.
  3. 在如下所示的屏幕中,单击左侧面板中的“存储资源管理器”,并在“arroutput”Blob 存储容器中找到你的输出模型(.arrAsset 文件)。 In the following screen, click on Storage explorer in the left panel and find your output model (.arrAsset file) in the arroutput blob storage container. 右键单击该文件,并从上下文菜单中选择“获取共享访问签名”:访问签名Right-click on the file and select Get Shared Access Signature from the context menu: Signature Access
  4. 此时会打开一个新屏幕,在其中可以选择过期日期。A new screen opens where you can select an expiry date. 按“创建”,并复制下一个对话框中显示的 URI。Press Create, and copy the URI that is shown in the next dialog. 这一新 URI 将替换脚本创建的临时 URI。This new URI replaces the temporary URI that the script created.

后续步骤Next steps

了解基础知识后,接下来请查看我们的教程获得更深入的知识。Now that you know the basics, have a look at our tutorials to gain more in-depth knowledge.

若要了解有关模型转换的详细信息,请查看模型转换 REST APIIf you want to learn the details of model conversion, check out the model conversion REST API.