Working with Scene Data

<< Click to Display Table of Contents >>

Navigation:  Simplygon API 7.1 User guide >

Working with Scene Data

The Simplygon API represents a scene and a scene graph with the IScene class. A scene can contain materials, textures, bones and meshes. A scene by default contains a root node, a material table, a texture table, a bone table and a selection set table. See the figure below.

Scengraph.png

 

IScene

The IScene class object can be created by the API object by calling the CreateScene method. The IScene class provides the GetNodeFromPath method to fetch nodes in the scene using a path, see ISceneNode below for information on how to fetch the path of a node. IScene class also provides a method to save a scene as a binary representation using the SaveToFile method. The binary file can be loaded again for reuse using the LoadFromFile method. These methods are used internally and it is not guaranteed that they will work in later releases.

 

ISceneNode

The Simplygon API uses the ISceneNode base class to represent nodes in the scene graph. A node can be created by using the API object and calling the CreateSceneNode method. Each node can have a name which can be used when navigating from an ISceneobject. The class allows the user to work with child nodes by using AddChild, GetChild, GetChildCount, RemoveChild, RemoveChildren, HasChild and FindNamedChild methods. The GetParent method is provided to access the parent node. The ISceneNode class also provides a method to retrieve the path of the node in the scene by calling the GetPath method. Each ISceneNode object in Simplygon also keeps a relative transformation to its parent node which can be accessed using GetRelativeTranform method. The class also provides a method to get the absolute transform of a node in the scene hierarchy by using the EvaluateDefaultGlobalTransformationmethod. See figure 7 for an example of global and local transformations.

 

Root Node

The root node is an ISceneNode that is automatically created when an IScene object is created. All nodes that are added to the scene must be placed in a hierarchy below the root node. See figure 8.

 

ISceneMesh

The Simplygon API provides an ISceneMesh class to represent a mesh node in a scene. ISceneMesh is derived from ISceneNode. An ISceneMesh object can be created from the API object by calling CreateSceneMesh method. To assign IGeometryData to an ISceneMesh object use the SetGeometry method. In figure 8 the blue mesh nodes belong to the ISceneMesh class.

 

ISceneBone

The Simplygon API provides an ISceneBone class to represent a bone in a scene. An ISceneBone object can be created from the API object by calling CreateSceneBone method. ISceneBone class also provides all the functionality of its parent class ISceneNode. See the Bone Table section for more information. In figure 8 the green bone nodes belong to the ISceneBone class.

 

ISceneCamera

The Simplygon API provides an ISceneCamera class to represent a camera in a scene. The camera has properties that determine the field of view and the coordinate system. A camera can have multiple camera views that are each defined by a camera position and a target position. Cameras are used when computing the visibility in the scene.

 

IScenePlane

The Simplygon API provides an IScenePlane class to represent an infinite geometrical plane in the scene, defined by an origin and a normal. These are not relevant for any reduction processing, but they can be used as cutting planes when performing remeshing.

 

ISelectionSet

An ISelectionSet is a set of references to scene nodes, by their GUID. These sets can be created and added to the scene selection set table, and subsequently be used to set what nodes in a given scene will be processes in the reduction processors. Selection sets are also used to select which planes in the scenes are to be used as cutting planes by the remeshing processor, or which scene cameras are used in the visibility processing of both the reduction and remeshing processor.

 

Material Table

An IScene object internally maintains an IMaterialTable which is used to setup and maintain materials in a scene. To access the material table from an IScene object use the GetMaterialTable method. Each material created in the scene must be added to the material table. To add materials use AddMaterial method. The unique id returned by AddMaterial is then assigned to the items in the material id field in an IGeometryData object (per-triangle MaterialIds). See figure 8.

 

Texture Table

An IScene object internally maintains an ITextureTable which is used to add and cache textures used by material shading networks in a scene. To access the texture table from an IScene object use the GetTextureTable method. To add textures, i.e. objects of type ITexture, use the AddTexture method.

 

Bone Table

An IScene object internally maintains an IBoneTable which is used to maintain bones in a scene. To access the bone table from an IScene object use the GetBoneTable method. Each bone that is created in the scene must be added to the bone table. To add a bone use AddBone method. When you add a bone to the bone table it returns a unique bone id which can then be bound to geometry data (Bones Ids). See figure 8. For bone reduction to work make sure that the scene's bone table is properly setup.

 

SelectionSet Table

An IScene object internally maintains an ISelectionSetTable which is used to maintain selection sets in a scene. The selection sets positions in this table determines their selection set id, which is used to set any selection set settings in the processors.

 

Scene Example
 
void SceneExample(spGeometryData geom)
{
   // Create a new scene object.
   spScene scene = sg->CreateScene();
   // Create a new scene mesh object.
   spSceneMesh mesh = sg->CreateSceneMesh();
   mesh->SetName("mesh");
 
   // Assign the geometry data to the mesh.
   mesh->SetGeometry(geom);
 
   // Add mesh to the scene.
   scene->GetRootNode()->AddChild(mesh);  
}
 

Scene Bone Example

 
void AddBoneToTheScene(spScene scene)
{
   // Access the scene bone table.
   spSceneBoneTable scene_bone_table = scene->GetBoneTable();
   // Create a new bone object.
   spSceneBone bone = sg->CreateSceneBone();
   bone->SetName("RootBone");
 
   // Add bone to the bone table.
   rid boneId = scene_bone_table->AddBone(root_bone);
 
   // ... do any other operation like apply transformation ...
   // Add bone to the scene.
   scene->GetRootNode()->AddChild(bone);  
}
 

For more help with setting up a scene graph, see the scene data example.