Using Hoops in C# (I) : HelloHoops

25 Oct

Hoops is a good 3D Visualization toolkit with OOP model enabled. In this tutorial, Hoops will be used in combination of .net. C# language will be used to demostrate the typical usage.

  1. Createa a new winform project, name it HelloHoops
  2. In the Hoops installation folder, search the file “HPanel.cs”, and copy it in explorer, and in, paste it.


  3. Drag a button and a panel to the form designer


    Implement the event handler of the button click:

    private void Open_Click(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Open Photo"; dlg.Filter = "HMF/HSF files (*.hmf)|*.hmf;"; if (dlg.ShowDialog() == DialogResult.OK) { if (dlg.FileName.EndsWith("hmf")) { HCS.Open_Segment("?picture"); HCS.Flush_Contents(".", "geometry, subsegments"); HCS.Read_Metafile(dlg.FileName, "?picture", ""); HCS.QUnSet_Bounding_Volume("?picture"); HCS.Close_Segment(); HoopsPanel.Refresh(); } } }

  4. Name the panel as “HoopsPanel”, and

    In the MainForm.Designer.cs, replace the type of HoopsPanel from “Panel” to HPanelHelloHoops6

    Change the instanciation code accordingly:


  5. Add two reference dll to the project:


  6. Compile and run. Click the open button and select the \HOOPS-Installation folder\demo\common\standard\fruit.hmf”, now it works!


In this HelloHoops project, we use hoops 3D Graphics System (3DGS) to render the image. The HPanel class handles the image rendering in its OnPaint event handler:

/*! Instructs HOOPS/3dGS to redraw the scene */ override protected void OnPaint(PaintEventArgs e) { base.OnPaint(e); HLONG key = HCS.KOpen_Segment("?picture"); HCS.Control_Update_By_Key(key, "redraw everything"); HCS.Update_Display(); HCS.Close_Segment(); }

And in the button_click event for the “Open” button,  an image file is loaded, and then the panel is refreshed to reflect the update. You can of course define your own OnPaint() and OnOpenClick() code, and do more complex rendering tasks. However this shows the basic mechnism how HOOPS 3DGS works.

Some notes:

  • Properly select the x86 or x64 or AnyCPU platform which matches the assembly you added to the project;
  • Add the Hoops installation\bin folder to the system path directory, or else there may be some errors such as DLL not found exceptions

Download Project file here.

Leave a comment

Posted by on October 25, 2010 in CAD, Dotnet/C#


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: