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

    0
    48


    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 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 strategy will present updated 3D fashions and improved scene load instances 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, a typical 3D picture format that may be exported and opened by numerous 3D picture enhancing packages.
    • MTL – Materials library file, accommodates 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 considered one of two potential file extensions: .gltf or .glb
    • 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 belongings 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 purposes. The glTF format minimizes the scale of 3D belongings 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, resembling 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 resembling Cesium obj2gltf.

    Within the structure under, you will note 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 might include 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 probably 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 inside the OBJ mannequin. The xyz file won’t 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 resembling 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 pictures previous to changing to glTF. Consequently, the conversion will produce a a lot smaller GLB or glTF file as seen on this AWS IoT TwinMaker Scene under. Be aware, a glTF file makes use of considered one of two potential file extensions: .gltf or .glb. GLB might be used on this weblog as this can be a binary format versus JSON leading to a smaller mannequin file.

    Instance Matterport Scan in AWS IoT TwinMaker

    Stipulations

    An AWS account might be required to setup and execute the steps on this weblog. An AWS Cloudformation template will configure and set up the required AWS Lambda Operate, IAM roles, and Amazon S3 bucket. It is suggested that you just work within the Virginia area (us-east-1). Chances are you’ll incur value on a number of the following providers:

    • 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, resembling Pro2. This obtainable checklist of bundles might 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 pictures
      – Convert OBJ information to GLB
      – Add GLB 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. Go away 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 may host your mannequin information. This might be created for you. Remember to choose a reputation that’s globally distinctive as it can 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 beneath the Assets 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. Remember to preserve it zipped because the Lambda perform will unzip it throughout processing. The conversion course of will start routinely and will take a couple of minutes.
    11. If the mannequin is transformed efficiently, you will note a GLB file within the root of the S3 Bucket. If not, test Amazon CloudWatch for any logs from the Lambda perform.

    Add Mannequin to Scene (Optionally available)

    To recap, you’ve gotten efficiently compressed and transformed an almost 180MB level cloud scan by Matterport to a 18MB GLB file. With the mannequin transformed, you possibly can 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 should be recreated utilizing IoT TwinMaker Tags within the Scene composer.

    1. In your IoT TwinMaker Workspace, add the GLB mannequin within the Assets part. In case 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. In case you want steering on this course of, the documentation is accessible right here. Don’t neglect to set environmental lighting because the mannequin will seem all black.

    Clear Up

    Remember to clear up the work on this weblog to keep away from costs. Delete the next sources when completed on this order

    1. Delete the article information 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 contains generic conversion of OBJ from different programs as properly. With this pipeline, it is possible for you to to cut back Scene load instances 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 belongings to glTF to be used with AWS IoT TwinMaker

    Concerning the writer

    Chris Azer is a Senior IoT Specialist Architect serving to clients with their digital twin initiatives. Chris has labored in numerous roles at AWS since 2017 supporting companions and clients with architecting IoT options. This features a broad set of use circumstances protecting 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 right this moment with their sensible manufacturing journey.

     

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here