On 08/09/2016 at 02:29, xxxxxxxx wrote:
Hello,
the easiest and safest way to handle NGons is not to use the low level API but to use the Modeling library instead. This library takes care that all the data is handled correctly. Here is a simple example:
// create modeling object
AutoAlloc<Modeling> modeling;
if (!modeling)
return false;
PolygonObject* polyObject = PolygonObject::Alloc(0, 0);
if (polyObject == nullptr)
return true;
// set point count to 10
const Int32 pointCount = 10;
// resize polygon object
polyObject->ResizeObject(pointCount, 0);
// init polygon object for modeling
modeling->InitObject(polyObject);
Float64 cos;
Float64 sin;
Float64 angle = 0.0;
const Float64 step = 2 * PI / Float64(pointCount);
// prepare array for the indices
maxon::BaseArray<Int32> ngonPoints;
// create points for the polygon object
for (Int32 i = 0; i < pointCount; ++i)
{
// calculate coordinates
maxon::SinCos(angle, sin, cos);
const Vector coords = Vector(cos * 100.0, sin * 100.0, 0);
// set coordinates for the given point
modeling->SetPoint(polyObject, i, coords);
// save index for later
ngonPoints.Append(i);
// next step
angle = angle + step;
}
// create Ngon
modeling->CreateNgon(polyObject, ngonPoints.GetFirst(), (Int32)ngonPoints.GetCount());
// commit the modeling transformation before inserting the polygon object into the document
if (!modeling->Commit())
return false;
// add the polygon object to the document
doc->InsertObject(polyObject, nullptr, nullptr);
EventAdd();
best wishes,
Sebastian