Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:meshbooleanintersection [2015/09/14] (current)
Line 1: Line 1:
 +====== Mesh Boolean Intersection ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates how to intersect meshes.//
 +
 +===== C++ =====
 +<code c++>
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  int i = 0;
 +
 +  CRhinoGetObject go;
 +  go.SetCommandPrompt( L"​Select first set of meshes"​ );
 +  go.SetGeometryFilter( CRhinoGetObject::​mesh_object );
 +  go.GetObjects( 1, 0 );
 +  if( go.CommandResult() != CRhinoCommand::​success )
 +    return go.CommandResult();​
 +
 +  ON_SimpleArray<​const ON_Mesh*>​ InMeshes0( go.ObjectCount() );
 +  for( i = 0; i < go.ObjectCount();​ i++ )
 +  {
 +    const ON_Mesh* mesh = go.Object(i).Mesh();​
 +    if( 0 == mesh )
 +      return CRhinoCommand::​failure;​
 +    InMeshes0.Append( mesh );
 +  }
 +
 +  go.SetCommandPrompt( L"​Select second set of meshes"​ );
 +  go.EnablePreSelect( false );
 +  go.EnableDeselectAllBeforePostSelect( false );
 +  go.GetObjects( 1, 0 );
 +  if( go.CommandResult() != CRhinoCommand::​success )
 +    return go.CommandResult();​
 +
 +  ON_SimpleArray<​const ON_Mesh*>​ InMeshes1( go.ObjectCount() );
 +  for( i = 0; i < go.ObjectCount();​ i++ )
 +  {
 +    const ON_Mesh* mesh = go.Object(i).Mesh();​
 +    if( 0 == mesh )
 +      return CRhinoCommand::​failure;​
 +    InMeshes1.Append( mesh );
 +  }
 +
 +  double intersection_tolerance = ON_SQRT_EPSILON * 10;
 +  double overlap_tolerance = ON_SQRT_EPSILON * 10;
 +
 +  ON_SimpleArray<​ON_Mesh*>​ OutMeshes;
 +  bool bSomethingHappened = false;
 +  bool rc = RhinoMeshBooleanIntersection(
 +        InMeshes0, ​
 +        InMeshes1,
 +        intersection_tolerance,​
 +        overlap_tolerance, ​
 +        &​bSomethingHappened, ​
 +        OutMeshes
 +        );
 +
 +  if( !rc )
 +  {
 +    RhinoApp().Print( L"No mesh intersections found.\n"​ );
 +    return CRhinoCommand::​nothing;​
 +  }
 +
 +  for( i = 0; i < OutMeshes.Count();​ i++ )
 +  {
 +    CRhinoMeshObject* mesh_obj = new CRhinoMeshObject();​
 +    mesh_obj->​SetMesh( OutMeshes[i] );
 +    ​
 +    OutMeshes[i] = 0;
 +    ​
 +    if( context.m_doc.AddObject(mesh_obj) )
 +      mesh_obj->​Select( true );
 +    else
 +      delete mesh_obj;
 +  }
 +  ​
 +  context.m_doc.Redraw();​
 +
 +  return CRhinoCommand::​success;​
 +}
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/meshbooleanintersection.txt ยท Last modified: 2015/09/14 (external edit)