Basic Streaming for an HSF File

Streaming of 3D data typically refers to a process whereby graphical information is retrieved from a remote location such as a website or server and is displayed as soon as it is received by the client application. It allows the end-user to quickly obtain some visual feedback, as well as interact with the scene as it is still being displayed.

The following steps are necessary to add support for streaming an HSF into an application:

  1. Create an instance of a BStreamFileToolkit object.
  2. Open a file. For a local file, this could be done manually using fopen, or the toolkit's wrapper function BStreamFileToolkit::OpenFile could be used.
  3. Read, process and incrementally draw chunks of the file to the screen by calling the sequence of BStreamFileToolkit::ReadBuffer, BStreamFileToolkit::ParseBuffer and your application-specific scene-graph drawing function within a loop until the entire file has been read. For a local file, reading could be done manually using fread. If the toolkit's BStreamFileToolkit::OpenFile wrapper function was used to previously open the file, than BStreamFileToolkit::ReadBuffer may be used to read from the file.

In review, it is up to the developer to map the data to their custom data-structures within the Execute method of their custom opcode handlers when using the base classes.

The following code demonstrates how an HSF file called 'factory.hsf'could be streamed into the HOOPS/3dGS database and incrementally drawn, using the base classes:

void Stream_HSF_File (char const * filename)
{
auto char block[BUFFER_SIZE];
auto TK_Status status = TK_Normal;
auto int amount;
BStreamFileToolkit * tk = new BStreamFileToolkit;
// our sample custom toolkit only cares about segment and shells
tk->SetOpcodeHandler (TKE_Open_Segment, new TK_My_Open_Segment);
tk->SetOpcodeHandler (TKE_Close_Segment, new TK_My_Close_Segment);
tk->SetOpcodeHandler (TKE_Shell, new TK_My_Shell);
if ((status = tk->OpenFile (filename)) != TK_Normal)
return status;
do
{
if (tk->ReadBuffer (block, BUFFER_SIZE, amount) != TK_Normal)
break;
status = tk->ParseBuffer (block, amount);
MyGraphicsUpdateFunction();
if (status == TK_Error)
{
// whatever...
break;
}
} while (status != TK_Complete);
tk->CloseFile ();
delete tk;
}

top_level:2 prog_guide:2 prog_guide/base_stream:1