add method

dynamic add(
  1. List<Mesh> items
)

Implementation

add(List<Mesh> items) {
  var objects = _objects,
      indicesByUUID = _indicesByUUID,
      paths = _paths,
      parsedPaths = _parsedPaths,
      bindings = _bindings,
      nBindings = bindings.length;

  Mesh? knownObject;
  var nObjects = objects.length;
  var nCachedObjects = nCachedObjects_;

  for (var i = 0, n = items.length; i != n; ++i) {
    var object = items[i], uuid = object.uuid;
    var index = indicesByUUID[uuid];

    if (index == null) {
      // unknown object -> add it to the ACTIVE region

      index = nObjects++;
      indicesByUUID[uuid] = index;
      objects.add(object);

      // accounting is done, now do the same for all bindings

      for (var j = 0, m = nBindings; j != m; ++j) {
        bindings[j].add(PropertyBinding(object, paths[j], parsedPaths[j]));
      }
    } else if (index < nCachedObjects) {
      knownObject = objects[index];

      // move existing object to the ACTIVE region

      var firstActiveIndex = --nCachedObjects, lastCachedObject = objects[firstActiveIndex];

      indicesByUUID[lastCachedObject.uuid] = index;
      objects[index] = lastCachedObject;

      indicesByUUID[uuid] = firstActiveIndex;
      objects[firstActiveIndex] = object;

      // accounting is done, now do the same for all bindings

      for (var j = 0, m = nBindings; j != m; ++j) {
        var bindingsForPath = bindings[j], lastCached = bindingsForPath[firstActiveIndex];

        var binding = bindingsForPath[index];

        bindingsForPath[index] = lastCached;

        binding ??= PropertyBinding(object, paths[j], parsedPaths[j]);

        bindingsForPath[firstActiveIndex] = binding;
      }
    } else if (objects[index] != knownObject) {
      print('three.AnimationObjectGroup: Different objects with the same UUID '
          'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
    } // else the object is already where we want it to be

  } // for arguments

  nCachedObjects_ = nCachedObjects;
}