Skip to content
On this page

Deep Copy and New Copy

The Simplygon API provides two important copy methods. The DeepCopy method used to copy one object to another and NewCopy which does a deep copy of the object into a new object which is returned.

The deep and new copy methods are present in classes derived from IArray and ISceneNode, the IGeometryData class, the IPackedGeometryData class and the IImageData class. In some cases these functions take a bool argument; this bool argument determines whether to copy the actual data or just the object structure (fields, color depth, etc) without actually populating the data arrays.

The IMatrix4x4 class contains only the DeepCopy method.

Notice that any attached Observer from the original object will not be attached to the new copy.

Example - How to use deep and new copy

cpp
void DeepCopyNewCopy()
{
    spRealArray arr = sg->CreateRealArray();
    spRealArray arr_ids = sg->CreateRealArray();
    // ... some work done on arr_ids ...
    // Create a new copy of arr_ids.
    spRealArray arr_ids_cpy = arr_ids->NewCopy(true);
    //  elements of arr_ids into arr.
    arr->DeepCopy(arr_ids);
}
csharp
void DeepCopyNewCopy()
{
    spRealArray arr = sg.CreateRealArray();
    spRealArray arr_ids = sg.CreateRealArray();
    // ... some work done on arr_ids ...
    // Create a new copy of arr_ids.
    spRealArray arr_ids_cpy = arr_ids.NewCopy(true);
    //  elements of arr_ids into arr.
    arr.DeepCopy(arr_ids);
}
python
def deep_copy_new_copy(sg):
    arr = sg.CreateRealArray()
    arr_ids = sg.CreateRealArray()
    # ... some work done on arr_ids ...
    # Create a new copy of arr_ids.
    arr_ids_cpy = arr_ids.NewCopy(True)
    # elements of arr_ids into arr.
    arr.DeepCopy(arr_ids)