add method
Adds an arbitrary number of objects to this AnimationObjectGroup
.
Implementation
void add(List<Mesh> items) {
final objects = _objects,
indicesByUUID = _indicesByUUID,
paths = _paths,
parsedPaths = _parsedPaths,
bindings = _bindings,
nBindings = bindings.length;
late Object3D knownObject;
int nObjects = objects.length;
int nCachedObjects = nCachedObjects_;
for (int i = 0, n = items.length; i != n; ++i) {
final object = items[i], uuid = object.uuid;
int? 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 (int 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
final 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 (int j = 0, m = nBindings; j != m; ++j) {
final bindingsForPath = bindings[j],
lastCached = bindingsForPath[firstActiveIndex];
PropertyBinding? binding = bindingsForPath[index];
bindingsForPath[index] = lastCached;
binding ??= PropertyBinding(object, paths[j], parsedPaths[j]);
bindingsForPath[firstActiveIndex] = binding;
}
}
else if (objects[index] != knownObject) {
console.warning('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;
}