Tutorial 6: Static Model Workflow
Using a static model can dramatically reduce rendering time, especially for large models. In this tutorial, we'll walk you through the basics of setting up your scene to work with a static model. For a top-level overview of the performance benefits of using a static model, please see the Performance Considerations section of the Programming Guide.
6.1 Importing a model file
We'll start off by importing an HSF file using an ImportOptionsKit. (For more information on importing files, please see this section.)
HPS.
Model myModel = Factory.CreateModel();
string filename = "C:\\myData\\bnc.hsf";
HPS.
Stream.ImportNotifier importNotifier =
new Stream.ImportNotifier();
try
{
HPS.
Stream.ImportOptionsKit myImportOptionsKit =
new Stream.ImportOptionsKit();
myImportOptionsKit.SetSegment(modelSegment);
importNotifier =
HPS.
Stream.File.Import(filename, myImportOptionsKit);
importNotifier.Wait();
}
{
}
6.2 Setting the static model
Next we'll attach the newly imported model to the front view of our canvas. Then, we'll define this segment as a static model:
_canvas.GetFrontView().AttachModel(myModel);
modelSegment.GetPerformanceControl().SetStaticModel(Performance::StaticModel::Attribute);
window.UpdateWithNotifier(Window::UpdateType::Exhaustive).Wait();
_canvas.GetFrontView().AttachModel(myModel);
modelSegment.GetPerformanceControl().SetStaticModel(Performance.StaticModel.Attribute);
window.UpdateWithNotifier(Window.UpdateType.Exhaustive).Wait();
6.3 Collecting performance diagnostics
In order to see diagnostic information about our static model, we'll use the WindowInfoControl to populate an UpdateInfo object:
WindowInfoControl windowInfo = window.GetWindowInfoControl();
UpdateInfo updateInfo;
size_t static_models_created = 0;
if (windowInfo.ShowLastUpdateInfo(updateInfo))
{
static_models_created = updateInfo.statics_created_count;
}
WindowInfoControl windowInfo = window.GetWindowInfoControl();
int static_models_created = 0;
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
{
}
6.4 Changing the static model
For illustration purposes, we're going to change the modelling matrix by doubling the scale of the model; this change will invalidate the static model and will require an update:
_canvas.GetFrontView().GetAttachedModel().GetSegmentKey().GetModellingMatrixControl().Scale(2.0f, 2.0f, 2.0f);
_canvas.GetFrontView().GetAttachedModel().GetSegmentKey().GetModellingMatrixControl().Scale(2.0f, 2.0f, 2.0f);
6.5 Using the Resource Monitor
A component of the HPS::DebuggingControl class, the Resource Monitor displays a variety of helpful statistics, including the number of static models generated in the most recent update. It's a useful tool for debugging and for testing which changes will trigger regeneration of the static model.
[figure 6.1.a] The Resource Monitor
Here's how to load it into the scene:
window.GetDebuggingControl().SetResourceMonitor(true);
window.GetDebuggingControl().SetResourceMonitor(true);
6.6 Update types
For performance reasons, when a window is updated with the Default UpdateType, the static model is not regenerated during an update immediately following any changes that have been made to the scene that invalidated the static model subtree.
Instead, the static model will be regenerated on the next update as long as no further changes have occurred that would have invalidated the static model subtree. In other words, Visualize waits until it's reasonably sure that all of the invalidating changes have been made before performing an update to the static model. This is a performance optimization to avoid generating a static model unnecessarily.
(To force a static model regeneration, however, you would simply use the Exhaustive UpdateType.)
The first non-Exhaustive and non-CompileOnly update after a modification will not build a static model.
window.UpdateWithNotifier(Window::UpdateType::Default).Wait();
if (windowInfo.ShowLastUpdateInfo(updateInfo))
static_models_created = updateInfo.statics_created_count;
window.UpdateWithNotifier(Window.UpdateType.Default).Wait();
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
static_models_created = (int)updateInfo.statics_created_count;
The second non-Exhaustive and non-CompileOnly update after a modification will build a static model (assuming no additional static-breaking changes are made, which would delay the update).
window.UpdateWithNotifier(Window::UpdateType::Default).Wait();
if (windowInfo.ShowLastUpdateInfo(updateInfo))
static_models_created = updateInfo.statics_created_count;
window.UpdateWithNotifier(Window.UpdateType.Default).Wait();
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
static_models_created = (int)updateInfo.statics_created_count;
Appendices
Full source code:
try
{
}
{
throw;
}
_canvas.GetFrontView().AttachModel(myModel);
modelSegment.GetPerformanceControl().SetStaticModel(Performance::StaticModel::Attribute);
window.UpdateWithNotifier(Window::UpdateType::Exhaustive).
Wait();
WindowInfoControl windowInfo = window.GetWindowInfoControl();
UpdateInfo updateInfo;
size_t static_models_created = 0;
if (windowInfo.ShowLastUpdateInfo(updateInfo))
{
static_models_created = updateInfo.statics_created_count;
}
_canvas.GetFrontView().GetAttachedModel().GetSegmentKey().GetModellingMatrixControl().Scale(2.0f, 2.0f, 2.0f);
window.GetDebuggingControl().SetResourceMonitor(true);
window.UpdateWithNotifier(Window::UpdateType::Default).
Wait();
if (windowInfo.ShowLastUpdateInfo(updateInfo))
static_models_created = updateInfo.statics_created_count;
window.UpdateWithNotifier(Window::UpdateType::Default).
Wait();
if (windowInfo.ShowLastUpdateInfo(updateInfo))
static_models_created = updateInfo.statics_created_count;
HPS.
Model myModel = Factory.CreateModel();
string filename = "C:\\myData\\bnc.hsf";
HPS.
Stream.ImportNotifier importNotifier =
new Stream.ImportNotifier();
try
{
HPS.
Stream.ImportOptionsKit myImportOptionsKit =
new Stream.ImportOptionsKit();
myImportOptionsKit.SetSegment(modelSegment);
importNotifier =
HPS.
Stream.File.Import(filename, myImportOptionsKit);
importNotifier.Wait();
}
{
}
_canvas.GetFrontView().AttachModel(myModel);
modelSegment.GetPerformanceControl().SetStaticModel(Performance.StaticModel.Attribute);
window.UpdateWithNotifier(Window.UpdateType.Exhaustive).Wait();
WindowInfoControl windowInfo = window.GetWindowInfoControl();
int static_models_created = 0;
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
{
}
_canvas.GetFrontView().GetAttachedModel().GetSegmentKey().GetModellingMatrixControl().Scale(2.0f, 2.0f, 2.0f);
window.GetDebuggingControl().SetResourceMonitor(true);
window.UpdateWithNotifier(Window.UpdateType.Default).Wait();
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
static_models_created = (int)updateInfo.statics_created_count;
window.UpdateWithNotifier(Window.UpdateType.Default).Wait();
if (windowInfo.ShowLastUpdateInfo(out updateInfo))
static_models_created = (int)updateInfo.statics_created_count;