Good day. I am new to Hoops Visualize. I am faced with a problem that I cannot solve. The task is to check if the bounded polygon (or bounded plane) intersects the shell (3D object).
I had two ideas for solving this problem:
- Use the HPS.Database.SelectByShell () method which was in the Collision detection example HOOPS Visualize HPS Documentation
This is how I create a shell:
geometrySegment.GetDrawingAttributeControl (). SetOverlay (Drawing.Overlay.Default);
int [] face_list = new int [] {4, 0, 1, 2, 3};
geometrySegment.InsertShell (points.ToArray (), face_list);
geometrySegment.GetVisualEffectsControl (). SetSimpleReflection (false) .SetSimpleShadow (false) .SetSilhouetteEdgesEnabled (false) .SetPostProcessEffectsEnabled (false);
geometrySegment.GetBoundingControl (). SetExclusion (true);
geometrySegment.SetModellingMatrix (matrix);
geometrySegment.SetIsHelperGeometryRecursively (true);
Here is my main code:
SelectionOptionsKit selectionOptions = new SelectionOptionsKit ();
selectionOptions.SetAlgorithm (Selection.Algorithm.Analytic);
selectionOptions.SetLevel (Selection.Level.Entity);
selectionOptions.SetScope (windowsSegmentKey);
SearchResults searchShellResults = new SearchResults ();
Search.Type [] types = new Search.Type [] {Search.Type.Shell};
// geometrySegment is a segment to which I added a shell based on polygon points.
geometrySegment.Find (types, Search.Space.Subsegments, out searchShellResults);
SearchResultsIterator iterator = searchShellResults.GetIterator ();
while (iterator.IsValid ())
{
Key key = iterator.GetItem ();
if (key.Type () == HPS.Type.ShellKey)
{
ShellKey shellKey = new ShellKey (key);
// Six objects are constantly returned
ulong numSelectedItems = Database.SelectByShell (shellKey, selectionOptions, out SelectionResults selectionResults);
SelectionResultsIterator srIterator = selectionResults.GetIterator ();
while (srIterator.IsValid ())
{
SelectionItem selectionItem = srIterator.GetItem ();
selectionItem.ShowSelectedItem (out Key resultKey);
var typeOfObj = resultKey.Type ();
if (key.Type () == HPS.Type.ShellKey)
{
}
srIterator.Next ();
}
}
iterator.Next ();
}
In numSelectedItems, six objects are always returned, although there is nothing on the stage except one shell for which I am looking for an intersection. I don’t know what I’m doing wrong. Please tell me, I will be grateful for any help.
- Use a cutting plane to define the intersection. I used the Extracting cutting plane geometry example at HOOPS Visualize HPS Documentation Here is my code:
// My cutting plane
Plane planeRes1 = new Plane (resultGearPoints);
workItemSegmentKey.GetVisibilityControl (). SetCutGeometry (true);
workItemSegmentKey.GetCuttingSectionAttributeControl (). SetCappingLevel (CuttingSection.CappingLevel.Segment) .SetCuttingLevel (CuttingSection.CuttingLevel.Local);
workItemSegmentKey.GetMaterialMappingControl (). SetCutEdgeColor (new RGBAColor (1, 0, 0));
workItemSegmentKey.InsertCuttingSection (planeRes1);
CutGeometryGatheringOptionsKit opt = new CutGeometryGatheringOptionsKit ();
opt.SetLevel (CuttingSection.GatheringLevel.Segment);
KeyPath path = new KeyPath ();
path.Append (windowsSegmentKey);
ulong cap_count = path.GatherCutGeometry (windowsSegmentKey.Subsegment ("caps"), opt);
if (cap_count> 0)
{
// my logic
}
When the workItemSegmentKey object was crossed by the cutting plane, a part of the object was cut off (everything is as it should be), but when the path.GatherCutGeometry () function was called to see how many objects would be cut off, cap_count is always equal to 0.
Tell me, I was thinking in the right direction when solving this problem. I would be very grateful for any help.
Best regards, Dmitry