ibms-dome/Backend/Controllers/ModelDerivativeController.cs

58 lines
1.9 KiB
C#
Raw Permalink Normal View History

2022-11-28 23:18:13 +08:00
using Autodesk.Forge;
using Autodesk.Forge.Model;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
2022-11-28 23:18:13 +08:00
using System.Collections.Generic;
using System.Threading.Tasks;
namespace forgeSample.Controllers
{
[ApiController]
public class ModelDerivativeController : ControllerBase
{
private static IConfiguration _configuration;
public ModelDerivativeController(IConfiguration configuration) { _configuration = configuration; }
2022-11-28 23:18:13 +08:00
/// <summary>
/// Start the translation job for a give bucketKey/objectName
/// </summary>
/// <param name="objModel"></param>
/// <returns></returns>
[HttpPost]
[Route("api/forge/modelderivative/jobs")]
public async Task<dynamic> TranslateObject([FromBody] TranslateObjectModel objModel)
{
dynamic oauth = await OAuthController.GetInternalAsync(_configuration);
2022-11-28 23:18:13 +08:00
// prepare the payload
List<JobPayloadItem> outputs = new List<JobPayloadItem>()
{
new JobPayloadItem(
JobPayloadItem.TypeEnum.Svf,
new List<JobPayloadItem.ViewsEnum>()
{
JobPayloadItem.ViewsEnum._2d,
JobPayloadItem.ViewsEnum._3d
})
};
JobPayload job;
job = new JobPayload(new JobPayloadInput(objModel.objectName), new JobPayloadOutput(outputs));
// start the translation
DerivativesApi derivative = new DerivativesApi();
derivative.Configuration.AccessToken = oauth.access_token;
dynamic jobPosted = await derivative.TranslateAsync(job);
return jobPosted;
}
/// <summary>
/// Model for TranslateObject method
/// </summary>
public class TranslateObjectModel
{
public string bucketKey { get; set; }
public string objectName { get; set; }
}
}
}