Hi;
what is wrong with my code, Why is the point has transform going in the wrong direction ?
This is my file LVI192067P.3dm (396.0 KB)
CRhinoGetObject go;
go.SetCommandPrompt(L"SELECT POINT");
go.SetGeometryFilter(CRhinoGetObject::point_object);
go.GetObjects(1, 1);
if (go.CommandResult() != CRhinoCommand::success)
return go.CommandResult();
CRhinoGetObject go1;
go1.SetCommandPrompt(L"SELECT MESH");
go1.SetGeometryFilter(CRhinoGetObject::mesh_object);
go1.GetObjects(1, 1);
if (go1.CommandResult() != CRhinoCommand::success)
{
return go1.CommandResult();
}
ON_MESH_POINT point;
ON_3dVector nor = ON_UNSET_POINT;
ON_Mesh* mesh = const_cast<ON_Mesh*>(go1.Object(0).Mesh());
if (!mesh->HasFaceNormals())
mesh->ComputeFaceNormals();
mesh->GetClosestPoint(go.Object(0).m_point, &point);
if (point.m_ci.m_type == ON_COMPONENT_INDEX::meshtop_vertex)
{
ON_SimpleArray<int> faces;
const ON_MeshTopology& top = mesh->Topology();
int topvi = top.m_topv_map[point.m_ci.m_index];
const ON_MeshTopologyVertex& topvert = top.m_topv[topvi];
for (int i = 0; i < topvert.m_tope_count; i++)
{
const ON_MeshTopologyEdge& topedge = top.m_tope[topvert.m_topei[i]];
for (int j = 0; j < topedge.m_topf_count; j++)
faces.Append(topedge.m_topfi[j]);
}
faces.QuickSort(&ON_CompareIncreasing<int>);
int fi = -1;
for (int i = faces.Count() - 1; i >= 0; i--)
{
if (faces[i] == fi)
faces.Remove(i);
else
fi = faces[i];
}
ON_3dVector ve_s = mesh->m_FN[faces[0]];
for (int i = 1; i < faces.Count(); i++)
{
ON_3dVector ve_e = mesh->m_FN[faces[i]];
ve_s = ve_s + ve_e;
}
ve_s.Unitize();
ON_3dPoint point_tranform(point.m_P);
point_tranform.Transform(ON_Xform::TranslationTransformation(ve_s));
RhinoApp().ActiveDoc()->AddPointObject(point_tranform);
}
RhinoApp().ActiveView()->Redraw();
return success;