donmccurdy / glTF-Transform

glTF 2.0 SDK for JavaScript and TypeScript, on Web and Node.js.
https://gltf-transform.dev
MIT License
1.43k stars 150 forks source link

Support KHR_animation_pointer #1448

Open heeen opened 4 months ago

heeen commented 4 months ago

Describe the bug importing a file with KHR_animation_pointer and re-serializing it breaks said extension

To Reproduce WebIO with ALL_EXTENSIONS registered import document through io.readJSON export document through io.writeJSON

Expected behavior it is expected that the gltf-transform without explicit changes is idempotent.

original file contains

"extensionsUsed": [
    "KHR_animation_pointer"
  ],

and animations

  "animations": [
    {
      "channels": [
        {
          "sampler": 0,
          "target": {
            "path": "pointer",
            "extensions": {
              "KHR_animation_pointer": {
                "pointer": "/nodes/2/rotation"
              }
            }
          }
        }
      ],
      "samplers": [
        {
          "input": 13,
          "interpolation": "LINEAR",
          "output": 14
        }
      ],
      "name": "SpinPlatform"
    },
    {
      "channels": [
        {
          "sampler": 0,
          "target": {
            "path": "pointer",
            "extensions": {
              "KHR_animation_pointer": {
                "pointer": "/nodes/5/rotation"
              }
            }
          }
        },
        {
          "sampler": 1,
          "target": {
            "path": "pointer",
            "extensions": {
              "KHR_animation_pointer": {
                "pointer": "/nodes/3/translation"
              }
            }
          }
        }
      ],

resulting file does not contain extensionsUsed. animations look like:

"animations": [
        {
            "name": "SpinPlatform",
            "samplers": [
                {
                    "input": 13,
                    "output": 14,
                    "interpolation": "LINEAR"
                }
            ],
            "channels": [
                {
                    "sampler": 0,
                    "target": {
                        "path": "pointer"
                    }
                }
            ]
        },
        {
            "name": "animate the inner box",
            "samplers": [
                {
                    "input": 15,
                    "output": 16,
                    "interpolation": "LINEAR"
                },
                {
                    "input": 17,
                    "output": 18,
                    "interpolation": "LINEAR"
                }
            ],
            "channels": [
                {
                    "sampler": 0,
                    "target": {
                        "path": "pointer"
                    }
                },
                {
                    "sampler": 1,
                    "target": {
                        "path": "pointer"
                    }
                }
            ]
        }
    ],

Versions:

heeen commented 4 months ago

source file boxanimated-source.zip transformed file archive(1).zip

donmccurdy commented 4 months ago

Hi @heeen! glTF Transform provides official implementations of the extensions listed here:

https://gltf-transform.dev/extensions

For any others, you'd need to create and register an implementation of that extension. All provided extensions are implemented in a separate package (@gltf-transform/extensions) to make sure that third-party extensions also have access to necessary APIs. I should caution that KHR_animation_pointer is not a trivial extension to support. Loosely related: