mergeDocuments

  • mergeDocuments(target: Document, source: Document, resolve?: PropertyResolver<Property>): Map<Property, Property>
  • Merges contents of source Document into target Document, without modifying the source. Any extensions missing from the target will be added Scenes and Buffers are not combined — the target Document may contain multiple Scenes and Buffers after this operation. These may be cleaned up manually (see unpartition), or document contents may be merged more granularly using copyToDocument.

    Example:

    import { mergeDocuments, unpartition } from '@gltf-transform/functions';
    
    // Merge contents of sourceDocument into targetDocument.
    mergeDocuments(targetDocument, sourceDocument);
    
    // (Optional) Remove all but one Buffer from the target Document.
    await targetDocument.transform(unpartition());
    

    To merge several Scenes into one:

    import { mergeDocuments } from '@gltf-transform/functions';
    
    const map = mergeDocuments(targetDocument, sourceDocument);
    
    // Find original Scene.
    const sceneA = targetDocument.getRoot().listScenes()[0];
    
    // Find counterpart of the source Scene in the target Document.
    const sceneB = map.get(sourceDocument.getRoot().listScenes()[0]);
    
    // Create a Node, and append source Scene's direct children.
    const rootNode = targetDocument.createNode()
        .setName('SceneB')
        .setPosition([10, 0, 0]);
    for (const node of sceneB.listChildren()) {
        rootNode.addChild(node);
    }
    
    // Append Node to original Scene, and dispose the empty Scene.
    sceneA.addChild(rootNode);
    sceneB.dispose();
    
Function symbol, where the argument and output are a box labeled 'glTF'.

Made by Don McCurdy. Documentation built with greendoc and published under Creative Commons Attribution 3.0.