mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
101.91k stars 35.32k forks source link

Editor: Potential name conflicts when exporting multiple animated assets with `GLTFExporter`. #25179

Open fengxinming opened 1 year ago

fengxinming commented 1 year ago

Description

This is part of error stacks

Uncaught (in promise) RangeError: Invalid array length
    at getMinMax (GLTFExporter.js:248:8)
    at GLTFWriter.processAccessor (GLTFExporter.js:1038:18)
    at GLTFWriter.processAnimation (GLTFExporter.js:1857:18)
    at GLTFWriter.processInput (GLTFExporter.js:2140:9)
    at GLTFWriter.write (GLTFExporter.js:453:8)
    at GLTFExporter.parse (GLTFExporter.js:113:10)
    at UIRow.<anonymous> (Menubar.File.js:252:12)

Reproduction steps

  1. git clone https://github.com/mrdoob/three.js.git
  2. npm install
  3. npm run dev
  4. after editor server running then import three.js/examples/models/gltf/Horse.glb and three.js/examples/models/gltf/Stork.glb into the editor scene
  5. click file menu to export a glb file
  6. open chrome dev tool to see error stacks

Code

none

Live example

none

Screenshots

image

Version

0.147.0

Device

Desktop

Browser

Chrome

OS

MacOS

Mugen87 commented 1 year ago

I can reproduce. The error appears with r122 for the first time. At that time, the editor starts to support animation export with GLTFExporter (#20454). So the bug probably already existed in the exporter but did not become apparent.

Interestingly, the error only occurs with two or more morphed assets. Non-animated assets work as expected as well as a the combination of a one morphed and one skinned mesh.

donmccurdy commented 1 year ago

I expect that this issue (#25179) and #25198 have the same cause. three.js animations reference their targets by a unique name. Importing two assets into the Editor, then exporting, may cause the animation from one model to be in conflict with another. This is fine in normal usage (scope an AnimationMixer to each model) but would require renaming objects for export in the Editor.

GLTFExporter probably cannot fix this; given an AnimationClip list with non-unique names, it's too late to figure out which clip goes where. Maybe this is something we fix in the Editor by prefixing clip names, or by warning users to rename things, or ... ?