robot_parts.zip (222.7 KB)
I have a lot of similar questions that motivated me to post this article. Thanks to HOOPS Visualize’s scene graphic structure, I think it is fairly straightforward to build a POC application using the Sandbox. Here is an example with attached the 6 axis robot part files.
Step 1 : Create a Segment Structure
void CHPSView::OnUserCode2()
{
// Setup segments
HPS::SegmentKey newmodel = HPS::Database::CreateRootSegment();
newmodel.MoveTo(GetDocument()->GetModel().GetSegmentKey());
HPS::SegmentKey work = newmodel.Subsegment();
HPS::SegmentKey j1 = newmodel.Subsegment();
HPS::SegmentKey j2 = j1.Subsegment();
HPS::SegmentKey j3 = j2.Subsegment();
HPS::SegmentKey j4 = j3.Subsegment();
HPS::SegmentKey j5 = j4.Subsegment();
HPS::SegmentKey j6 = j5.Subsegment();
HPS::SegmentKey j7 = j6.Subsegment();
newmodel.GetVisibilityControl().SetLines(true);
Step 2 : Read robot parts in each separate segment
HPS::Stream::ImportOptionsKit ioOpts;
HPS::Stream::ImportNotifier notifier;
HPS::UTF8 filename = HPS::UTF8("work.hsf");
ioOpts.SetSegment(work);
notifier = HPS::Stream::File::Import(filename.GetBytes(), ioOpts);
work.GetModellingMatrixControl().Rotate(0, 0, 90);
work.GetModellingMatrixControl().Translate(900, 0, 0);
filename = HPS::UTF8 ("j1.hsf");
ioOpts.SetSegment(j1);
notifier = HPS::Stream::File::Import(filename.GetBytes(), ioOpts);
filename = HPS::UTF8("j2.hsf");
ioOpts.SetSegment(j2);
notifier = HPS::Stream::File::Import(filename.GetBytes(), ioOpts);
j2.GetModellingMatrixControl().Translate(0, 0, 380);
filename = HPS::UTF8("j3.hsf");
ioOpts.SetSegment(j3);
notifier = HPS::Stream::File::Import(filename.GetBytes(), ioOpts);
j3.GetModellingMatrixControl().Translate(150, 0, 300);
filename = HPS::UTF8("j4.hsf");
ioOpts.SetSegment(j4);
notifier = HPS::Stream::File::Import(filename.GetBytes(), ioOpts);
j4.GetModellingMatrixControl().Translate(0, 0, 800);
filename = HPS::UTF8("j5.hsf");
ioOpts.SetSegment(j5);
notifier = HPS::Stream::File::Import(filename.GetBytes(), ioOpts);
j5.GetModellingMatrixControl().Translate(220, 0, 90);
filename = HPS::UTF8("j6.hsf");
ioOpts.SetSegment(j6);
notifier = HPS::Stream::File::Import(filename.GetBytes(), ioOpts);
j6.GetModellingMatrixControl().Translate(500, 0, 0);
filename = HPS::UTF8("j7.hsf");
ioOpts.SetSegment(j7);
notifier = HPS::Stream::File::Import(filename.GetBytes(), ioOpts);
j7.GetModellingMatrixControl().Translate(70, 0, 0);
Step 3 : Move this robot by editing the matrix attributes of each segment
MatrixKit matrix, matrix_in, matrix_out;
matrix.RotateOffAxis(HPS::Vector(0,0,1), 30);
j2.ShowModellingMatrix(matrix_in);
matrix_out = matrix.Multiply(matrix_in);
j2.SetModellingMatrix(matrix_out);
matrix.Reset(); matrix.RotateOffAxis(HPS::Vector(0,1,0), 20);
j3.ShowModellingMatrix(matrix_in);
matrix_out = matrix.Multiply(matrix_in);
j3.SetModellingMatrix(matrix_out);
matrix.Reset(); matrix.RotateOffAxis(Vector(0, 1, 0), 20);
j4.ShowModellingMatrix(matrix_in);
matrix_out = matrix.Multiply(matrix_in);
j4.SetModellingMatrix(matrix_out);
matrix.Reset(); matrix.RotateOffAxis(Vector(1, 0, 0), -50);
j5.ShowModellingMatrix(matrix_in);
matrix_out = matrix.Multiply(matrix_in);
j5.SetModellingMatrix(matrix_out);
matrix.Reset(); matrix.RotateOffAxis(Vector(0, 1, 0), 40);
j6.ShowModellingMatrix(matrix_in);
matrix_out = matrix.Multiply(matrix_in);
j6.SetModellingMatrix(matrix_out);
matrix.Reset(); matrix.RotateOffAxis(Vector(1, 0, 0), 20);
j7.ShowModellingMatrix(matrix_in);
matrix_out = matrix_in.Multiply(matrix);
j7.SetModellingMatrix(matrix_out);
notifier.Wait(); //wait until loading is done
GetCanvas().GetFrontView().FitWorld();
GetCanvas().Update();
}