How to show several imported model in hoops?

Ofen, we need show multi imported model and some created objects. But examples of hoops have not such demo. Is there anyone know it and would like to show it in brief code?

Here is a quick example how you would add another hsf file to an already existing model. Just add this code to the mfc sandbox:

void CHPSView::OnUserCode4()
{
	HPS::SegmentKey newmodel = HPS::Database::CreateRootSegment(); 
	newmodel.MoveTo(GetDocument()->GetModel().GetSegmentKey());

	HPS::Stream::ImportOptionsKit ioOpts;
	ioOpts.SetSegment(newmodel);

	HPS::UTF8 filename("e:\\temp\\test.hsf");
	HPS::Stream::File::Import(filename.GetBytes(), ioOpts);
}

Thanks @guido

I know @jamestruax and @dave.calkins are pretty skilled with Visualize. They might have some additional suggestions as well.

@467531559 how are you importing the model? Are you importing a CAD model with Exchange and rendering it with Visualize? If so, I can try and help with that as that’s what we do.

Get it, thank you~
~

Thanks for you detail reply. I import external model using exchange in qt mostly. Importing model like your given code with the same way in qt was not ok. If you konw qt, can you give the code demo in qt?

Yes, mostly we import model using exchange for more types of model. Can you show your suggestions in code? Thanks a lot~

@467531559 We import CAD files with Exchange, but do so by calling HOOPS Visualize which itself calls into Exchange to do the import.

  • HPS.Exchange.File.Import() returns a notifier (HPS.Exchange.ImportNotifier)
  • When the notifier indicates successful completion we get the model via notifier.GetCADModel(), this returns the HPS.Exchange.CADModel object for the imported model
  • A new segment in HPS is created beneath the model key using the HPS.SegmentKey.Subsegment() call on the model segment key, the result is in a variable, SegKey
  • To add the imported CAD model to the visual scene, beneath the newly created segment we do the following
  • Call HPS.Exchange.CADModel.ActivateDefaultCapture(), which returns an HPS view object (importedView) containing the visual representation of the imported model. When we first started used HOOPS we realized this was a bit of an issue. The intent here, as we understood it, was to replace the current view with this new view. Meaning there was an assumption that you only wanted to ever render a single CAD model. Techsoft support helped us work through this with the following.
  • Extract the conditions on the view which was returned from ActivateDefaultCapture(), these will be needed when adding the imported model to an existing scene
    • Setup a list which will hold all the conditions
      • List<string> conditionsAll = new List<string>();
    • On the view which was returned, call GetSegmentKey().GetStyleControl().Show() to return an array of the styles
    • loop through the styles array and for each one call ShowSource()
    • Use the below to handle the result from ShowSource() and build up the conditionsAll array
     string[] conditions = null;
        HPS.Style.Type styleType;
        HPS.SegmentKey styleSegment;
        string styleName;
        if (style.ShowSource(out styleType, out styleSegment, out styleName))
        {
            if (styleType == HPS.Style.Type.Segment)
            {
                styleSegment.ShowConditions(out conditions);
            }
            else
            {
                HPS.PortfolioKey viewPortfolio;
                if (_importedView.GetSegmentKey().GetPortfolioControl().ShowTop(out viewPortfolio))
                {
                    HPS.NamedStyleDefinition namedStyle;
                    if (viewPortfolio.ShowNamedStyleDefinition(styleName, out namedStyle))
                    {
                        namedStyle.GetSource().ShowConditions(out conditions);
                    }
                }
            }
        }

        if (conditions != null)
        {
            foreach (string condition in conditions)
            {
                conditionsAll.Add(condition);
            }
        }
  • You now have all the conditions set on the imported view
  • Apply the conditions from the view to the new segment created beneath the model key
    • SegKey.SetConditions(conditionsAllArr);
  • Create a new child segment beneath SegKey with the below
    • var attrKey = SegKey.Subsegment("custom attrs");
    • We used this additional attribute key so that we can set attributes on it and not interfere with anything set in the main SegKey for this model (this may or may not be necessary)
  • Include the imported model from your segment
    • attrKey.IncludeSegment(importedView.GetAttachedModel().GetSegmentKey());

The end result is that you have a new child segment under your model and this has the same conditions applied as was setup with ActivateDefaultCapture() and then you include the model from ActivateDefaultCapture() as well. We had to do this all to get it to work properly. It seems, as I mentioned earlier, there’s an assumption that you only ever want a single model, but for us this is not the case and it sounds like that’s your situation as well.

Hope this helps!

1 Like


Recently, i found a pic from the training material, which may help beginers like me understand the multi-model display simultaneously.

1 Like

It seems to be right for moving imported model to existing model. I tried this using exchange, but HPS::Exchange::ImportOptionsKit has not the function “ioOpts.SetSegment(newmodel)”. Can anyone who is familiar with exchange and know how to solve this little problem answer this question? Waiting online…


By similar manipulation, i displayed two .hsf models together.

		HPS::Stream::ImportOptionsKit ioKit;
		ioKit.SetSegment(view.GetSegmentKey());

		notifier = HPS::Stream::File::Import(filename.toUtf8(), ioKit);