Sample Code: Create an animation using HBhvInterpolatorVertexMorph class

Build environment:

  • HOOPS 3DF Version 27.xx (at the time of this writing this KB article)
  • Visual Studio 2015 and up

The HBhvInterpolatorVertexMorph class performs interpolation by interpolating the individual vertex parameters of an object. The result of the animation is that object changes shape but retains the same set of vertices. Below are the steps to create a very rudimentary animation:

  1. First download HOOPS Visualize 3DF 27.xx from the Developer Zone portal in your preferred Visual Studio platform/version.
  2. While you’re at the portal, also download a hoops_license.h header by clicking the License Generator button. Move the license header to the directory HOOPS_3DF_27xx\Dev_Tools\hoops_3dgs\source (it’s okay to replace the existing header).
  3. Navigate to the HOOPS Visualize root/install directory and launch samples_v1Xxx.sln in Visual Studio.
  4. Set the project hoopspartviewer_v14x as the startup project.
  5. Expand Source folder and view CSolidHoopsView.cpp.
  6. Press CNTRL + End to get to the bottom of the file. Paste the following code to replace void CSolidHoopsView::OnExtraSlot1():
HC_KEY insertCube(char *x, HBaseView *view, HPoint pos, char *color = "green")
{
	HC_KEY shellKey = INVALID_KEY;

	int points = 8, faces = 30;
	HPoint pts[8];
	int faceList[30] = { 4, 0, 1, 2, 3,
		4, 1, 5, 6, 2,
		4, 5, 4, 7, 6,
		4, 4, 0, 3, 7,
		4, 3, 2, 6, 7,
		4, 0, 4, 5, 1 };

	HC_Open_Segment_By_Key(view->GetModelKey()); {
		HC_Open_Segment(x); {
			HC_Set_Visibility("edges");
			char mycolor[128];
			sprintf_s(mycolor, "faces=%s", color);
			HC_Set_Color(mycolor);

			pts[0].Set(-0.1 + pos.x, -0.1 + pos.y, -0.1 + pos.z);
			pts[1].Set(0.1 + pos.x, -0.1 + pos.y, -0.1 + pos.z);
			pts[2].Set(0.1 + pos.x, 0.1 + pos.y, -0.1 + pos.z);
			pts[3].Set(-0.1 + pos.x, 0.1 + pos.y, -0.1 + pos.z);
			pts[4].Set(-0.1 + pos.x, -0.1 + pos.y, 0.1 + pos.z);
			pts[5].Set(0.1 + pos.x, -0.1 + pos.y, 0.1 + pos.z);
			pts[6].Set(0.1 + pos.x, 0.1 + pos.y, 0.1 + pos.z);
			pts[7].Set(-0.1 + pos.x, 0.1 + pos.y, 0.1 + pos.z);

			shellKey = HC_Insert_Shell(points, pts, faces, faceList);
		} HC_Close_Segment();
	} HC_Close_Segment();

	return shellKey;
}

void CSolidHoopsView::OnExtraSlot1()
{
	HC_KEY cube_0_key = insertCube("cube_0", m_pHView, HPoint(0, 0, 0));

	int pcount_size = 0;
	int flist_size = 0;
	HC_Show_Shell_Size(cube_0_key, &pcount_size, &flist_size);
	HPoint * points = new HPoint[pcount_size];
	int * face_list = new int[flist_size];
	HC_Show_Shell(cube_0_key, 0, points, 0, face_list);

	HBhvInterpolatorPosition *pos = new HBhvInterpolatorPosition();
	pos->Append(new HKeyframeChannelLinear(0, 0, 0));
	pos->Append(new HKeyframeChannelLinear(0.3, 0, 0));
	pos->Append(new HKeyframeChannelLinear(0.3, .3, 0));
	pos->Append(new HKeyframeChannelLinear(0.0, 0.3, 0));
	pos->Append(new HKeyframeChannelLinear(0.0, 0.0, 0));

	HBhvTimeline *timeline = new HBhvTimeline();
	timeline->AddKeyframe(0);
	timeline->AddKeyframe(5);
	timeline->AddKeyframe(10);
	timeline->AddKeyframe(15);
	timeline->AddKeyframe(20);

	HBhvBehaviorManager *bm = m_pHView->GetModel()->GetBhvBehaviorManager();
	HBhvAnimation *move_0 = bm->AddAnimation("move_0", "SPATH:MODEL/cube_0", timeline, pos);
	move_0->SetTimeline(timeline);
	move_0->SetTargetByPath("SPATH:MODEL/cube_0");

	HBhvInterpolatorVertexMorph *vertMorph = new HBhvInterpolatorVertexMorph();

	//Add two different point sets
	vertMorph->AddMorphData(points, pcount_size, m_pHView->GetModel(), 0);
	points[0].x = -2; points[0].y = -2; points[0].z = -2; //modify a single point only for simplification
	vertMorph->AddMorphData(points, pcount_size, m_pHView->GetModel(), 1);

	//Toggle between the two data points
	vertMorph->Insert("0");
	vertMorph->Insert("1");
	vertMorph->Insert("0");
	vertMorph->Insert("1");
	vertMorph->Insert("0");

	//Add vertex morph as an interpolator
	move_0->AddInterpolator(vertMorph);

	bm->ScheduleAllAnimations(true);

	bm->Play();

	m_pHView->Update();

	delete[] points;
	delete[] face_list;
}
  1. Build and run the project.