Making an attempt to get began with AWS IoT TwinMaker and have to convert your OBJ file to glTF? Maybe you’ve gotten carried out some extent 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 strategy will present updated 3D fashions and improved scene load occasions in AWS IoT TwinMaker.
Overview
On this weblog submit, a number of file extensions and mannequin codecs are referenced. Earlier than getting began, it’s good to grasp the next:
- OBJ – Object file, a typical 3D picture format that may be exported and opened by varied 3D picture enhancing packages.
- 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, a typical file format for three-dimensional scenes and fashions. A glTF file makes use of one in every of two attainable 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 dimensions of 3D content material. It compresses vertex positions, normals, colours, texture coordinates, and every other generic vertex attributes, enhancing the effectivity and velocity of transmitting 3D content material over the online.
- 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 info in JSON format or binary and allows environment friendly transmission and loading of 3D fashions in functions. The glTF format minimizes the dimensions of 3D property and the runtime processing wanted to unpack and use them. The 3D fashions from conventional CAD functions, in addition to level cloud scans, might be transformed to glTF utilizing AWS Associate options, similar to these from Pixyz. On this weblog, you’ll discover an alternate server-less strategy 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 note how AWS Lambda can be utilized to detect a Matterpak zip bundle uploaded to an Amazon S3 bucket. This may set off the conversion to glTF inside an extended working Lambda execution. The zipped file might comprise OBJ, MTL, and JPG information.
Inside a Matterpak bundle, there are a number of information together with an OBJ, MTL, level cloud scan (xyz), and presumably many JPG information. Matterport on this instance has transformed the purpose cloud scan to an object mesh format, OBJ. The MTL and JPG information collectively offers coloured texturing over the objects throughout 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 similar 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 giant. To enhance this, the Lambda operate on this weblog will first compress all JPG photos previous to changing to glTF. As well as, this mannequin shall be compressed even additional through the use of Draco Compression. In consequence, 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 every of two attainable file extensions: .gltf or .glb. The glTF extension shall be used on this weblog.
Instance Matterport Scan in AWS IoT TwinMaker
Conditions
An AWS account shall be required to setup and execute the steps on this weblog. An AWS Cloudformation template will configure and set up the required AWS Lambda Perform, IAM roles, and Amazon S3 bucket. It is suggested that you simply work within the Virginia area (us-east-1). You might incur value on among the following companies:
- Amazon Easy Storage Service (S3) Storage prices
- AWS Lambda Mannequin Convert Perform
Steps
Obtain Matterpak Pattern Bundle
Obtain one of many Matterpak Bundles. Choose one of many bundles, similar to Pro2. This out there checklist of bundles might change. The approximate file measurement for the Pro2 pattern bundle is 178MB.
Set up Mannequin Convert Lambda Perform
- Obtain the pattern Lambda Mannequin Convert deployment bundle. The operate code inside this bundle will carry out the next:
– Obtain Matterpak bundle from S3
– Extract to the Lambda /tmp listing
– Compress all JPG photos
– Convert OBJ information to glTF
– Convert glTF to Draco glTF
– Add Draco glTF mannequin again to the S3 Bucket. - Log into the Amazon S3 console
- Create an S3 bucket or select an present one the place you’ll add the Lambda operate you downloaded. Go away the file zipped as is.
- As soon as the Lambda operate has been positioned in S3, launch this CloudFormation template
- Change the LambdaArtifactBucketName parameter worth to the title of the bucket you uploaded the Lambda operate to
- Change the S3BucketName parameter worth to the title of a brand new bucket that may host your mannequin information. This shall be created for you. You should definitely choose a reputation that’s globally distinctive as it’ll fail throughout the creation of the stack in any other case.
- Click on on Create Stack to arrange the mannequin conversion pipeline
- As soon as full, navigate to the brand new S3 bucket. A hyperlink might be discovered beneath the Sources tab
- Create a folder on this bucket and title it paks
- Add the Matterpak bundle that was downloaded in step 1 to the paks folder. You should definitely hold it zipped because the Lambda operate will unzip it throughout processing. The conversion course of will start routinely and should take a couple of minutes.
- If the mannequin is transformed efficiently, you will note a glTF file within the root of the S3 Bucket. If not, verify Amazon CloudWatch for any logs from the Lambda operate.
Add Mannequin to Scene (Optionally available)
To recap, you’ve gotten efficiently compressed and transformed a virtually 180MB level cloud scan by Matterport to an 8MB glTF file. With the mannequin transformed, you may attempt to load this in your IoT TwinMaker workspace. Be aware that any Mattertags you’ve gotten created in Matterport usually are not transferrable on this course of. This should be recreated utilizing IoT TwinMaker Tags within the Scene composer.
- In your IoT TwinMaker Workspace, add the glTF mannequin within the Sources part. If you happen to haven’t already created a workspace, please comply with the steps at Getting Began with AWS IoT TwinMaker.
- Add this mannequin to your scene or create one if it doesn’t exist already. If you happen to want steerage on this course of, the documentation is offered right here. Don’t overlook to set environmental lighting because the mannequin will seem all black.
Clear Up
You should definitely clear up the work on this weblog to keep away from fees. Delete the next sources when completed on this order
- Delete the article information within the Lambda and Mannequin S3 Buckets. Be aware, this isn’t the IoT TwinMaker Workspace bucket however fairly the buckets created for this weblog
- Delete the CloudFormation Stack
- 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 contains generic conversion of OBJ from different methods as properly. With this pipeline, it is possible for you to to cut back Scene load occasions and streamline 3D mannequin updates on to your IoT TwinMaker workspace.
Listed below are different mannequin conversion blogs out there, with extra to return:
– Find out how to convert CAD property to glTF to be used with AWS IoT TwinMaker
Updates
- 9/1/2022: Added Draco Compression to cut back mannequin measurement
In regards to the creator
Chris Azer is a Senior IoT Specialist Architect serving to prospects with their digital twin initiatives. Chris has labored in varied roles at AWS since 2017 supporting companions and prospects with architecting IoT options. This features a broad set of use circumstances overlaying the DoD, Manufacturing, State and Native Authorities, Federal and Civilian, Sensible Cities, Companions, and others. His profession in Industrial Automation dates again to 2004 the place he continues to help enterprises immediately with their good manufacturing journey. |