leezer3 / OpenBVE

OpenBVE- A free train simulator
http://www.openbve-project.net
281 stars 51 forks source link

.x unable to read all meshes #1059

Closed jhemmmm closed 3 months ago

jhemmmm commented 3 months ago

Description

The output from Assimp and the XFileParser is very different. I am expecting two meshes, yet I received only one when using the XFileParser.

Reproduction

Here's How I debug it:

using AssimpNET;
using AssimpNET.X;
using System.Diagnostics;

var importer = new XFileParser(File.ReadAllBytes("../../../sample.x"));
var scene = importer.GetImportedData();

foreach (var child in scene.RootNode.Children)
{
    Console.WriteLine($"Child: {child.Name} - Mesh: {child.Meshes.Count}");
}

var assimp = new Assimp.AssimpContext();
var assimpScene = assimp.ImportFile("../../../sample.x",
    Assimp.PostProcessSteps.Triangulate |
    Assimp.PostProcessSteps.GenerateNormals);

foreach (var child in assimpScene.RootNode.Children)
{
    Console.WriteLine($"Assimp Child: {child.Name} - Assimp Mesh: {child.MeshCount}");
}

.X File

sample.zip

Logs

Child: m1_KGgs_body - Mesh: 1
Assimp Child: m1_KGgs_body - Assimp Mesh: 2

Related information

leezer3 commented 3 months ago

Build from today will fix the display of this model with the NewXParser.

Basically, it's using a bunch of nested transforms, which neither parser liked too much. I haven't got to the bottom of what's going on with Assimp at the minute, but will try to do so.

(The version we've got is actually a port of a version of the original C++ library to .Net from about 6 years ago. I've applied various patches to this over the years, but I understand the workings of the NewXParser better, simply as I wrote it.....)

leezer3 commented 3 months ago

I've now fixed AssimpXParser too.

Please let me know if there's anything amiss now, but closing this for the minute.