Model import

Now that the HOOPS Native Platform application is running, we can import a model. For this project, we’ll use the “Aquo Bottle” demo model which can be found here <models/>.

In the tutorial source, hps_basic.cpp, you’ll find ImportModel, which handles the import process:

	Exchange::ImportNotifier exchangeNotifier;
	UTF8 file_in = stExchangeModelsFolder + "catiaV5/CV5_Aquo_Bottle/_Aquo Bottle.CATProduct";
	Exchange::ImportOptionsKit iok;
	exchangeNotifier = Exchange::File::Import(file_in, iok);

Like we did when creating the stand-alone window, we use an options kit to set up the file import. For loading a file using HOOPS Exchange, an Exchange::ImportOptionsKit needs to be used. Using the kit, the filename is set and a few other settings are configured which dictate how the model is to be imported. In this case, we are setting the filename and one other field, which is the BRep mode, Exchange::BRepMode::BRepAndTessellation. This means that both the model’s BRep and tessellation data will be imported.

Next, we call Exchange::File::Import using the file name and options kit as parameters. This is where the model is actually being read. Any file type supported by Exchange can be read by this function, as long as the options kit is set correctly. For other supported file types, such as HSF (HOOPS Stream File), or 2D images, the process is similar, but you would use HPS::File::Import with its appropriate import options kit.

For very large models, the load process can take some time. For this reason, we encourage you to set up your application so that it happens as gracefully as possible. An Exchange::ImportNotifier object is immediately returned from Import and the load process begins on a separate thread. The notifier object can be queried for status updates. In our case, we are simply waiting for the import process to complete by calling Wait(). This is important because if you try to use the notifier before the import is complete, you will get undefined behavior.

Once Wait() returns, we can get a reference to the loaded model by calling GetCADModel() on the notifier. This will be explained further in the following section.

If you attempt to reference the model before Wait() completes, you will encounter unpredictable behavior. It is imperative to ensure the model is fully loaded before any interaction. Additionally, the import process can throw an HPS::IOException, so always be prepared to always handle it in your application.