The SDK's buildable, queryable, importable and exportable semantic data model
Overview
The xeokit SDK uses a generic entity-relationship data graph to manage model semantics. This graph includes entities,
properties, and relationships and is compatible with both the browser and NodeJS. It serves as a versatile tool for generating
models, converting between model formats, and navigating content within the model viewer.
It's important to note that DataObjects and PropertySets are global, created on their DataModels but stored globally
on the Data. Additionally, DataModels automatically reuse DataObjects and PropertySets wherever they're already
created by other DataModels. Finally, DataObjects can have Relationships with other DataObjects in different DataModels.
Installation
npminstall@xeokit/sdk
Usage
Creating a DataModel from JSON
We will start with an example where we create a DataModel using a single parameter
object of type DataModelParams.
The DataModel we create will define a simple piece of furniture - a table consisting of a tabletop and four legs.
We will then query the data model to retrieve all the DataObjects within it.
To achieve this, we will create a DataModel that contains six DataObjects: one for the
table, one for the tabletop, and one for each of the four legs. We will also define Relationships
to connect the DataObjects into an aggregation hierarchy, and we will assign Properties to the
DataObjects to give them attributes such as height and weight.
To give the DataObjects and Relationships semantic meaning, we will assign
them types from one of the SDK's bundled data type sets, @xeokit/basictypes. This set of types classifies each DataObject
as a BasicEntity and each Relationship as
a BasicAggregation.
It's worth noting that in a real-world scenario, we would likely use a more complex set of data types, such as
@xeokit/ifctypes. However, we cannot mix different sets of data types within our Data,
as traversals of the DataObjects with Data.searchObjects must be
guided uniformly by the same set of types across all the DataObjects and Relationships in the graph.
To create our DataModel, we will use the following code, which creates a new Data object and then
creates a DataModel from a set of objects, relationships, and property sets. The SDKError class
is used to handle errors that may occur during the process:
In our next example, we'll demonstrate how to traverse the DataObjects along their
Relationships. We'll start at the root DataObject and visit all the DataObjects
we encounter along the outgoing Relationships.
xeokit Semantic Data Model
The SDK's buildable, queryable, importable and exportable semantic data model
Overview
The xeokit SDK uses a generic entity-relationship data graph to manage model semantics. This graph includes entities, properties, and relationships and is compatible with both the browser and NodeJS. It serves as a versatile tool for generating models, converting between model formats, and navigating content within the model viewer.
In more detail, the xeokit SDK provides a Data container class that holds DataModels consisting of DataObjects, PropertySets, and Relationships, as shown in the diagram below.
Various model file formats can be imported into DataModels using methods such as loadGLTF, loadLAS, loadCityJSON, loadWebIFC, loadDotBIM, and loadXGF, while DataModels can be exported to various formats, using methods such as saveDotBIM.
To programmatically build DataModels, builder methods such as Data.createModel, DataModel.createObject, DataModel.createPropertySet, and DataModel.createRelationship can be employed. DataObjects can be queried using the Data.searchObjects method, and semantic data can be attached to model representations by using it alongside SceneModel.
It's important to note that DataObjects and PropertySets are global, created on their DataModels but stored globally on the Data. Additionally, DataModels automatically reuse DataObjects and PropertySets wherever they're already created by other DataModels. Finally, DataObjects can have Relationships with other DataObjects in different DataModels.
Installation
Usage
Creating a DataModel from JSON
We will start with an example where we create a DataModel using a single parameter object of type DataModelParams. The DataModel we create will define a simple piece of furniture - a table consisting of a tabletop and four legs. We will then query the data model to retrieve all the DataObjects within it.
To achieve this, we will create a DataModel that contains six DataObjects: one for the table, one for the tabletop, and one for each of the four legs. We will also define Relationships to connect the DataObjects into an aggregation hierarchy, and we will assign Properties to the DataObjects to give them attributes such as height and weight.
To give the DataObjects and Relationships semantic meaning, we will assign them types from one of the SDK's bundled data type sets, @xeokit/basictypes. This set of types classifies each DataObject as a BasicEntity and each Relationship as a BasicAggregation.
It's worth noting that in a real-world scenario, we would likely use a more complex set of data types, such as @xeokit/ifctypes. However, we cannot mix different sets of data types within our Data, as traversals of the DataObjects with Data.searchObjects must be guided uniformly by the same set of types across all the DataObjects and Relationships in the graph.
To create our DataModel, we will use the following code, which creates a new Data object and then creates a DataModel from a set of objects, relationships, and property sets. The SDKError class is used to handle errors that may occur during the process:
Creating a DataModel using Builder Methods
In our second example, we'll create our DataModel again, this time instantiating each PropertySet, Property, DataObject and Relationship individually, using the DataModel's builder methods.
Reading DataObjects
With our DataModel built, we'll now use the Data.searchObjects method to traverse it to fetch the IDs of the DataObjects we find on that path.
One example of where we use this method is to query the aggregation hierarchy of the DataObjects for building a tree view of an IFC element hierarchy.
Searching DataObjects
In our next example, we'll demonstrate how to traverse the DataObjects along their Relationships. We'll start at the root DataObject and visit all the DataObjects we encounter along the outgoing Relationships.
Serializing a DataModel to JSON
Deserializing a DataModel from JSON
Destroying a DataModel
Loading a DataModel from a File
We can also import DataModels from several file formats.
For example, let's use loadDotBIM to load a .BIM file into a new SceneModel and DataModel: