Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed Assimp binding to Silk.Net.Assimp #1158

Closed
wants to merge 8 commits into from

Conversation

johang88
Copy link
Contributor

@johang88 johang88 commented Oct 2, 2021

PR Details

Changed the Assimp native binding to Silk.Net.Assimp.

Description

Changed the Assimp native binding to Silk.Net.Assimp and converted the importer to a native C# library. I have also converted the Stride.Importer.Common library to a native C# library as it contained no native code.

This is a WIP PR and it currently lacks some of the material import code, otherwise it's close to a 1 to 1 conversion of the previous Assimp importer.

Motivation and Context

This change allows us to remove much of the C++/CLR code used by the asset compiler and brings us one step closer to running the asset compiler on non windows systems.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@johang88
Copy link
Contributor Author

johang88 commented Oct 2, 2021

Things left:

  • Complete material importer
  • Test skeleton / animation importing
  • Clean up code / "csharpify" it where appropriate
  • Maybe fix some todo's from the old importer, but might be better to push these in other PR's later on

Issues present in both old/new versions

  • Blend models not importing
  • Skeleton import not working. Had to transpose matrices.

else
{
if (AllowUnsignedBlendIndices)
((byte*)(vbPointer + blendIndicesOffset))[bone] = (byte)vertexIndexToBoneIdWeight[(int)i][bone].Item1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems to need a check for the bone index since the resulting list might end up having a size of less than 4


var totalWeight = 0.0f;
for (var boneId = 0; boneId < nbBoneByVertex; ++boneId)
totalWeight += curVertexWeights[boneId].Item2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same size issue here and on line 882.
Maybe can be corrected on line 872?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, had a translation error on the line above where i just set Capacity on the list instead of adding empty elements like the original version does with curVertexWeights.resize(nbBoneByVertex, std::pair<short, float>(0, 0.0f));


IComputeColor curComposition = null, newCompositionFather = null;

var isRootElement = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if i understood well, a material element is root if it's not currently referencing the previous element of the stack, or it's not being referenced by the next element of the stack.

Suggested change
var isRootElement = true;
//var isRootElement = true; Should go in the loop
bool isRootElement = top.type != Material.StackType.Operation && stack.Peek().type != Material.StackType.Operation;

curCompositionFather = compositionFathers.Pop();
}

var set = sets.Pop();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is removed too early, if the current material element is not result of an operation there's no need to pop this one here


if (type == Material.StackType.Operation)
{
var realTop = (Material.StackOperation)top;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var realTop = (Material.StackOperation)top;
var set = sets.Pop();
var realTop = (Material.StackOperation)top;

@ykafia
Copy link
Contributor

ykafia commented Dec 27, 2021

I got to a point where assimp loads a gltf mesh, albeit very broken (looks like a vertex declaration issue), will continue to work on it.

@tebjan
Copy link
Member

tebjan commented Dec 27, 2021

looks like a vertex declaration issue

Did you try the assimp loading flags, for example FlipWinding? It's important to check the intended coordinate system for a mesh and convert it to strides coordinate system... If the handedness changes, the winding has to be flipped, and/or the normals. Ideally these are settings or checkboxes in the loading dialogue.

@johang88
Copy link
Contributor Author

Will check this out, it should all match the existing code base just moved to C# from C++, but quite possible that I made some errors when converting : ) If it matches the existing code base then I would prefer to fix stuff in a later pass.

@ykafia
Copy link
Contributor

ykafia commented Dec 27, 2021

Sure! Those are only suggestions, I've only tested gltf.
And yeah you're right, I'll try the other file formats and what's currently working on master before focusing on gltf!
I'll make a PR after yours

@johang88
Copy link
Contributor Author

johang88 commented Dec 27, 2021

Tested gltf models from https://kaylousberg.itch.io/kaykit-dungeon seems to be working, skeletal meshes import but the skeleton itself is correct, bone weights looks fine though as mesh is correct if I switch to skeleton imported from FBX instead. Will have to check if the issue exists in the old assimp importer or not : )

EDIT: Same issues present in old importer.
EDIT2: Or maybe my test models were cached :D Got it to work now at least

@Perksey
Copy link

Perksey commented Dec 27, 2021

FYI A lot of this code doesn't seem Stride-specific. It's an ongoing issue that the C API that we bind to is pretty thin, and isn't easy to work with. As such, if you'd like feel free to contribute some of the wrappers you've made back to Silk.NET!

Issue: dotnet/Silk.NET#249

@Jklawreszuk
Copy link
Collaborator

@Eideren Please close this since my PR based on Johan's work was merged 😊

@Eideren Eideren closed this Aug 19, 2023
@Eideren
Copy link
Collaborator

Eideren commented Aug 19, 2023

Thank you @johang88 for the initial work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants