donmccurdy / glTF-Transform

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

Center of model changing #1308

Closed dennis-modelsend closed 3 months ago

dennis-modelsend commented 3 months ago

Describe the bug Loading a model with GLTFLoader.load directly vs loading a model through gltf-transform then GLTFLoader.parse generates a different center for the model (according to Box3().setFromObject(model).getCenter())

To Reproduce

  1. Load this model through gltf-transform then GLTFLoader.parse https://we.tl/t-BgNDHZ1xrZ
  2. Compare center to when loading with GLTFLoader.load

Expected behavior Center should remain consistent

Versions:

donmccurdy commented 3 months ago

@dennis-modelsend could you expand on what you mean by "load this model through gltf-transform"? Do you mean simply read/write without changes? Testing that on the CLI:

gltf-transform cp input.glb output.glb

The scene has the same bounds before and after:

# name rootName bboxMin bboxMax
0 Sketchfab_Scene Sketchfab_model -47.82007, -47.82007, -79.41164 47.82007, 47.82007, -1.26045
# name rootName bboxMin bboxMax
0 Sketchfab_Scene Sketchfab_model -47.82007, -47.82007, -79.41164 47.82007, 47.82007, -1.26045

To investigate this I'll need to be able to reproduce it, and knowing the version of glTF Transform used, and complete steps to reproduce, would be helpful.

dennis-modelsend commented 3 months ago

@donmccurdy I use threejs FileLoader then use @gltf-transform/core WebIO.readBinary and writeBinary without any transforms

dennis-modelsend commented 3 months ago

Using 4.0.0-alpha.8

donmccurdy commented 3 months ago

@dennis-modelsend I've had a quick go at this, and I'm not immediately able to reproduce any issue. If you can share full reproduction steps — a demo, or complete code — I can investigate further. I'm happy to spend time investigating the bug, but would prefer not to spend time guessing what your code looks like. Occasionally, the cause of a bug can be something as non-obvious as the bundler configuration.

dennis-modelsend commented 3 months ago

Found the issue while writing the demo, I was only calling updateMatrixWorld on only one of the objects ... thank you for the help Don

donmccurdy commented 3 months ago

@dennis-modelsend ah sorry, that's the least fun kind of bug! Note that THREE.GLTFLoader in r163 will start doing updateMatrixWorld automatically before returning the scene: