How to use the @gltf-transform/core.GLTFUtil.addBuffer function in @gltf-transform/core

To help you get started, we’ve selected a few @gltf-transform/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github donmccurdy / glTF-Transform / packages / split / src / split.ts View on Github external
json.bufferViews.forEach((bufferView, bufferViewIndex) => {
      if (bufferViewMap[bufferViewIndex] !== meshName) return;

      const bufferData = container.getBuffer(bufferView.buffer);
      const bufferViewData = bufferData.slice(bufferView.byteOffset, bufferView.byteOffset + bufferView.byteLength);

      const newBufferURI = `${meshName}.bin`;
      const newBuffer = container.json.buffers.find((buffer) => buffer.uri === newBufferURI)
        || GLTFUtil.addBuffer(container, meshName, new ArrayBuffer(0));
      const newBufferIndex = container.json.buffers.indexOf(newBuffer);

      const newBufferView = GLTFUtil.addBufferView(container, bufferViewData, newBufferIndex);
      const newBufferViewIndex = container.json.bufferViews.indexOf(newBufferView);
      container.json.accessors.forEach((accessor) => {
        if (accessor.bufferView === bufferViewIndex) {
          accessor.bufferView = newBufferViewIndex;
        }
      })

      removedBufferViews.push(bufferViewIndex);
    });