How-To: Render different line pattern when line is obstructed and un-obstructed in HPS

Below is sample code on how to change line pattern when lines are obstructed vs un-obstructed.
Sample code only changes color.

// Setup scene

	HPS::SegmentKey lineSegment = GetCanvas().GetFrontView().GetAttachedModel().GetSegmentKey().Subsegment("lines");
    HPS::SegmentKey cubeSegment = GetCanvas().GetFrontView().GetAttachedModel().GetSegmentKey().Subsegment("cube");

    Point points[8] = { Point(0, 0, 0), Point(2, 0, 0), Point(2, 2, 0), Point(0, 2, 0),
                    Point(0, 0, 2), Point(2, 0, 2), Point(2, 2, 2), Point(0, 2, 2) };

    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 };

	cubeSegment.InsertShell(8, points, 30, faceList);
	cubeSegment.GetModellingMatrixControl().Translate(1, 1, 1);
	cubeSegment.GetMaterialMappingControl().SetFaceColor(HPS::RGBAColor(1.0f, 0.0f, 0.0f, 1.0f));
	cubeSegment.GetVisibilityControl().SetEverything(false).SetFaces(true);

    PointArray pointArray(3);

    // the points specified are the endpoints of the line segments
    pointArray[0] = Point(0, 0, 0);
    pointArray[1] = Point(10, 0, 0);
	lineSegment.InsertLine(pointArray);

	pointArray[1] = Point(0, 10, 0);
    lineSegment.InsertLine(pointArray);

    pointArray[1] = Point(0, 0, 10);
    lineSegment.InsertLine(pointArray);


	GetCanvas().UpdateWithNotifier().Wait();
	

// Setup Line pattern for obstructed lines
    HPS::LinePatternKit myLinePatternKitpk = HPS::LinePatternKit::GetDefault(HPS::LinePattern::Default::LongDash);

    GetCanvas().GetFrontView().GetPortfolioKey().DefineLinePattern("my_new_pattern", myLinePatternKitpk);
    GetCanvas().GetFrontView().SetRenderingMode(HPS::Rendering::Mode::HiddenLine);
	GetCanvas().GetFrontView().GetSegmentKey().GetHiddenLineAttributeControl().SetRenderFaces(true).SetVisibility(true).SetAlgorithm(HPS::HiddenLine::Algorithm::ZBuffer);
    GetCanvas().GetFrontView().GetSegmentKey().GetHiddenLineAttributeControl().SetSilhouetteCleanup(true).SetColor(HPS::RGBAColor(1, 1, 1));
	GetCanvas().GetFrontView().GetSegmentKey().GetHiddenLineAttributeControl().SetLinePattern("my_new_pattern");


// Setup Line pattern for un-obstructed lines
    lineSegment.GetVisibilityControl().SetLines(true);
	lineSegment.GetMaterialMappingControl().SetLineColor(HPS::RGBAColor(0, 0, 1));

	GetCanvas().UpdateWithNotifier().Wait();

1 Like