The SDK's buildable, viewable, importable and exportable 3D scene representation
Overview
The xeokit SDK represents models in a scene graph that include the model's 3D objects, geometries, and materials. This scene
graph works on both the browser and NodeJS platforms and can be used to create models, convert between model formats, and provide
content for the SDK's model Viewer.
Create Scene content programmatically using builder methods.
Notes
SceneTextureSets are collections of textures that are shared among SceneMeshes and are organized into texture atlasses to optimize rendering efficiency on GPUs.
Each SceneMesh can be assigned to only one SceneObject, whereas each SceneGeometry and SceneTextureSet can be allocated to an unlimited number of SceneMeshes.
If we're coding in the browser, we can view our Scene by attaching it to a Viewer, as
shown below. The Viewer will then provide an interactive 3D view of our Scene. As we create and destroy objects,
they will appear and disaapear in the view.
Our minimal browser Viewer gets a WebGLRenderer, to adapt it
to use the browser's WebGL graphics API for 3D viewing. Our Viewer also gets a single View
to make it draw to a specified canvas in the page. The View also gets a CameraControl,
so we can interact with it using mouse and touch input.
Note that a Scene does not need to be attached to a Viewer. A Scene functions as a stand-alone data structure, and
is agnostic of Viewer. In the browser, we typically use Scene with a Viewer. In a NodeJS script, that has no need to draw
anything, we would typically use Scene without a Viewer.
When we've finished constructing our SceneModel, we'll call SceneModel.build. After that,
our SceneModel appears in our Viewer and we can interact with it.
The classes Scene, SceneModel, SceneObject, and SceneMesh each have
an "aabb" property that contains their axis-aligned world-space 3D boundaries
(AABB).
The SceneGeometry class has an "aabb" property that represents the geometry's local-space boundary.
When we created our SceneModel, the SceneModel.createGeometry
method internally performed some on-the-fly compression and processing of our geometry parameters.
To speed up SceneModel creation, we may want to perform that compression in advance.
xeokit 3D Scene Representation
The SDK's buildable, viewable, importable and exportable 3D scene representation
Overview
The xeokit SDK represents models in a scene graph that include the model's 3D objects, geometries, and materials. This scene graph works on both the browser and NodeJS platforms and can be used to create models, convert between model formats, and provide content for the SDK's model Viewer.
To elaborate further:
Notes
Installation
Usage
Import Modules
First we'll import the modules we'll need:
Creating a Scene
Next, we'll create a Scene:
Viewing the Scene
If we're coding in the browser, we can view our Scene by attaching it to a Viewer, as shown below. The Viewer will then provide an interactive 3D view of our Scene. As we create and destroy objects, they will appear and disaapear in the view.
Our minimal browser Viewer gets a WebGLRenderer, to adapt it to use the browser's WebGL graphics API for 3D viewing. Our Viewer also gets a single View to make it draw to a specified canvas in the page. The View also gets a CameraControl, so we can interact with it using mouse and touch input.
Note that a Scene does not need to be attached to a Viewer. A Scene functions as a stand-alone data structure, and is agnostic of Viewer. In the browser, we typically use Scene with a Viewer. In a NodeJS script, that has no need to draw anything, we would typically use Scene without a Viewer.
Building a SceneModel
Next, we'll create a SceneModel that will model the simple table object shown in the image above. Our SceneModel will contain five SceneObjects, five SceneMeshes, one SceneGeometry and one SceneTexture.
When we've finished constructing our SceneModel, we'll call SceneModel.build. After that, our SceneModel appears in our Viewer and we can interact with it.
Reading the SceneModel
Now that we've built our SceneModel, we can read all of its components.
Reading Boundaries
The classes Scene, SceneModel, SceneObject, and SceneMesh each have an "aabb" property that contains their axis-aligned world-space 3D boundaries (AABB).
The SceneGeometry class has an "aabb" property that represents the geometry's local-space boundary.
Using Compressed Geometry
When we created our SceneModel, the SceneModel.createGeometry method internally performed some on-the-fly compression and processing of our geometry parameters.
To speed up SceneModel creation, we may want to perform that compression in advance.
We can use the compressGeometryParams function to pre-compress the geometry parameters so that we can then use SceneModel.createGeometryCompressed instead, to create the geometry directly from the compressed parameters.
In the example below, we'll now use compressGeometryParams to compress a SceneGeometryParams into a SceneGeometryCompressedParams.
The value of our new SceneGeometryCompressedParams is shown below.
We can see that:
aabb
, to de-quantize the positions within the ViewerWe could then create a SceneGeometry from the compressed parameters like this:
Saving a SceneModel to a File
We can export SceneModels to several file formats.
For example, let's use saveDotBIM to save our SceneModel to .BIM format:
Loading a SceneModel from a File
We can also import SceneModels from several file formats.
For example, let's use loadDotBIM to load a .BIM file into a new SceneModel:
Serializing a SceneModel to JSON
Deserializing a SceneModel from JSON
Destroying a SceneModel