All Collections
APIs
Viewer and Data Integration example
Viewer and Data Integration example
F
Written by Faisal Ramady
Updated over a week ago

Utilising 3D Repo's APIs you can store and retrieve data from the database and apply it inside a custom web application. In this example we are going to look at the Lego House Federation project which comes with all new 3D Repo accounts.

Views

The "Lego_House_Federation" comes with 4 views by default:

We can query these via the data API using the Views - List All Views API request with the following variables:

  • teamspace - the name of the teamspace you model/federation has been upload to

  • model - the GUID of the model, available in the model viewer URL string

  • api key - your unique API key (Generate an API Key | 3D Repo Help Centre)

curl --location --request GET 'https://www.3drepo.io/api/{teamspace}/{model}/viewpoints?key={api key}'

Producing the following response:

[    {        "_id": "1e579e40-6ce5-11e9-b2c5-7f7dd1cfd775",        "viewpoint": {            "fov": 1.0471975803375244,            "right": [                0.2593497037887573,                0,                -0.9657834768295288            ],            "far": 35619.46875,            "look_at": [                6790.517578125,                4629.623046875,                -7234.9794921875            ],            "up": [                -0.03559441119432449,                0.9993206262588501,                -0.009558457881212234            ],            "clippingPlanes": [                {                    "distance": 14189.1953125,                    "clipDirection": -1,                    "normal": [                        -1,                        0,                        0                    ]                }            ],            "near": 71.23893737792969,            "view_dir": [                -0.9651273488998413,                -0.03685547783970833,                -0.25917351245880127            ],            "aspect_ratio": 0.816688597202301,            "position": [                24945.419921875,                5322.9072265625,                -2359.695068359375            ],            "highlighted_group_id": ""        },        "name": "Section view",        "thumbnail": "mosmentDemo/710b5cc0-caee-....",        "screenshot": {            "thumbnail": "mosmentDemo/710b5cc0-caee-..."        },        "clippingPlanes": [            {                "distance": 14189.1953125,                "clipDirection": -1,                "normal": [                    -1,                    0,                    0                ]            }        ]    }, .........

In order to display this in a custom web application, first we need to deploy the sample application, which can be found on our 3D Repo GitHub page. Once you have the model loaded in the view you can use the setViewpoint API with the following values:

UnityUtil.setViewpoint(pos: [], up: [], forward: [], lookAt: [])
  • pos - from the "position" value in the earlier API request

  • up - from the "up" value

  • forward - from the "view_dir" value

  • lookAt - from the "look_at" value

This can then be called from inside your new web application:

UnityUtil.setViewpoint(    [        24945.419921875,        5322.9072265625,        -2359.695068359375    ],    [        -0.03559441119432449,        0.9993206262588501,        -0.009558457881212234    ],    [        -0.9651273488998413,        -0.03685547783970833,        -0.25917351245880127    ],    [        6790.517578125,        4629.623046875,        -7234.9794921875    ])

Result:

Colour Overrides

Colour overrides can be applied in a number of areas in 3D Repo, including issues, risks and viewpoints. For this guide we will focus on Groups, which should provide a good jumping off point.

As with the previous example we will be using the "Lego_House_Federation" included in all new teamspaces. This time we will be looking at Groups. Opening up the Groups card in 3D Repo you can see there are a number of colour overrides:

We can query these via the data API using the Groups - List All Groups API request with the following variables:

  • teamspace - the name of the teamspace you model/federation has been upload to

  • model - the GUID of the model, available in the model viewer URL string

  • api key - your unique API key (Generate an API Key | 3D Repo Help Centre)

curl --location --request GET 'https://www.3drepo.io/api/{teamspace}/{model}/revision/master/head/groups?key={api key}&noIssues=true&noRisks=true&noViews=true'

Producing the following response:

[    {        "_id": "2988d9d0-4961-11e8-bfe5-eb53f1800955",        "color": [            87,            88,            187        ],        "objects": [            {                "account": "mosmentDemo",                "model": "70f7fbd0-caee-11ec-98b5-814c7d82bc19",                "shared_ids": [                    "7c7bc0b4-38c6-4592-a488-7e5332d0a8c1",                    "c195e042-4c33-4eb6-89fd-68067eedba11",                    "3c4d1e62-7a89-42cd-9d8c-6789e35d0942",                    "23e27b83-25b7-4bc0-ab4c-bd82cb84b810",                    "3b18ba28-047a-4c2f-89aa-99744e2a73bb",                    "0449b1d9-e08d-45c1-9da9-e06f93c29df3",                    "8a2f1dd6-0230-4c82-a7e0-e9a38900c3e4",                    "18a1ac37-5ec5-40a8-871b-faebc385a17c",                    "96594c10-5949-4ce7-bed0-638ab38bc8d4",                    "023c440d-3c0b-458e-a778-ed96ac200f0f",                    "65506041-39ba-4567-bc0a-534bbb46ea87",                    "dd96566a-3022-4edf-9b46-68765c87b65c",                    "19cf75a8-19ae-4946-95f3-8f28ddea2efb"                ]            },            {                "account": "mosmentDemo",                "model": "70f7adb0-caee-11ec-98b5-814c7d82bc19",                "shared_ids": [                    "75147e3e-3dce-4606-849c-db5048876036",                    "0f262620-3a01-4828-9a09-6ec869ea0b3c",                    "60d910f5-dc11-4d52-a0ec-93bda5b73589",                    "80aa9dbd-464e-4e32-8c11-6233b77666fd",                    "50859639-1c69-4e26-9441-fb66aaa4caf4"                ]            }        ],        "name": "Isolate group",        "author": "mosmentDemo",        "createdAt": 1524754223184,        "updatedBy": "Laika0416",        "updatedAt": 1524754819471,        "description": "to see all objects in the group"    } ......

This produces a set of "shared_ids" referring to objects inside the group, regardless of whether the group has been created by Normal or Smart groups. These values need to be matched to mesh IDs using either the Model - Get ID Map or Model - Get Tree (requires sub model iteration). In this example we will use the Get ID Map request:

curl --location --request GET 'https://www.3drepo.io/api/{teamspace}/{model}/revision/master/head/idMap.json'

Returning the following key/value pairs:

{   "subModels": [        {            "account": "mosmentDemo",            "model": "70fbcc60-caee-11ec-98b5-814c7d82bc19",            "idMap": {                "6b6d7837-ef2e..": "6600cecb-f0b2-43b..",                "a79ff7de-fef1..": "d1f74640-d8a9-411.." ....

In order to display this first group colour override inside your custom application you will need to use the overrideMeshColor API with the following values:

UnityUtil.overrideMeshColor(account: string, model: string, meshIDs: [], color: [])
  • account - the name of the teamspace you model/federation has been upload to

  • model - the model id of the model/federation

  • meshIDs - an array of mesh_ids from the Get ID Map request relative to the shared_ids from the Get All Groups request

  • color- the colour of the overide as an RGB Percent value (0 - 1). In order to convert the values from the previous request we must divide each RGB value by 255 eg. (87, 88, 187) becomes (0.302, 0.345, 0.733)

This can then be called from inside your new web application:

UnityUtil.overrideMeshColor(    "mosmentDemo",    "70f7fbd0-caee-11ec-98b5-814c7d82bc19",    [        "0301f695-826e-4578-a4cd-45e2fb8a1f84",        "08e2c5ef-3fea-4f4e-a860-ac3c18ddfe83",        "0aaa794f-9088-4d6f-b5f3-9f58d3be1046",        "0fba5117-6561-4a6d-9d74-77d1b89149af",        "25f8cacb-8975-4e5d-962b-4a53962b318d",        "5acb943e-dfa3-4482-99fe-96076782d501",        "7c059122-38c7-4cd5-8383-c427e4bebe6c",        "870647e4-5f00-49fb-ab5e-e17c891ec9ea",        "93b52a2f-40b3-4ce9-81ed-6d51049d9f89",        "94bdcb5d-47b2-43b3-9eae-02385ce61c81",        "aba7d25d-89ce-4447-9f32-f366dd275bf1",        "e012e92b-a25c-40ba-bb95-b379c3a6f226",        "f08ed827-e45d-4844-bb87-8fe99695b399"    ],    [        0.302,        0.345,        0.733    ])

Result:

Did this answer your question?