Friday, September 30, 2022
HomeIoTLearn how to convert and compress OBJ fashions to GLTF to be...

Learn how to convert and compress OBJ fashions to GLTF to be used with AWS IoT TwinMaker


Attempting to get began with AWS IoT TwinMaker and must convert your OBJ file to glTF? Maybe you’ve gotten carried out a degree cloud scan of your surroundings with Matterport and it’s not clear how one can import the Matterpak bundle into AWS IoT TwinMaker. On this weblog, you’ll apply a mannequin conversion pipeline to compress and convert a Matterpak bundle into glTF format. This method will present updated 3D fashions and improved scene load occasions in AWS IoT TwinMaker.

Overview

On this weblog publish, a number of file extensions and mannequin codecs are referenced. Earlier than getting began, it’s good to grasp the next:

  • OBJ – Object file, an ordinary 3D picture format that may be exported and opened by numerous 3D picture modifying applications.
  • MTL – Materials library file, incorporates a number of materials definitions, every of which incorporates the colour, texture, and reflection map of particular person supplies for objects in an OBJ mannequin
  • glTF – Graphics Language Transmission Format, an ordinary file format for three-dimensional scenes and fashions. A glTF file makes use of one in all two doable file extensions: .gltf or .glb
  • Draco Compression – A glTF extension for mesh compression. This Cesium library will compress and decompress 3D meshes to considerably scale back the scale of 3D content material. It compresses vertex positions, normals, colours, texture coordinates, and some other generic vertex attributes, enhancing the effectivity and velocity of transmitting 3D content material over the net.
  • Level Cloud Scans – A big assortment of particular person factors (x, y, z coordinates) inside a 3D house, captured utilizing a 3D laser scanner and saved in ASCII (.xyz) or binary format.

AWS IoT TwinMaker helps 3D property within the glTF format, which is a 3D file format that shops 3D mannequin data in JSON format or binary and permits environment friendly transmission and loading of 3D fashions in purposes. The glTF format minimizes the scale of 3D property and the runtime processing wanted to unpack and use them. The 3D fashions from conventional CAD purposes, in addition to level cloud scans, may be transformed to glTF utilizing AWS Accomplice options, comparable to these from Pixyz. On this weblog, you’ll discover another server-less method to mannequin conversion of Matterpak bundles to glTF utilizing open supply libraries by Cesium, together with obj2gltf and gltf-pipeline.

Within the structure beneath, you will notice how AWS Lambda can be utilized to detect a Matterpak zip bundle uploaded to an Amazon S3 bucket. It will set off the conversion to glTF inside an extended working Lambda execution. The zipped file could comprise OBJ, MTL, and JPG recordsdata.

Inside a Matterpak bundle, there are a number of recordsdata together with an OBJ, MTL, level cloud scan (xyz), and probably many JPG recordsdata. Matterport on this instance has transformed the purpose cloud scan to an object mesh format, OBJ. The MTL and JPG recordsdata collectively supplies coloured texturing over the objects inside the OBJ mannequin. The xyz file is not going to be used on this conversion course of as this has already been transformed to OBJ within the Matterpak.

Mannequin Conversion Pipeline Structure

When working with level cloud scans comparable to Matterport, excessive decision JPG textures are captured all through the scan. Doing a easy conversion of the OBJ to glTF will nonetheless be fairly massive. To enhance this, the Lambda perform on this weblog will first compress all JPG photographs previous to changing to glTF. As well as, this mannequin can be compressed even additional through the use of Draco Compression. Consequently, the conversion will produce a a lot smaller glTF file as seen on this AWS IoT TwinMaker Scene beneath. Be aware, a glTF file makes use of one in all two doable file extensions: .gltf or .glb. The glTF extension can be used on this weblog.

Instance Matterport Scan in AWS IoT TwinMaker

Stipulations

An AWS account can be required to setup and execute the steps on this weblog. An AWS Cloudformation template will configure and set up the mandatory AWS Lambda Operate, IAM roles, and Amazon S3 bucket. It is suggested that you simply work within the Virginia area (us-east-1). It’s possible you’ll incur price on a few of the following companies:

  • Amazon Easy Storage Service (S3) Storage prices
  • AWS Lambda Mannequin Convert Operate

Steps

Obtain Matterpak Pattern Bundle

Obtain one of many Matterpak Bundles. Choose one of many bundles, comparable to Pro2. This obtainable record of bundles could change. The approximate file measurement for the Pro2 pattern bundle is 178MB.

Set up Mannequin Convert Lambda Operate

  1. Obtain the pattern Lambda Mannequin Convert deployment bundle. The perform code inside this bundle will carry out the next:
    – Obtain Matterpak bundle from S3
    – Extract to the Lambda /tmp listing
    – Compress all JPG photographs
    – Convert OBJ recordsdata to glTF
    – Convert glTF to Draco glTF
    – Add Draco glTF mannequin again to the S3 Bucket.
  2. Log into the Amazon S3 console
  3. Create an S3 bucket or select an present one the place you’ll add the Lambda perform you downloaded. Depart the file zipped as is.
  4. As soon as the Lambda perform has been positioned in S3, launch this CloudFormation template
  5. Change the LambdaArtifactBucketName parameter worth to the title of the bucket you uploaded the Lambda perform to
  6. Change the S3BucketName parameter worth to the title of a brand new bucket that can host your mannequin recordsdata. This can be created for you. Make sure you choose a reputation that’s globally distinctive as it is going to fail in the course of the creation of the stack in any other case.
  7. Click on on Create Stack to arrange the mannequin conversion pipeline
  8. As soon as full, navigate to the brand new S3 bucket. A hyperlink may be discovered underneath the Sources tab
  9. Create a folder on this bucket and title it paks
  10. Add the Matterpak bundle that was downloaded in step 1 to the paks folder. Make sure you preserve it zipped because the Lambda perform will unzip it throughout processing. The conversion course of will start robotically and should take a couple of minutes.
  11. If the mannequin is transformed efficiently, you will notice a glTF file within the root of the S3 Bucket. If not, examine Amazon CloudWatch for any logs from the Lambda perform.

Add Mannequin to Scene (Non-obligatory)

To recap, you’ve gotten efficiently compressed and transformed an almost 180MB level cloud scan by Matterport to an 8MB glTF file. With the mannequin transformed, you’ll be able to attempt to load this in your IoT TwinMaker workspace. Be aware that any Mattertags you’ve gotten created in Matterport aren’t transferrable on this course of. This have to be recreated utilizing IoT TwinMaker Tags within the Scene composer.

  1. In your IoT TwinMaker Workspace, add the glTF mannequin within the Sources part. When you haven’t already created a workspace, please observe the steps at Getting Began with AWS IoT TwinMaker.
  2. Add this mannequin to your scene or create one if it doesn’t exist already. When you want steerage on this course of, the documentation is out there right here. Don’t overlook to set environmental lighting because the mannequin will seem all black.

Clear Up

Make sure you clear up the work on this weblog to keep away from fees. Delete the next sources when completed on this order

  1. Delete the item recordsdata within the Lambda and Mannequin S3 Buckets. Be aware, this isn’t the IoT TwinMaker Workspace bucket however moderately the buckets created for this weblog
  2. Delete the CloudFormation Stack
  3. Delete the mannequin out of your TwinMaker workspace

Conclusion

On this weblog, you created a mannequin conversion pipeline to compress and convert a Matterpak bundle into glTF format.  This consists of generic conversion of OBJ from different programs as nicely. With this pipeline, it is possible for you to to scale back Scene load occasions and streamline 3D mannequin updates on to your IoT TwinMaker workspace.

Listed here are different mannequin conversion blogs obtainable, with extra to come back:
Learn how to convert CAD property to glTF to be used with AWS IoT TwinMaker

Updates

  • 9/1/2022: Added Draco Compression to scale back mannequin measurement

Concerning the writer

Chris Azer is a Senior IoT Specialist Architect serving to prospects with their digital twin initiatives. Chris has labored in numerous roles at AWS since 2017 supporting companions and prospects with architecting IoT options. This features a broad set of use circumstances masking the DoD, Manufacturing, State and Native Authorities, Federal and Civilian, Good Cities, Companions, and others. His profession in Industrial Automation dates again to 2004 the place he continues to help enterprises right now with their good manufacturing journey.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular