Moves the specified Properties from the source
Document to the target Document, and removes them from the source.
Dependencies of the source properties will be copied into the
target, but not removed from the source. Returns a Map from source
properties to their counterparts in the target Document.
Example:
import { moveToDocument, prune } from'@gltf-transform/functions';
// Move all materials from sourceDocument to targetDocument.const map = moveToDocument(targetDocument, sourceDocument, sourceDocument.listMaterials());
// Find the new counterpart of `sourceMaterial` in the target Document.const targetMaterial = map.get(sourceMaterial);
// (Optional) Remove any resources (like Textures) that may now be unused// in the source Document after their parent Materials have been moved.await sourceDocument.transform(prune());
Moving a Mesh, Animation, or another resource depending on
a Buffer will create a copy of the source Buffer in the target
Document. If the target Document should contain only one Buffer, call
unpartition after moving properties.
Repeated use of moveToDocument may create multiple copies of some
resources, particularly shared dependencies like Textures or
Accessors. While duplicates can be cleaned up with
dedup, it is also possible to prevent duplicates by creating and
reusing the same resolver for all calls to moveToDocument:
If the transferred properties include ExtensionProperties,
the associated Extensions must be added to the target
Document first:
for (const sourceExtension of source.getRoot().listExtensionsUsed()) {
const targetExtension = target.createExtension(sourceExtension.constructor);
if (sourceExtension.isRequired()) targetExtension.setRequired(true);
}
Moves the specified Properties from the source Document to the target Document, and removes them from the source. Dependencies of the source properties will be copied into the target, but not removed from the source. Returns a Map from source properties to their counterparts in the target Document.
Example:
import { moveToDocument, prune } from '@gltf-transform/functions'; // Move all materials from sourceDocument to targetDocument. const map = moveToDocument(targetDocument, sourceDocument, sourceDocument.listMaterials()); // Find the new counterpart of `sourceMaterial` in the target Document. const targetMaterial = map.get(sourceMaterial); // (Optional) Remove any resources (like Textures) that may now be unused // in the source Document after their parent Materials have been moved. await sourceDocument.transform(prune());
Moving a Mesh, Animation, or another resource depending on a Buffer will create a copy of the source Buffer in the target Document. If the target Document should contain only one Buffer, call unpartition after moving properties.
Repeated use of
moveToDocument
may create multiple copies of some resources, particularly shared dependencies like Textures or Accessors. While duplicates can be cleaned up with dedup, it is also possible to prevent duplicates by creating and reusing the same resolver for all calls tomoveToDocument
:import { moveToDocument, createDefaultPropertyResolver } from '@gltf-transform/functions'; const resolve = createDefaultPropertyResolver(targetDocument, sourceDocument); // Move materials individually, without creating duplicates of shared textures. moveToDocument(targetDocument, sourceDocument, materialA, resolve); moveToDocument(targetDocument, sourceDocument, materialB, resolve); moveToDocument(targetDocument, sourceDocument, materialC, resolve);
If the transferred properties include ExtensionProperties, the associated Extensions must be added to the target Document first:
for (const sourceExtension of source.getRoot().listExtensionsUsed()) { const targetExtension = target.createExtension(sourceExtension.constructor); if (sourceExtension.isRequired()) targetExtension.setRequired(true); }
Root properties cannot be moved.
TextureInfo properties cannot be given in the property list, but are handled automatically when moving a Material.
To copy properties without removing them from the source Document, see copyToDocument.