Skip to content

How to get the positions and indices of a list of meshes? #1170

Answered by donmccurdy
krispya asked this question in Q&A
Discussion options

You must be logged in to vote

A good starting point might be:

  1. remove all materials
  2. remove all non-essential vertex attributes
  3. flatten the node hierarchy
  4. join meshes
  5. retrieve vertex positions and indices

Untested code, but it should be something like:

import { prune, flatten, join } from '@gltf-transform/functions';

// 1. remove all materials
for (const material of document.getRoot().listMaterials()) {
  material.dispose();
}

// 2. remove all non-essential vertex attributes
for (const mesh of document.getRoot().listMeshes()) {
  for (const prim of mesh.listPrimitives()) {
    for (const semantic of prim.listSemantics()) {
      if (semantic !== 'POSITION') {
        prim.setAttribute(semantic, null);
      }
    }
  }

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@donmccurdy
Comment options

@krispya
Comment options

@donmccurdy
Comment options

@krispya
Comment options

@donmccurdy
Comment options

Answer selected by krispya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants