atteneder / glTFast

Efficient glTF 3D import / export package for Unity
Other
1.23k stars 250 forks source link

glTF exported from Cinema 4D doesn't import at runtime #501

Closed pzhine closed 1 year ago

pzhine commented 1 year ago

Describe the bug I have a glTF exported from Cinema 4D that works fine with the editor import but not with the runtime import. I see no errors or messages in the console when running the runtime import, but the game object that should contain the model is simply empty.

Files https://cdn01.elysium.ar/sim/troubleman.glb

To Reproduce Steps to reproduce the behavior:

  1. Drag the GLB file into the Assets panel in Unity
  2. Model imports correctly
  3. Add the following to the Start method of a game object:
    var gltf = gameObject.AddComponent<GLTFast.GltfAsset>();
    gltf.url = "https://cdn01.elysium.ar/sim/troubleman.glb";
  4. Run the game
  5. Nothing is loaded into the game object and nothing is logged to the console

Desktop (please complete the following information):

pzhine commented 1 year ago

I figured it out. The glTF had no defaultSceneIndex. As stated in the comments for instantiateMainScene: If the main scene index is not set, it instantiates nothing (as defined in the glTF 2.0 specification).

The updated code below works:

if (gltfImporter.defaultSceneIndex.HasValue)
{ 
    gltfImporter.InstantiateMainScene(instantiator);
}
else
{
    for (int sceneId = 0; sceneId < gltfImporter.sceneCount; sceneId++) {
        gltfImporter.InstantiateScene(instantiator, sceneId);
    }
}