Saturday, July 2, 2022
HomeTechnologyHow to convert CAD assets to glTF for use with AWS IoT...

How to convert CAD assets to glTF for use with AWS IoT TwinMaker


Customers often have existing 3D CAD (Computer-aided Design) assets that they would like to use with AWS IoT TwinMaker. CAD files are either proprietary formats optimized for use in proprietary applications or interchange formats designed for moving CAD data from one application to another. They are not usually compatible with realtime WebGL viewports like those used in AWS IoT TwinMaker, which supports the glTF format. Customers will need to convert their CAD assets to the glTF format before importing those assets to AWS IoT TwinMaker.

In this post, I will demonstrate a workflow for using Pixyz Scenario Processor to convert a CAD file in the STEP format to a realtime 3D file in the glTF format. Pixyz Scenario Processor is a solution provided by Pixyz that is available in AWS Marketplace. It can be configured for several different scenarios. In this example, I will be using the GenericPolygonTarget scenario. This scenario uses the most common settings for converting CAD assets to realtime assets for use in game engines and WebGL views. It has options for setting the desired polygon count, determining if objects should be merged together, and determining if hidden objects should be deleted.

Overview of solution

In this walkthrough, you will setup Amazon Elastic Container Service (ECS) to run the Pixyz Scenario Processor on a file stored in Amazon Simple Storage Service (Amazon S3).

You will create an Amazon S3 bucket and upload your CAD file for conversion. You will also create and run an AWS Fargate Task that uses the Pixyz Scenario Composer container image to convert the CAD file to glTF. After running the task, you will download the resulting file from Amazon S3 to inspect it in a glTF compatible viewer.

Walkthrough

In this walkthrough I will demonstrate the creation of an AWS Fargate Task that will grab a CAD file from an S3 bucket, convert it to a GLB (binary glTF format) file and store it back in that S3 bucket. The Fargate Task will use the Pixyz Scenario Processor from the AWS Marketplace. This requires adjusting the default IAM policy for running tasks on Amazon ECS to allow for metering usage of the AWS Marketplace solution.

We will run through the following steps:

  1. Upload the source files to an S3 Bucket
  2. Create an IAM Role for running Amazon ECS Tasks with the Pixyz Scenario Processor
  3. Create the Network Only Cluster
  4. Create the Task Definition
  5. Run the Fargate Task
  6. Examine the Logs
  7. (Optional) Download the glTF file and view it

Prerequisites

For this walkthrough, the following are prerequisites:

  • An AWS account
  • Amazon S3 to store your CAD file
  • AWS IAM
  • Amazon ECS and AWS Fargate
  • A subscription to Pixyz Scenario Processor on AWS Marketplace.
    • For this example, you will be charged for using Pixyz Scenario Processor with usage based pricing. Current pricing information is available on the AWS Marketplace product page for Pixyz Scenario Processor. Estimated cost of completing this exercise is $0.25 – $1.00.
  • A CAD file to convert. I will be using the file, Waste_Container.step, but you can use your own visual assets.
Image of the asset Waste_Container.step, a large green metal waste container.

Rendering of Waste_Container.step

Step 1: Upload the source files to an S3 Bucket

  1. Navigate to the Amazon S3 Console.
  2. Create a new bucket to use. I will be using the us-west-2 region for this example.
    My bucket name is: pixyz-example-20211117.
  3. Create an input and an output folder inside the bucket.
  4. Upload the CAD file you want to convert into the input folder.
    I am using a STEP file: Waste_Container.step.
Screenshot of AWS S3 Console page

Waste_Container.step uploaded to Amazon S3

Step 2: Create an IAM Role for running Amazon ECS Tasks with the Pixyz Scenario Processor

  1. Navigate to the AWS IAM Console Page.
  2. Choose the Roles section and press the Create Role button.
  3. Select Elastic Container Service, then Elastic Container Service Task, then select the Next:Permissions button.
  4. Attach the following Permissions:
    1. AWSMarketplaceMeteringRegisterUsage (allows AWS Marketplace to Meter usage)
    2. AmazonS3FullAccess (allows Amazon ECS to access the S3 bucket)
    3. AmazonECSTaskExecutionPolicy (allows Amazon ECS to execute Tasks)
  5. Select the Next:Tags button.
  6. Select the Next:Review button.
  7. Name the role, I used pixyz-example-role-20211117.
  8. Add a description, I used “Role created for Pixyz Scenario Processor example.” Select the Create role button.

You should now have a role that looks similar to:

Screenshot of the AWS IAM Console

Permissions policies applied to IAM Role pixyz-example-role-20211117

Step 3: Create the Network Only Cluster

  1. Navigate to the Amazon ECS console.
  2. Navigate to the Clusters section and select the button to Create Cluster.
  3. Select Networking Only and then the Next step button.
  4. Configure the Cluster with:
    1. name: pixyz-example-cluster
    2. Enable Create a new VPC for this cluster.
    3. Use default CIDR and subnet blocks.
    4. Enable Cloudwatch Container Insights.
  5. Select the Create button.

Step 4: Create the Task Definition

  1. Navigate to the Amazon ECS console.
  2. Navigate to the Task Definition section and select the button to Create new Task Definition.
  3. Choose the Fargate option and select the Next step button.
  4. Configure the Task:
    1. Give it a name, I used: pixyz-example-task
    2. For Task role, use the IAM role you created above: pixyz-example-role-20211117
    3. Operating system family: Linux.
    4. For Task Execution role, again, use the IAM role you created: pixyz-example-role-20211117
    5. Task Memory: 4 GB
    6. Task CPU (vCPU): 1 vCPU
    7. Create a container with the Add container button and configure with:
      1. name: pixyz-example-container
      2. image url: 709825985650.dkr.ecr.us-east-1.amazonaws.com/pixyz-software/scenario-processor:2021.1.0.79
      3. remove port-mappings
      4. Environment Command:
        GenericPolygonTarget,s3File_with_arguments,"pixyz-example-20211117","us-west-2","input/Waste_Container.step",False,"pixyz-example-20211117","us-west-2","output/Waste_Container.glb",10000,False,False,False

        The command template provided in the Pixyz Scenario Processor Quick-Start is:

        GenericPolygonTarget,s3File_with_arguments,"my-input-bucket-name", "my-input-bucket-region", "input/inputFile.step",False,"my-output-bucket-name","my-output-bucket-region","outputFolder/resultFile.xxx",10000,False,False,False

        In our version we’ve replaced:
        my-input-bucket-name with pixyz-example-20211117
        my-input-bucket-region with us-west-2
        input/inputFile.step with input/Waste_Container.step
        my-output-bucket-name with pixyz-example-20211117
        my-output-bucket-region with us-west-2
        outputFolder/resultFile.xxx with output/Waste_Container.glb

Step 5: Run the Fargate Task

  1. Navigate to the Amazon ECS console.
  2. Navigate to the Task Definition section.
  3. Select the Task Definition and from the Actions button select Run Task.
  4. Configure the Run Task with:
    1. Launch Type: Fargate
    2. Operating System Family: Linux
    3. Cluster: pixyz-example-cluster
    4. Add the both of the available Subnets to the Cluster VPC.
  5. Press the Run Task button to run the task.

Step 6: Examine the Logs

You can use the Amazon CloudWatch Console to watch the Fargate task in progress. As the Pixyz Scenario Processor runs it outputs logs to a CloudWatch Log Group.

  1. Navigate to the Amazon CloudWatch Console.
  2. Navigate to the Log Groups section and choose the ecs/pixzy-example-task log group.
  3. Select the Log Stream that will look similar to ecs/pixyz-example-container
  4. Read through the logs generated by the task.

Common errors are:

  1. Register error: AccessDenied Exception. The IAM role used does not have the appropriate policies. The task is using an autogenerated ecsTaskExecutionRole instead of the IAM role we created above. You’ll need to update the Task Definition with the correct role.
  2. Bucket Not Found. There is a typo in the Environment Command where the buckets and files defined in the command string do not exist. You’ll need to update the Task Definition with the correct bucket names an input and output folder/filenames.

Step 7: (Optional) Download the glTF file and view it

  1. Navigate to the Amazon S3 Console.
  2. Navigate to the bucket pixyz-example-20211117 and folder output.
  3. Select the file generated by the task, for me this is Waste_Container.glb, and press the Download button.

To view glTF and GLB files on my local computer, I use Visual Studio Code with the glTF Tools extension.

Screenshot of Waste_Container.glb viewed in Visual Studio Code

Waste_Container.glb rendered in Visual Studio Code.

Cleaning up

To avoid incurring ongoing storage charges for objects in Amazon S3 or logs in Amazon CloudWatch, you should delete the resources created in this walkthrough. You should also remove the IAM role, AWS Fargate Task Definition and Cluster. Finally, unsubscribe from the Pixyz Scenario Processor to finish cleaning up from this walkthrough.

Remove the S3 bucket, folders, and files

  1. Navigate to the Amazon S3 Console and the bucket, pixyz-example-20211117.
  2. Delete the S3 objects input/Waste_Container.step and output/WasteContainer.glb.
  3. Delete the folders input and output.
  4. Delete the S3 bucket, pixyz-example-20211117.

Remove the IAM role

  1. Navigate to the AWS IAM Console.
  2. Choose the Roles section and delete pixyz-example-role-20211117.

Remove the AWS Fargate Task Definition and Cluster

  1. Navigate to the Amazon ECS console.
  2. In the Task Definitions section, use the Actions button to de-register the Task, pixyz-example-task.
  3. In the Clusters section, use the Delete Cluster button to delete your cluster, pixyz-example-cluster.

Remove the Logs from Amazon CloudWatch

  1. Navigate to the Amazon CloudWatch Console.
  2. In the Log Groups section, use the Actions button to Delete log group(s), ecs/pixzy-example-task.

Unsubscribe from the Pixyz Scenario Processor subscription

  1. Navigate to the AWS Marketplace Console.
  2. Select the Pixyz Scenario Processor and use the Actions button to Cancel subscriptions.

Conclusion

In this walkthrough you used the Pixyz Scenario Processor to convert a CAD asset to a glTF file that is ready to use with AWS IoT TwinMaker. You can modify the AWS Fargate Task to convert any other CAD files you would like to use with AWS IoT TwinMaker.

Now that you have a glTF asset, you can use it with AWS IoT TwinMaker to create digital twins of real-world systems to optimize operations.

About the author

Jeremiah Habets is a Sr. Spatial Consultant with Amazon Web Services (AWS) Professional Services. Jeremiah helps customers solve problems in AR/VR, Simulation, Visualizations using realtime 3D technology.

 

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments