CRhinoCommand::result CCommandSampleLineMeshIntersect::RunCommand( const CRhinoCommandContext& context ) { CRhinoGetObject gm; gm.SetCommandPrompt(L"Select mesh to intersect"); gm.SetGeometryFilter(CRhinoGetObject::mesh_object); gm.GetObjects(1, 1); if (gm.CommandResult() != CRhinoCommand::success) return gm.CommandResult(); const ON_Mesh* mesh = gm.Object(0).Mesh(); if (0 == mesh) return CRhinoCommand::failure; CRhinoGetObject gl; gl.SetCommandPrompt(L"Select line to intersect with"); gl.SetGeometryFilter(CRhinoGetObject::curve_object); gl.SetGeometryAttributeFilter(CRhinoGetObject::open_curve); gl.EnablePreSelect(FALSE); gl.EnableDeselectAllBeforePostSelect(FALSE); gl.GetObjects(1, 1); if (gl.CommandResult() != CRhinoCommand::success) return gl.CommandResult(); const ON_Curve* curve = gl.Object(0).Curve(); if (0 == curve) return CRhinoCommand::failure; const ON_LineCurve* line_curve = ON_LineCurve::Cast(curve); if (0 == line_curve) { RhinoApp().Print(L"Not a line curve.\n"); return CRhinoCommand::nothing; } ON_3dPointArray points; points.Append(line_curve->m_line.from); points.Append(line_curve->m_line.to); const ON_MeshTree* mesh_tree = mesh->MeshTree(true); if (mesh_tree) { ON_SimpleArray<ON_CMX_EVENT> cmx; if (mesh_tree->IntersectPolyline(2, points.Array(), cmx)) { for (int i = 0; i < cmx.Count(); i++) { RhinoApp().Print(L"Intesection found at face index = %d.\n", cmx[i].m_M[0].m_face_index); CRhinoPointObject* point_object = context.m_doc.AddPointObject(cmx[i].m_M[0].m_P); if (point_object) point_object->Select(); } context.m_doc.Redraw(); } if (1 == cmx.Count()) RhinoApp().Print(L"1 intesection found.\n"); else RhinoApp().Print(L"%d intesections found.\n", cmx.Count()); } return CRhinoCommand::success; }
CRhinoCommand::result CCommandTestAnimator::RunCommand( const CRhinoCommandContext& context ) { // Select objects to animate CRhinoGetObject go; go.SetCommandPrompt( L"Select objects to animate" ); go.GetObjects( 1, 0 ); if( go.CommandResult() != success ) return go.CommandResult(); // Select path curve CRhinoGetObject gc; gc.SetCommandPrompt( L"Select path curve" ); gc.SetGeometryFilter( CRhinoGetObject::curve_object ); gc.SetGeometryAttributeFilter( CRhinoGetObject::open_curve ); gc.GetObjects( 1, 1 ); if( gc.CommandResult() != success ) return gc.CommandResult(); const ON_Curve* crv = gc.Object(0).Curve(); if( 0 == crv ) return failure; // Create an array of normalized curve parameters ON_SimpleArray<double> t_array( m_max_steps ); t_array.SetCount( m_max_steps ); int i = 0; for( i = 0; i < m_max_steps; i++ ) { double t = (double)i / ( (double)m_max_steps - 1 ); t_array[i] = t; } // Get the real parameters along the curve if( !crv->GetNormalizedArcLengthPoints(m_max_steps, t_array.Array(), t_array.Array()) ) return failure; // Create our dialog box with animatin slider... CTestAnimatorDlg dlg( CWnd::FromHandle(RhinoApp().MainWnd()) ); dlg.m_max_steps = m_max_steps; dlg.m_start = crv->PointAtStart(); // Get points along curve for( i = 0; i < m_max_steps; i++ ) { ON_3dPoint pt = crv->PointAt( t_array[i] ); dlg.m_points.Append( pt ); } // Hide objects and add them to callback's object array for( i = 0; i < go.ObjectCount(); i++ ) { CRhinoObjRef ref = go.Object(i); context.m_doc.HideObject( ref ); dlg.m_conduit.m_objects.Append( ref.Object() ); } // Do the dialog INT_PTR rc = dlg.DoModal(); // If OK was pressed, transform the objects. // Otherwise, just unhide them. for( i = 0; i < go.ObjectCount(); i++ ) { CRhinoObjRef ref = go.Object(i); context.m_doc.ShowObject( ref ); if( rc == IDOK ) { ON_Xform xform = dlg.m_conduit.m_xform; context.m_doc.TransformObject( ref, xform ); } } context.m_doc.Redraw( CRhinoView::regenerate_display_hint ); return CRhinoCommand::success; }
CRhinoCommand::result CCommandTestUVMesh::RunCommand( const CRhinoCommandContext& context ) { bool bDeleteInput = false; CRhinoGetObject go; go.SetCommandPrompt(L"Select untrimmed surface"); go.AddCommandOptionInteger(RHCMDOPTNAME(L"U"), &m_U, 0, 2); go.AddCommandOptionInteger(RHCMDOPTNAME(L"V"), &m_V, 0, 2); go.AddCommandOptionToggle(RHCMDOPTNAME(L"DeleteInput"), RHCMDOPTVALUE(L"No"), RHCMDOPTVALUE(L"Yes"), bDeleteInput, &bDeleteInput); go.SetGeometryFilter(CRhinoGetObject::surface_object); go.SetGeometryAttributeFilter(CRhinoGetObject::untrimmed_surface); CRhinoGet::result rs = CRhinoGet::no_result; while (CRhinoGet::cancel != rs && CRhinoGet::nothing != rs && CRhinoGet::object != rs) rs = go.GetObjects(1,1); if (CRhinoGet::cancel == rs) return CRhinoCommand::cancel; if (0 == go.ObjectCount()) return CRhinoCommand::failure; const CRhinoObject* pObj = go .Object(0).Object(); if (0 == pObj) return CRhinoCommand::failure; const ON_BrepFace* pBrepFace = go.Object(0).Face(); if (0 == pBrepFace) return CRhinoCommand::failure; const ON_Surface* pSurf = pBrepFace->SurfaceOf(); if (0 == pSurf) return CRhinoCommand::failure; ON_SimpleArray<double>UArray(m_U+1); ON_SimpleArray<double>VArray(m_V+1); double UDist, VDist; UDist = (pSurf->Domain(0).m_t[1]-pSurf->Domain(0).m_t[0])/m_U; VDist = (pSurf->Domain(1).m_t[1]-pSurf->Domain(1).m_t[0])/m_V; int i; for (i=0; i <= m_U; i++) UArray.Append(pSurf->Domain(0).m_t[0] + i*UDist); for (i=0; i <= m_V; i++) VArray.Append(pSurf->Domain(1).m_t[0] + i*VDist); //If m_U or m_V are large then there can be a slight difference between //pSurf->Domain(0).m_t[0] + (m_U-1)*UDist and pSurf->Domain(0).m_t[1] //ON_MeshSurface requires it to be less than or equal to pSurf->Domain(0).m_t[1] //05/24/06 TimH Fix for RR21194 double* d = UArray.Last(); if (pSurf->Domain(0).m_t[1] < *d) *d = pSurf->Domain(0).m_t[1]; d = VArray.Last(); if (pSurf->Domain(1).m_t[1] < *d) *d = pSurf->Domain(1).m_t[1]; ON_Mesh* pMeshOut = ON_MeshSurface(*pSurf, m_U+1, UArray.Array(), m_V+1, VArray.Array()); if (0 == pMeshOut) return CRhinoCommand::failure; CRhinoMeshObject* pMeshObj = new CRhinoMeshObject(pObj->Attributes()); if (0 == pMeshObj) { delete pMeshOut; return CRhinoCommand::failure; } pMeshObj->SetMesh(pMeshOut); if (true == bDeleteInput) context.m_doc.ReplaceObject(pObj, pMeshObj); else context.m_doc.AddObject(pMeshObj); context.m_doc.Redraw(); return CRhinoCommand::success; }