Search code examples
jsonautodesk-forgeautodesk-viewerautodesk-model-derivative

How does Forge Viewer interacts with the local repository (json files)?


I need to implement some customization to the autodesk viewer, and to do that I need to understand how the relationships with the repository files work, to understand these relationships I'm also using the model.sdb provided by forge derivative-api (the same which gives us the json files).

I have identified 6 files:

objects_ids.json.gz
objects_attrs.json.gz
objects_avs.json.gz
objects_vals.json.gz
objects_offs.json.gz
objects_viewables.json.gz

Some of this files are pretty simple to understand:

objects_ids.json.gz - This file has the same content as the _objecs_id table, basically the external id and dbids (which is the row number -1).

objects_attrs.json.gz - Again this file is equivalent to a table on the sdb database, very easy to read. Here we have the definition for the attributes used in the modelviewer. It has the following "columns": id,name,category,data_type,data_type_context,description,display_name,flags,display_precision

objects_vals.json.gz Equivalent to _objects_val table, here we have two things, ID and VALUE (for the attributes defined on the previous json document).

Until now things are pretty easy... We have the object identification, attributes and it's possible values, but the problem is, how to make then work together? Right now they are isolated, so they're useless right now. I need to relate a object identification with it's attributes with it's values.

To do that in the model.mdb we can join the tables, with the main relationship table: _objects_eav It has the entity_id, the attribute_id and value_id. So to join the data and have the information we need we can simply do:

`SELECT * FROM _objects_id
INNER JOIN _objects_eav ON _objects_id.id = _objects_eav.entity_id
INNER JOIN _objects_attr ON _objects_attr.id = _objects_eav.attribute_id
INNER JOIN _objects_val ON _objects_val.id = _objects_eav.value_id`

But there is no json file equivalent to the _objects_eav table...

Instead we have the following files objects_avs.json.gz, objects_offs.json.gz, objects_viewables.json.gz

Right now I have no idea how to merge the data between these files and get the whole information needed. Any toughs about this?

Other thoughts: Alternatively I could use the model.sdb to access the data, but I rather use the JSON, since they are way smaller (30 x smaller than the model.sdb, that's a massive amount).

I could also get some data using the methods provided by the viewer objects in JavaScript, but then I would be stuck with the methods and properties provided by the viewer, and unfortunately they do not fulfill all my requirements.

Then there is the option to use the model-derivative API, but one of my requirements is to be able to work with the data disconnected (offline).


Solution

  • Here's what the individual .json.gz files contain:

    • objects_ids.json.gz - object IDs
    • objects_offs.json.gz - for each object ID at the same index in objects_ids.json.gz, this array defines an offset into the attribute-value list in objects_avs.json.gz
    • objects_avs.json.gz - contains attribute-value pairs which are basically offsets into objects_attrs.json.gz and objects_vals.json.gz
    • objects_attrs.json.gz - contains different attributes (and their metadata I believe)
    • objects_vals.json.gz - contains de-duplicated values

    With that said, I'd still suggest to use the sqlite format (even though it's bigger), instead of the proprietary .json.gz files as those are really meant to be used by the Forge Viewer and could potentially change in the future.