Notifications
Clear all

[Closed] Creating many objects slowdown

Hi good people!

Im writing an importer that creates a lot of objects in the scene, and as I create more and more objects the creation process for each new object gets slower.
It has been a long time since I used max, so Im hoping there is something trivial I forgot. Im using C#.

The object count is usually around 50K objects, but the slowdown is noticable when creating only 5K objects as well. In other applications this only takes a second, but max takes much longer, so Im probably doing something wrong

Here is the gist of what Im doing:


                global.COREInterface13.DisableSceneRedraw();
                global.COREInterface13.EnableUndo(false);
                
                foreach (Curve3D curve in curves)
                {
        // A simple wrapper that reads point data and creates a spline
                    var curveWrapper = new CurveWrapper(global, curve.Geometry);
                    curveWrapper.Create(objType, new WStr(objType), color);
                }
                global.COREInterface13.EnableUndo(true);
                global.COREInterface13.EnableSceneRedraw();
            }

And this is how I create the spline geometry


protected override INode CreateGeometry()
{
            ShapeObject shapeObject = Factory.CreateShapeObject(ClassIds.SplineShape);
            SplineShape splineShape = SplineShape._CastFrom(shapeObject);
            BezierShape bezierShape = splineShape.GetShape();
            Spline3D spline = bezierShape.NewSpline();
            foreach (float[] point in _curve.PointsAsArray)
            {
                Point3 point3 = new Point3(point[0], point[1], point[2]);
                spline.AddKnot(new SplineKnot(
                    SplineKnot.KnotType.CornerKnot, SplineKnot.LineType.LineLineType, point3, point3, point3));
            }
            spline.SetClosed(false);
            bezierShape.UpdateSels();
            bezierShape.InvalidateGeomCache();
            return Factory.CreateNode(shapeObject);            
}