stride3d / stride

Stride (formerly Xenko), a free and open-source cross-platform C# game engine.
https://stride3d.net
MIT License
6.62k stars 955 forks source link

[Model] Unable to import GLTF json and GLB binary 3d Model assets #603

Open acampbellb opened 4 years ago

acampbellb commented 4 years ago

Release Type: Official Release/GitHub

Version: 3.2

Platform(s): Windows

Describe the bug Unable to create a 3D Model asset from a GLTF file (GLTF json form or GLB binary form). The models load without a problem in GLTF viewers, Xenko's Assimp library seems to be the problem. An eaten exception seems to be occurring somewhere w/ in the call to ExtractEntity (see below). Model attached, you can use this viewer to confirm model as valid https://gltf-viewer.donmccurdy.com/

gltf_model.zip

Exception

Index was outside the bounds of the array.

at Xenko.AssimpNet.NetTranslation.Materials.convertAssimpStackCppToCs(aiMaterial* material, aiTextureType type) in C:\xenko\xenko\sources\tools\Xenko.Assimp.Translation\Materials.cpp:line 161

Callstack

Xenko.GameStudio.exe!Xenko.GameStudio.DataBindingExceptionRethrower.FirstChanceExceptionThrown(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e) Line 84 at C:\xenko\xenko\sources\editor\Xenko.GameStudio\DataBindingExceptionRethrower.cs(84) [External Code] Xenko.Assimp.Translation.dll!Xenko::AssimpNet::NetTranslation::Materials::convertAssimpStackCppToCs(aiMaterial material, aiTextureType type) Line 161 at C:\xenko\xenko\sources\tools\Xenko.Assimp.Translation\Materials.cpp(161) Xenko.Importer.Assimp.dll!Xenko::Importer::AssimpNET::MeshConverter::GenerateOneTextureTypeLayers(aiMaterial pMat, aiTextureType textureType, int& textureCount, Xenko::Assets::Materials::MaterialAsset^ finalMaterial) Line 741 at C:\xenko\xenko\sources\tools\Xenko.Importer.Assimp\Xenko.Importer.Assimp.cpp(741) Xenko.Importer.Assimp.dll!Xenko::Importer::AssimpNET::MeshConverter::BuildLayeredSurface(aiMaterial pMat, bool hasBaseColor, bool hasBaseValue, Xenko::Core::Mathematics::Color4 baseColor, float baseValue, aiTextureType textureType, Xenko::Assets::Materials::MaterialAsset^ finalMaterial) Line 897 at C:\xenko\xenko\sources\tools\Xenko.Importer.Assimp\Xenko.Importer.Assimp.cpp(897) Xenko.Importer.Assimp.dll!Xenko::Importer::AssimpNET::MeshConverter::ProcessMeshMaterial(aiMaterial pMaterial) Line 1085 at C:\xenko\xenko\sources\tools\Xenko.Importer.Assimp\Xenko.Importer.Assimp.cpp(1085) Xenko.Importer.Assimp.dll!Xenko::Importer::AssimpNET::MeshConverter::ExtractMaterials(aiScene scene, std::map<aiMaterial ,std::basic_string<char,std::char_traits,std::allocator >,std::less<aiMaterial >,std::allocator<std::pair<aiMaterial const,std::basic_string<char,std::char_traits,std::allocator > > > >& materialNames) Line 1305 at C:\xenko\xenko\sources\tools\Xenko.Importer.Assimp\Xenko.Importer.Assimp.cpp(1305) Xenko.Importer.Assimp.dll!Xenko::Importer::AssimpNET::MeshConverter::ExtractEntity(System::String^ inputFilename, System::String^ outputFilename, bool extractTextureDependencies) Line 1477 at C:\xenko\xenko\sources\tools\Xenko.Importer.Assimp\Xenko.Importer.Assimp.cpp(1477) Xenko.Assets.Models.dll!Xenko.Assets.Models.AssimpAssetImporter.GetEntityInfo(Xenko.Core.IO.UFile localPath, Xenko.Core.Diagnostics.Logger logger, Xenko.Core.Assets.AssetImporterParameters importParameters) Line 36 at C:\xenko\xenko\sources\engine\Xenko.Assets.Models\AssimpAssetImporter.cs(36) Xenko.Assets.Models.dll!Xenko.Assets.Models.ModelAssetImporter.Import(Xenko.Core.IO.UFile localPath, Xenko.Core.Assets.AssetImporterParameters importParameters) Line 70 at C:\xenko\xenko\sources\engine\Xenko.Assets.Models\ModelAssetImporter.cs(70) Xenko.Assets.Presentation.dll!Xenko.Assets.Presentation.Templates.ModelFromFileTemplateGenerator.CreateAssets(Xenko.Core.Assets.Templates.AssetTemplateGeneratorParameters parameters) Line 130 at C:\xenko\xenko\sources\editor\Xenko.Assets.Presentation\Templates\ModelFromFileTemplateGenerator.cs(130) Xenko.Assets.Presentation.dll!Xenko.Assets.Presentation.Templates.AssetTemplateGenerator.Run(Xenko.Core.Assets.Templates.AssetTemplateGeneratorParameters parameters) Line 32 at C:\xenko\xenko\sources\editor\Xenko.Assets.Presentation\Templates\AssetTemplateGenerator.cs(32) Xenko.Core.Assets.Editor.dll!Xenko.Core.Assets.Editor.Components.TemplateDescriptions.TemplateGeneratorHelper.RunTemplateGeneratorSafe.AnonymousMethod__0() Line 56 at C:\xenko\xenko\sources\editor\Xenko.Core.Assets.Editor\Components\TemplateDescriptions\TemplateGeneratorHelper.cs(56) [External Code]

To Reproduce Steps to reproduce the behavior:

  1. Add 3D Model asset
  2. Select GLB file (GLTF binary form)
  3. Accept default options
  4. Click OK

Expected behavior 3D Model asset is created.

aurodev commented 4 years ago

Is gltf fully supported yet? see: #96 #458

tebjan commented 4 years ago

Xenko supports whatever Assimp 4.1 supports. I think it's missing a few special GLTF format variations, but there are easy to use tools, that convert model formats. so you can just convert it to a format that works.

acampbellb commented 4 years ago

Doesn't work w/ straight GLTF (JSON), or GLB. Forced to use FBX, argh!

vpenades commented 4 years ago

Hi, I would humbly propose to use my library, SharpGLTF for glTF model importing.

@tebjan suggested me here to do the Stride integration myself, but I'm full hands with the MonoGame integration, which is the engine I do know, so I cannot do the Stride integration myself. I would be able to answer any technical question you may have.

ykafia commented 4 years ago

Will work on this issue for now. Some questions (for Stride's devs):

vpenades commented 4 years ago

@ykafia regarding loading scenes or models.... there's a reason why glTF supports multiple scenes, and it is resource sharing

I'll give two examples:

1- Imagine you have the scene of a castle, divided in many rooms. A lot of the rooms will reuse many meshes... so you can have a single glTF for the whole castle, and each "scene" is a room. So you can control which room is being rendered, but the meshes will be shared between rooms.

2- Imagine a spaceship model: scene 0 is a brand new ship, scene 1 is the same ship with some hull damage, scene 2 is the same ship completely destroyed. In this case, some spaceship parts can be reused between scenes

In all cases, it's all about saving memory for vertex/index buffers and textures.